Package Data | |
---|---|
Maintainer Username: | a17mad |
Maintainer Contact: | dev.elknany@gmail.com (Ahmad Elkenany) |
Package Create Date: | 2018-10-05 |
Package Last Update: | 2020-01-12 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-15 15:12:05 |
Package Statistics | |
---|---|
Total Downloads: | 211 |
Monthly Downloads: | 2 |
Daily Downloads: | 0 |
Total Stars: | 1 |
Total Watchers: | 3 |
Total Forks: | 0 |
Total Open Issues: | 0 |
This package enables annotations in Laravel Lumen to define routes and event bindings.
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);
Once you have run php artisan route:scan
(NOTE: see below Examples), you have to include the generated routes.php
file in your bootstrap/app.php
file:
require __DIR__.'/../storage/framework/routes.php';
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).
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.
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.
After you have defined the routes and event bindings via annotations, you have to run the scan command:
php artisan route:scan
to register all routes.php artisan route:clear
to clear the registered routes.php artisan event:scan
to register all event bindings.php artisan event:clear
to clear the registered events.<?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;
}
}
<?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
{
...
}
<?php
namespace App\Handlers\Events;
use DevA7mad\Annotations\Annotations\Hears;
/**
* Annotation for event binding.
*
* @Hears("UserWasRegistered")
*/
class SendWelcomeMail
{
...
}
Bugs and feature requests are tracked on GitHub.
This package is released under the MIT License.
Hey dude! Help me out for a couple of :beers:!