rudra/router

Rudra framework

Installs: 859

Dependents: 1

Suggesters: 0

Security: 0

Stars: 1

Watchers: 2

Forks: 0

Open Issues: 0

pkg:composer/rudra/router

v25.12 2025-06-26 14:53 UTC

This package is auto-updated.

Last update: 2025-12-30 08:20:01 UTC


README

PHPunit Maintainability CodeFactor Coverage Status

Rudra-Router

Basic installation / Базовая установка

use Rudra\Router\Router;
use Rudra\Container\Rudra;

$router = new Router(Rudra::run());

Installation for facade use / Установка для использования фасада

use Rudra\Container\Facades\Rudra;  
use Rudra\Router\RouterFacade as Router;
use Rudra\Container\Interfaces\RudraInterface;

Rudra::binding()->set([RudraInterface::class => Rudra::run()]);

Setting the route / Устанавливаем маршрут callback/:name

$router->get('callback/:name', function ($name) {
    echo "Hello $name!";
});

with Regex

$router->get('callback/:[\d]{1,3}', function ($name) {
    echo "Hello $name!";
});

To call through the Facade / Для вызова через Фасад

Router::get('callback/:name', function ($name) {
    echo "Hello $name!";
});

with Regex

Router::get('callback/:[\d]{1,3}', function ($name) {
    echo "Hello $name!";
});

call / вызывает MainController::read

$router->get('read/:id', [MainController::class, 'read']);

To call through the Facade / Для вызова через Фасад

Router::get('read/:id', [MainController::class, 'read']);

call MainController::read with middleware

$router->get('read/page',  [MainController::class, 'read'], ['before' => [Middleware::class]);

To call through the Facade / Для вызова через Фасад

Router::get('read/page',  [MainController::class, 'read'], ['before' => [Middleware::class]);

С параметрами для middleware

$router->get('', [MainController::class, 'read'], [
    'before' => [FirstMidddleware::class, [SecondMidddleware::class, ['int' => 456, new \stdClass]]],
    'after'  => [FirstMidddleware::class, [SecondMidddleware::class, ['int' => 456, new \stdClass]]]
]);

call / вызывает MainController::create

$router->post('create/:id', [MainController::class, 'create']);

call / вызывает MainController::update

$router->put('update/:id', [MainController::class, 'update']);

call / вызывает MainController::update

$router->patch('update/:id', [MainController::class, 'update']);

call / вызывает MainController::delete

$router->delete('delete/:id', [MainController::class, 'delete']);

call / вызывает MainController::any 'GET|POST|PUT|PATCH|DELETE'

$router->any('any/:id', [MainController::class, 'any']);

call / вызывает MainController::read для GET

call / вызывает MainController::create для POST

call / вызывает MainController::update для PUT

call / вызывает MainController::delete для DELETE

$router->resource('api/:id', MainController::class);

Изменить методы контроллера по умолчанию можно передав массив с вашими именами
You can change the default controller methods by passing an array with your names

$router->resource('api/:id', MainController::class, ['actionIndex', 'actionAdd', 'actionUpdate', 'actionDrop']);

A variant of declaring a route using the set method / Вариант объявления маршрута методом set

call / вызывает MainController::actionIndex

$router->set(['/test/:id', 'DELETE|PUT', [MainController::class, 'actionIndex'], [
        'before' => [First::class, Second::class],
        'after'  => [[First::class], [Second::class]]
]]);

Exemple / Пример Middleware

/**
 * Handles requests as a middleware using __invoke().
 */
class SomeMiddleware
{
    public function __invoke($next, ...$params)
    {
        // Logic here

        if ($next) {
            $next();
        }
    }
}

License

This project is licensed under the Mozilla Public License 2.0 (MPL-2.0) — a free, open-source license that:

  • Requires preservation of copyright and license notices,
  • Allows commercial and non-commercial use,
  • Requires that any modifications to the original files remain open under MPL-2.0,
  • Permits combining with proprietary code in larger works.

📄 Full license text: LICENSE
🌐 Official MPL-2.0 page: https://mozilla.org/MPL/2.0/

Проект распространяется под лицензией Mozilla Public License 2.0 (MPL-2.0). Это означает:

  • Вы можете свободно использовать, изменять и распространять код.
  • При изменении файлов, содержащих исходный код из этого репозитория, вы обязаны оставить их открытыми под той же лицензией.
  • Вы обязаны сохранять уведомления об авторстве и ссылку на оригинал.
  • Вы можете встраивать код в проприетарные проекты, если исходные файлы остаются под MPL.

📄 Полный текст лицензии (на английском): LICENSE
🌐 Официальная страница: https://mozilla.org/MPL/2.0/