Esempio n. 1
0
 /**
  * @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;
 }
Esempio n. 2
0
 /**
  * @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;
 }
Esempio n. 3
0
 /**
  * @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);
 }
Esempio n. 4
0
 /**
  * @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();
 }
Esempio n. 5
0
 /**
  * @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();
 }