/** * Parses the routes from the route entry array. * @param array[] $definitions List of simple route entries * @return array[] Parsed routes definitions */ private function parseRoutes(array $definitions) : array { $collector = new RouteCollector(); foreach ($definitions as list($methods, $path, $handler)) { $collector->map($methods, $path, $handler); } return $collector->getRoutes(); }
public function parse(RouteCollector $collector, array $patterns, $parentPrefix = '') { foreach ($this->getPatterns() as $pattern => $route) { if (isset($route['name'])) { $patternParams = [$pattern, $route['name']]; } else { $patternParams = $pattern; } if (is_string($route['callback'])) { $callback = explode(':', $route['callback']); } else { $callback = $route['callback']; } $collector->any($patternParams, $callback); } }
private function buildRouter(RouteCollector $rc, Server $server) { $allowedMethods = []; foreach ($this->routes as list($method, $uri, $actions)) { $allowedMethods[] = $method; $rc->addRoute($method, $uri, $this->bootRouteTarget($actions)); } $originalMethods = $server->getOption("allowedMethods"); if ($server->getOption("normalizeMethodCase")) { $allowedMethods = array_map("strtoupper", $allowedMethods); } $allowedMethods = array_merge($allowedMethods, $originalMethods); $allowedMethods = array_unique($allowedMethods); $server->setOption("allowedMethods", $allowedMethods); }
/** * Collect routes * * @param RouteCollector $route */ public function routes(RouteCollector $route) { $route->bind('html', Callback::class . '::htmlPageInstance'); }