PHP code example of alexpts / php-simple-router

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

    

alexpts / php-simple-router example snippets


$route2 = new Route('/blog/{id}/', $endPoint2, ['id' => '\d+']);

$route = new Route('/{lang}/users/{id}/{action}/', $endPoint, [
	'lang' => 'ru|en',
	'action' => '[a-z0-9_]+',
	'id' => '\d+',
], Route::ONLY_XHR);

$matcher = new Matcher();
$uri = '/profile/23/';
$routes = ...; // CollectionRoute instance
$endPoint = $matcher->matchFirst($routes, $uri); // IPoint instance

 foreach ($matcher->match($routes, $uri) as $endPoint) {
 	...
 }

$endPoint = new Point\CallablePoint([
	'callable' => function () {
		return '404';
	}
]);

$endPoint = new Point\ControllerPoint([
	'controller' => 'CollectionRouteTest',
	'action' => 'action'
]);

$endPoint = new Point\DynamicController([
	'prefix' => 'Demo'
]);

$endPoint = new Point\ControllerDynamicAction([
	'controller' => SomeController::class
]);