Beispiel #1
0
 /**
  *
  * @return boolean
  */
 public function isAdmin() : bool
 {
     return (bool) preg_match('/^admin[a-zA-Z0-9_-]*/', $this->router->name());
 }
Beispiel #2
0
$route->add('defined', '/regex/@alpha/{id}')->tokens(['id' => '@digit']);
// Add default route
$route->add('default', '/@base')->controller('DefaultController');
// Not found
$route->add('error', '/@notfound')->attach(function () {
    throw new Exception('404 Not Found');
});
// Define custom regular expression. It will be avilable for all routes
$route->addPatterns(['day' => '([0-9]{2})', 'month' => '([0-9]{2})', 'year' => '([0-9]{4})']);
$route->add(null, '/@year/@month/@day/');
// Get response
$matcher = new Matcher($route);
// Start parsing
// Matcher::match([Host $host [, string $baseQuery [, string HttpMethod]])
$host = new Host();
$response = new Response($matcher->match($host));
// Class Ignaszak\Router\Host([string $baseQuery])
// provides current request and http method
// $baseQuery argument defines folder via site is avilable:
// http://fullSite.com/Adress => $baseQuery = /Adress (without slash on end)
// It is possible to define custom request and http method:
// $matcher->match(null, '/customRequest', 'GET');
// Display response
// Display matched params
echo 'Routes:<pre>';
print_r($response->all());
echo '</pre>';
// Get concrete param
echo $response->get('token');
// Get route name
echo 'Route name: ';