Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/proai/lumen-annotations
:bookmark_tabs: Laravel Lumen 5 route and event binding annotations
https://github.com/proai/lumen-annotations
annotations laravel-lumen php
Last synced: about 2 months ago
JSON representation
:bookmark_tabs: Laravel Lumen 5 route and event binding annotations
- Host: GitHub
- URL: https://github.com/proai/lumen-annotations
- Owner: ProAI
- License: mit
- Created: 2015-11-25T14:57:21.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2019-11-22T00:38:22.000Z (about 5 years ago)
- Last Synced: 2024-11-07T06:20:37.254Z (2 months ago)
- Topics: annotations, laravel-lumen, php
- Language: PHP
- Homepage:
- Size: 41 KB
- Stars: 10
- Watchers: 3
- Forks: 4
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Lumen Annotations
[![Latest Stable Version](https://poser.pugx.org/proai/lumen-annotations/v/stable)](https://packagist.org/packages/proai/lumen-annotations) [![Total Downloads](https://poser.pugx.org/proai/lumen-annotations/downloads)](https://packagist.org/packages/proai/lumen-annotations) [![Latest Unstable Version](https://poser.pugx.org/proai/lumen-annotations/v/unstable)](https://packagist.org/packages/proai/lumen-annotations) [![License](https://poser.pugx.org/proai/lumen-annotations/license)](https://packagist.org/packages/proai/lumen-annotations)
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 add the package to your `composer.json` file:
```
"proai/lumen-annotations": "~1.0"
```Then you have to run `composer update` to install the package. Once this is completed, you have to add the service provider in `bootstrap/app.php`:
```
$app->register(ProAI\Annotations\AnnotationsServiceProvider::class);
```Copy `config/annotations.php` from this package to your configuration directory to use a custom configuration file.
##### Include generated routes
Once you have run `php artisan route:scan` (see below), you have to include the generated `routes.php` file in your `bootstrap/app.php` file:
```php
require __DIR__.'/../storage/framework/routes.php';
```##### Include generated event bindings
After you have executed `php artisan event:scan` (see below), you have to add the service provider to the providers array in `config/app.php`:
```
'ProAI\Annotations\EventServiceProvider'
```## 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