1. Go to this page and download the library: Download ignaszak/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/ */
ignaszak / router example snippets
use Ignaszak\Router\Collection\Route;
use Ignaszak\Router\Matcher\Matcher;
use Ignaszak\Router\Host;
use Ignaszak\Router\Response;
'test' => '(\w+)',
'id' => '(\d+)'
]);
$route->get('get', '/get/test')->controller('AnyController');
$route->post('post', '/post/{name}')
->tokens(['name' => '([a-z]+)'])
->defaults(['name' => 'demo'])
->attach(function ($name) {
echo $name;
});
$route->addTokens(['globalToken' => '([0-9]+)']);
// Match routes
$matcher = new Matcher($route);
$response = new Response($matcher->match(new Host()));
$response->all();
use Ignaszak\Router\Collection\Route;
include __DIR__ . '/vendor/autoload.php';
$route = Route::start();
// Define name (is not h for all methods).
$route->add('name', '/test/(\w+)/', 'GET');
// There are two more add methods:
$route->get(null, '/match/only/get');
$route->post(null, '/match/only/post');
use Ignaszak\Router\Collection\Route;
use Ignaszak\Router\Matcher\Matcher;
use Ignaszak\Router\Host;
r($route);
// Match routes with Host class
$matcher->match(new Host());
// Or define custom request and http method
$matcher->match(null, '/custom/request', 'GET');
new Host([string $baseQuery]);
use Ignaszak\Router\Collection\Route;
use Ignaszak\Router\Matcher\Matcher;
use Ignaszak\Router\Host;
use Ignaszak\Router\Response;
$route = Route::start();
/* Define routes */
$matcher = new Matcher($route);
/* Match routes */
// Get response
$response = new Response($matcher->match(new Host()));
// Get route name
$response->name();
// Get route controller
$response->controller();
// Get route group
$response->group();
// Get matched params in array
$response->all();
// Get param by token
$response->get(string $token [, $default = null]);
// Get tokens array
$response->tokens();
// Returns true if the token is defined
$response->has(string $token);
use Ignaszak\Router\Collection\Route;
use Ignaszak\Router\Matcher\Matcher;
use Ignaszak\Router\Host;
use Ignaszak\Router\Response;
use Ignaszak\Router\UrlGenerator;
$route = Route::start();
/* Define routes */
$host = new Host();
$matcher = new Matcher($route);
$response = new Response($matcher->match($host));
// UrlGenerator
$url = new UrlGenerator($route, $host);
// Example route: $route->get('user', '/user/{user})->tokens(['user' => '@alnum']);
$url->url('user', ['user' => 'UserName']);
use Ignaszak\Router\Collection\Yaml;
use Ignaszak\Router\Matcher\Matcher;
$yaml = new Yaml();
// Add yaml files
$yaml->add('example.yml');
$yaml->add('anotherExample.yml');
$matcher = new Matcher($yaml);
/* Match routes and get response */
use Ignaszak\Router\Collection\Yaml;
use Ignaszak\Router\Collection\Cache;
use Ignaszak\Router\Matcher\Matcher;
$yaml = new Yaml();
$yaml->add('example.yml');
$cache = new Cache($yaml);
$cache->tmpDir = __DIR__; // Define custom tmp dir - optional
$matcher = new Matcher($cache);
/* Match routes and get response */
sh
php phpunit.phar
/user/UserName
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.