Skip to content

raihel/controller

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Raihel Controller

Total Downloads Latest Stable Version License

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 controllers
  • controllers: An array with your controller classes
  • loadRoute: The class that will do the work of including the routes mapped in your controllers in your application accepts any class that implements Raihel\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.

About

Create your routes using attributes in your controllers

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages