TYPO3 CMS  TYPO3_8-7
Router.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
19 
32 {
38  protected $routes = [];
39 
46  public function addRoute($routeIdentifier, $route)
47  {
48  $this->routes[$routeIdentifier] = $route;
49  }
50 
56  public function getRoutes()
57  {
58  return $this->routes;
59  }
60 
68  public function match($pathInfo)
69  {
70  foreach ($this->routes as $routeIdentifier => $route) {
71  // This check is done in a simple way as there are no parameters yet (get parameters only)
72  if ($route->getPath() === $pathInfo) {
73  // Store the name of the Route in the _identifier option so the token can be checked against that
74  $route->setOption('_identifier', $routeIdentifier);
75  return $route;
76  }
77  }
78  throw new ResourceNotFoundException('The requested resource "' . $pathInfo . '" was not found.', 1425389240);
79  }
80 
87  public function matchRequest(ServerRequestInterface $request)
88  {
89  return $this->match($request->getAttribute('routePath'));
90  }
91 }
addRoute($routeIdentifier, $route)
Definition: Router.php:46
matchRequest(ServerRequestInterface $request)
Definition: Router.php:87