/** * @param BaseRouter|Router $router * @param BaseContext|Context $context * @param BaseRoute|Route $route * @return bool */ public function pass(BaseRouter $router, BaseContext $context, BaseRoute $route) : bool { /** @var CallbackFilter[] $filters */ $filters = $route->get('filters', []) + $router->getRouteCollection()->getFilters(); foreach ($route->get('before', []) as $name) { if (isset($filters[$name])) { if ($filters[$name]->setBindMode(false)->pass($router, $context, $route) === false) { return false; } } } return true; }
/** * @param BaseRouter|BaseRouter $router * @param BaseContext|Context $context * @param BaseRoute|Route $route * @return bool */ public function pass(BaseRouter $router, BaseContext $context, BaseRoute $route) : bool { //match secure if (null !== ($secure = $route->get('secure'))) { if ($secure !== $context->isSecure()) { return false; } } //match method if (!in_array($context->method(), $route->get('method', ['GET']))) { return false; } // match domain if (null !== ($domain = $route->get('domain'))) { $regex = $router->getRouteCollection()->getDomainCompiler()->getRegex($domain, $route->getWildcards()); return preg_match($regex, $context->domain()); } return true; }
/** * @param Context $context * @param Route $route * @param Router $router * @return bool */ public function pass(Router $router, Context $context, Route $route) : bool { $filter = $route->get('filter'); if (!is_callable($filter)) { return true; } $values = $router->extract($context, $route); $bindings = $router->bind($values, $route->getBindings()); $arguments = $router->buildArguments($filter, $bindings); return $filter(...$arguments); }
/** * @param BaseContext|Context $context * @param BaseRoute|Route $route * @return array */ public function extract(BaseContext $context, BaseRoute $route) : array { /** @var Context $context */ /** @var Route $route */ $names = []; if (null !== ($domain = $route->get('domain'))) { $names += $this->getRouteCollection()->getDomainCompiler()->getNames($domain); } $names += $this->getCompiler()->getNames($route->getPattern()); $regex = $this->getRouteCollection()->getRegex($route->getID()); $values = $this->getCompiler()->getValues($regex, (string) $context); return array_intersect_key($values, array_flip($names)) + $route->getDefaults(); }
/** * @param BaseRouter|Router $router * @param BaseContext|Context $context * @param BaseRoute|Route $route * @return DispatcherInterface */ public function resolve(BaseRouter $router, BaseContext $context, BaseRoute $route) : DispatcherInterface { $dispatcher = $route->get('dispatcher', 'default'); $factory = $this->collection->get($dispatcher); return $factory(); }