Ejemplo n.º 1
0
 /**
  * Configures and loads http
  * @link https://github.com/ignaszak/php-router
  */
 public function loadHttp()
 {
     $yaml = new RouterYaml();
     $yaml->add($this->routerYaml);
     $adminYaml = $this->adminExtension->getAdminExtensionsRouteYaml();
     foreach ($adminYaml as $file) {
         $yaml->add($file);
     }
     $cache = new Cache($yaml);
     $cache->tmpDir = $this->dir($this->conf['conf']['tmp']['router'] ?? '');
     $matcher = new Matcher($cache);
     $host = new Host(RegistryFactory::start('file')->register('Conf\\Conf')->getRequestUri());
     $response = new Response($matcher->match($host));
     $this->registry->set('url', new UrlGenerator($cache, $host));
     $this->http = new Http($response, Request::createFromGlobals());
     $this->registry->set('http', $this->http);
 }
Ejemplo n.º 2
0
 public function testMatchWithNoMatchedRouts()
 {
     $this->assertEmpty($this->matcher->match());
 }
Ejemplo n.º 3
0
//   @notfound - not found
//   @digit    - digits [0-9]
//   @alpha    - alphabetic characters [A-Za-z_-]
//   @alnum    - alphanumeric characters [A-Za-z0-9_-]
$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>';