ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
RouteCollector.php
Go to the documentation of this file.
1 <?php
2 
3 namespace FastRoute;
4 
6 {
8  protected $routeParser;
9 
11  protected $dataGenerator;
12 
15 
22  public function __construct(RouteParser $routeParser, DataGenerator $dataGenerator)
23  {
24  $this->routeParser = $routeParser;
25  $this->dataGenerator = $dataGenerator;
26  $this->currentGroupPrefix = '';
27  }
28 
38  public function addRoute($httpMethod, $route, $handler)
39  {
40  $route = $this->currentGroupPrefix . $route;
41  $routeDatas = $this->routeParser->parse($route);
42  foreach ((array) $httpMethod as $method) {
43  foreach ($routeDatas as $routeData) {
44  $this->dataGenerator->addRoute($method, $routeData, $handler);
45  }
46  }
47  }
48 
57  public function addGroup($prefix, callable $callback)
58  {
59  $previousGroupPrefix = $this->currentGroupPrefix;
60  $this->currentGroupPrefix = $previousGroupPrefix . $prefix;
61  $callback($this);
62  $this->currentGroupPrefix = $previousGroupPrefix;
63  }
64 
73  public function get($route, $handler)
74  {
75  $this->addRoute('GET', $route, $handler);
76  }
77 
86  public function post($route, $handler)
87  {
88  $this->addRoute('POST', $route, $handler);
89  }
90 
99  public function put($route, $handler)
100  {
101  $this->addRoute('PUT', $route, $handler);
102  }
103 
112  public function delete($route, $handler)
113  {
114  $this->addRoute('DELETE', $route, $handler);
115  }
116 
125  public function patch($route, $handler)
126  {
127  $this->addRoute('PATCH', $route, $handler);
128  }
129 
138  public function head($route, $handler)
139  {
140  $this->addRoute('HEAD', $route, $handler);
141  }
142 
148  public function getData()
149  {
150  return $this->dataGenerator->getData();
151  }
152 }
addRoute($httpMethod, $route, $handler)
Adds a route to the collection.
getData()
Returns the collected route data, as provided by the data generator.
head($route, $handler)
Adds a HEAD route to the collection.
patch($route, $handler)
Adds a PATCH route to the collection.
post($route, $handler)
Adds a POST route to the collection.
__construct(RouteParser $routeParser, DataGenerator $dataGenerator)
Constructs a route collector.
put($route, $handler)
Adds a PUT route to the collection.
addGroup($prefix, callable $callback)
Create a route group with a common prefix.
$handler