/** * Synthesize the `routes` config from `routes` fragments. * * @param array $fragments * * @return array * * @throws PatternNotDefined if a pattern is missing from a route definition. * @throws ControllerNotDefined if a controller is missing from a route definition and no * location is defined. */ public static function synthesize_routes_config(array $fragments) { new BeforeSynthesizeRoutesEvent($fragments); $routes = []; foreach ($fragments as $pathname => $fragment) { foreach ($fragment as $id => $definition) { RouteDefinition::assert_is_valid($definition); RouteDefinition::normalize($definition); $routes[$id] = ['__ORIGIN__' => $pathname] + $definition; } } new SynthesizeRoutesEvent($routes); return $routes; }
/** * Adds a route definition. * * **Note:** The method does *not* revoke cache. * * @param array $definition * @param bool $trusted_definition {@link TRUSTED_DEFINITIONS} if the method should be trusting the * definition, in which case the method doesn't assert if the definition is valid, nor does * it normalizes it. * * @return $this */ protected function add(array $definition, $trusted_definition = false) { if (!$trusted_definition) { RouteDefinition::assert_is_valid($definition); RouteDefinition::normalize($definition); RouteDefinition::ensure_has_id($definition); } $id = $definition[RouteDefinition::ID]; $this->routes[$id] = $definition; return $this; }