raihel / controller
Create your routes using attributes in your controllers
v0.2.1
2022-07-13 06:16 UTC
Requires
- php: ^8.1.0
- jerowork/file-class-reflector: ^0.1.0
- psr/log: ^1.0|^2.0|^3.0
This package is not auto-updated.
Last update: 2025-03-06 14:07:12 UTC
README
Create your routes using attributes in your controllers
Installation
composer install raihel/controller
Setting
Use Controller Factory to map your routes
diretory
: An array with the directories of your controllerscontrollers
: An array with your controller classesloadRoute
: The class that will do the work of including the routes mapped in your controllers in your application accepts any class that implementsRaihel\Controller\Core\Load\Type\LoudRoute
Slim:
require __DIR__.'/../../vendor/autoload.php'; use App\HelloController; use Raihel\Controller\Core\ControllerFactory; use Slim\App; $app = new App(); use Raihel\Controller\Core\Load\Type\SlimLoadRoute; ControllerFactory::load( loadRoute: new SlimLoadRoute($app), diretory: [__DIR__ . '/../src'], controllers: [HelloController::class] ); $app->run();
Lumen:
ControllerFactory::load( loadRoute: new LumenLoadRoute($router), diretory: [__DIR__ . '/../app/Http/Controllers'], );
Usage/Examples
Controller
Create your controller by adding the attribute Controller in your class it can receive a prefix that groups your routes
namespace App; use Raihel\Controller\Attributes\Controller; use Raihel\Controller\Attributes\Route\Get; use Raihel\Controller\Attributes\Route\Put; #[Controller('home')] class AppController { #[Get] public function home() { echo 'Hello World!'; } #[Get('hello'), Put('hello')] public function get2() { echo 'Hello World 2!'; } }
Routes
The attribute Get
before the home method creates a GET /home
endponit for application
Attributes |
---|
Get |
Post |
Put |
Delete |
Patch |
Authors
License
The Raihel Controller is open-sourced software licensed under the MIT license.