foxtool/yukon

Simple Router

Maintainers

Details

github.com/FoxTool/Yukon

Source

Issues

Installs: 17

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/foxtool/yukon

v1.0.0 2025-05-19 21:01 UTC

This package is not auto-updated.

Last update: 2026-01-08 17:51:24 UTC


README

The simple router

Define routes

All routes define in your project root folder. Create routes.php file in the configs folder.

Example:

use FoxTool\Yukon\Core\Router;

Router::get('/', 'HomeController@index');
Router::get('/sign-in', 'AuthController@index');
Router::post('/authentication', 'AuthController@authentication');

Class Router has static methods for each HTTP methods:

Example:

Router::get(...)
Router::post(...)
Router::put(...)
Router::patch(...)
Router::delete(...)

Each method gets two parameters, a route string and a "controller@action" string or a closure function.

Example:

Router::get('/', 'HomeController@index');
Router::get('/version', function() {
    echo 'v 1.0';
});

Routes can be grouped by common prefix

Example:

Router::prefix('/admin')->group(function() {
    Router::get('/users', 'UserController@index');
    Router::post('/users', 'UserController@create');
    Router::get('/users/{id}', 'UserController@show');
    Router::put('/users/{id}', 'UserController@update');
    Router::delete('/users/{id}', 'UserController@delete');
});

In this case, we have combined routes: '/admin/user', '/admin/users/{id}' etc.

Custom Controllers

Custom controllers should be created in the app/Controller folder and should be extended from the base controller FoxTool\Yukon\Core\Controller.

Example:

use FoxTool\Yukon\Core\Controller;

class UserController extends Controller {
    ...
}

Middleware (Authentication Guard)

Each route can be protected by the guard. Currently, implemented the guard for protecting API routes. It's the ApiAuthMiddleware and it uses Bearer token to check access rights.

Example:

// Single route
Router::get('/posts', 'UserController@index')->middleware('api');

// Groups of routes
Router::prefix('/api')->group(function() {
    Router::get('/users', 'UserController@create')->middleware('api');
    Router::post('/users', 'UserController@create')->middleware('api');
    Router::put('/users/{id}', 'UserController@update')->middleware('api');
    Router::delete('/users/{id}', 'UserController@delete')->middleware('api');
});