コード例 #1
0
ファイル: RouteCollection.php プロジェクト: opis/routing
 /**
  * @param Route $route
  * @return RouteCollection
  */
 public function addRoute(Route $route) : self
 {
     $id = $route->setRouteCollection($this)->getID();
     $this->routes[$id] = $route;
     if (null !== ($name = $route->getName())) {
         $this->namedRoutes[$name] = $id;
     }
     return $this;
 }
コード例 #2
0
ファイル: UserFilter.php プロジェクト: opis/view
 /**
  * @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);
 }
コード例 #3
0
ファイル: UserFilter.php プロジェクト: opis/http-routing
 /**
  * @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;
 }
コード例 #4
0
ファイル: Route.php プロジェクト: opis/http-routing
 /**
  * @return callable[]
  */
 public function getBindings() : array
 {
     if (!isset($this->cache[__FUNCTION__])) {
         /** @var RouteCollection $collection */
         $collection = $this->collection;
         $this->cache[__FUNCTION__] = parent::getBindings() + $collection->getBindings();
     }
     return $this->cache[__FUNCTION__];
 }
コード例 #5
0
ファイル: RequestFilter.php プロジェクト: opis/http-routing
 /**
  * @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;
 }
コード例 #6
0
ファイル: Router.php プロジェクト: opis/http-routing
 /**
  * @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();
 }
コード例 #7
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();
 }
コード例 #8
0
ファイル: ViewApp.php プロジェクト: opis/view
 /**
  * Register a new view
  * 
  * @param   string      $pattern
  * @param   callable    $resolver
  * @param   int         $priority
  * 
  * @return Route
  */
 public function handle(string $pattern, callable $resolver, int $priority = 0) : Route
 {
     $route = new Route($pattern, $resolver);
     $route->set('priority', $priority);
     $this->collection->addRoute($route);
     $this->cache = array();
     //clear cache
     return $route;
 }