You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.2 KiB
46 lines
1.2 KiB
<?php
|
|
|
|
namespace FastRoute;
|
|
|
|
class RouteCollector {
|
|
private $routeParser;
|
|
private $dataGenerator;
|
|
|
|
/**
|
|
* Constructs a route collector.
|
|
*
|
|
* @param RouteParser $routeParser
|
|
* @param DataGenerator $dataGenerator
|
|
*/
|
|
public function __construct(RouteParser $routeParser, DataGenerator $dataGenerator) {
|
|
$this->routeParser = $routeParser;
|
|
$this->dataGenerator = $dataGenerator;
|
|
}
|
|
|
|
/**
|
|
* Adds a route to the collection.
|
|
*
|
|
* The syntax used in the $route string depends on the used route parser.
|
|
*
|
|
* @param string|string[] $httpMethod
|
|
* @param string $route
|
|
* @param mixed $handler
|
|
*/
|
|
public function addRoute($httpMethod, $route, $handler) {
|
|
$routeDatas = $this->routeParser->parse($route);
|
|
foreach ((array) $httpMethod as $method) {
|
|
foreach ($routeDatas as $routeData) {
|
|
$this->dataGenerator->addRoute($method, $routeData, $handler);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Returns the collected route data, as provided by the data generator.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function getData() {
|
|
return $this->dataGenerator->getData();
|
|
}
|
|
}
|