PHP code example of fyre / router

1. Go to this page and download the library: Download fyre/router library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fyre / router example snippets


use Fyre\Router\Router;

$router = new Router($container, $modelRegistry, $config);

$container->singleton(Router::class);

$router = $container->use(Router::class);

$router->clear();

$route = $router->connect($path, $destination, $options);

$router->delete($path, $destination, $options);
$router->get($path, $destination, $options);
$router->patch($path, $destination, $options);
$router->post($path, $destination, $options);
$router->put($path, $destination, $options);
$router->redirect($path, $destination, $options);

$router->get('test/{id}', 'test', ['middleware' => 'alias:test,{id}']);

$baseUri = $router->getBaseUri();

$router->group($options, $callback);

$request = $router->loadRoute($request);

$url = $router->url($name, $arguments, $options)

$checkMethod = $route->checkMethod($method);

$checkPath = $route->checkPath($path);

$arguments = $route->getArguments();

$bindingFields = $route->getBindingFields();

$destination = $route->getDestination();

$middleware = $route->getMiddleware();

$path = $route->getPath();

$placeholders = $route->getPlaceholders();

$response = $route->handle($request, $response);

$route->setMiddleware($middleware);

$route->setPlaceholder($placeholder, $regex);

use Fyre\Router\Routes\ClosureRoute;

$route = new ClosureRoute($container, $destination, $path, $options);

$router->get('posts', function(): string {
    return view('Posts.index');
});

$router->get('posts/{post}', function(Post $post): string {
    return view('Posts.view', ['post' => $post]);
}); 

use Fyre\Router\Routes\ControllerRoute;

$route = new ControllerRoute($container, $destination, $path, $options);

$router->get('posts', [Posts::class]); // defaults to index method
$router->get('posts/{post}', [Posts::class, 'view']);

$action = $route->getAction();

$controller = $route->getController();

use Fyre\Router\Routes\RedirectRoute;

$route = new RedirectRoute($container, $destination, $path, $options);

$router->redirect('test', 'https://test.com/');
$router->redirect('test/{id}', 'https://test.com/{id}');

use Fyre\Router\Middleware\RouterMiddleware;

$middleware = new RouterMiddleware($container, $middlewareRegistry, $router);

$middleware = $container->use(RouterMiddleware::class);

$response = $middleware->handle($request, $next);

use Fyre\Router\Middleware\SubstituteBindingsMiddleware;

$middleware = new SubstituteBindingsMiddleware($container, $middlewareRegistry, $entityLocator);

$middleware = $container->use(SubstituteBindingsMiddleware::class);

$response = $middleware->handle($request, $next);