deva7mad/lumen-annotations 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

deva7mad/lumen-annotations

Composer 安装命令:

composer require deva7mad/lumen-annotations

包简介

Laravel Lumen route and event binding annotations generate

README 文档

README

Latest Stable Version Total Downloads Latest Unstable Version License

This package enables annotations in Laravel Lumen to define routes and event bindings.

Installation

Lumen Annotations is distributed as a composer package. So you first have to run the following command

composer require deva7mad/lumen-annotations

After that copy config/annotations.php from this package to your configuration directory.

Finally: Add this lines to bootstrap/app.php file:

$app->configure('annotations');
$app->register(DevA7mad\Annotations\AnnotationsServiceProvider::class);
Include generated routes

Once you have run php artisan route:scan (NOTE: see below Examples), you have to include the generated generated.php file in your bootstrap/app.php file:

require __DIR__.'/../routes/generated.php';

Usage

By using annotations you can define your routes directly in your controller classes and your event bindings directly in your event handlers (see examples for usage of annotations).

Class Annotations

For routes:

Annotation Description
@Controller This annotation must be set to indicate that the class is a controller class. Optional parameters prefix and middleware.
@Resource First parameter is resource name. Optional parameters only and except.
@Middleware First parameter is middleware name.

For events:

Annotation Description
@Hears This annotation binds an event handler class to an event.
Method Annotations

For routes:

Annotation Description
@Get,
@Post,
@Options,
@Put,
@Patch,
@Delete,
@Any
First parameter is route url. Optional parameters as and middleware.
@Middleware First parameter is middleware name.

Commands

After you have defined the routes and event bindings via annotations, you have to run the scan command:

  • Use php artisan route:scan to register all routes.
  • Use php artisan route:clear to clear the registered routes.
  • Use php artisan event:scan to register all event bindings.
  • Use php artisan event:clear to clear the registered events.

Examples

Example #1
<?php

namespace App\Http\Controllers;

use DevA7mad\Annotations\Annotations as Route;

/**
 * Class annotation for UserController (belongs to all class methods).
 *
 * @Route\Controller(prefix="admin")
 */
class UserController
{
    /**
     * Method annotations for showProfile($id) method.
     * @param $id
     * @Route\Get("profiles/{id}", as="profiles.show")
     * @return mixed
     */
    public function showProfile($id)
    {
        return $id;
    }

}
Example #2
<?php

namespace App\Http\Controllers;

use DevA7mad\Annotations\Annotations as Route;

/**
 * Class annotations for resource controller CommentController (belongs to all class methods).
 *
 * @Route\Controller
 * @Route\Resource("comments", only={"create", "index", "show"})
 * @Route\Middleware("auth")
 */
class CommentController
{
    ...
}
Example #3
<?php

namespace App\Handlers\Events;

use DevA7mad\Annotations\Annotations\Hears;

/**
 * Annotation for event binding.
 *
 * @Hears("UserWasRegistered")
 */
class SendWelcomeMail
{
    ...
}

Support

Bugs and feature requests are tracked on GitHub.

Author

  • Ahmad Elkenany - Development - Linkedin

License

This package is released under the MIT License.

Support on Beerpay

Hey dude! Help me out for a couple of 🍻!

Beerpay Beerpay

统计信息

  • 总下载量: 213
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-10-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固