PHP code example of umityatarkalkmaz / route

1. Go to this page and download the library: Download umityatarkalkmaz/route 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/ */

    

umityatarkalkmaz / route example snippets


use UmitYatarkalkmaz\Route;

$router = new Route();

$router->get('/', static fn () => view('home'));
$router->get('/users/:id', static fn (string $id) => view('user', findUser($id)));
$router->post('/users', static fn () => createUser());

echo $router->dispatch();

$router->get('/files/:name', $handler)->where(['name' => '[a-z]+']);

$router->group('/admin', static function (Route $router): void {
    $router->get('/users', $handler);      // /admin/users
    $router->get('/settings', $handler);   // /admin/settings
});

$router = new Route(controllerNamespace: 'App\\Controller');

$router->get('/users/:id', 'UserController@show');

$router->setNotFoundHandler(static fn (string $method, string $path) => render404());
$router->setMethodNotAllowedHandler(static fn (string $method, string $path) => render405());

$router = new Route(allowMethodOverride: true);

<form method="post" action="/users/1">
    <?= Route::renderMethodField('DELETE') 

$router = new Route(basePath: '/shop');

self::assertSame('user 42', $router->dispatch('GET', '/users/42'));