コード例 #1
0
ファイル: BoundRoute.php プロジェクト: ranyuen/little
 /**
  * Get a response.
  *
  * @param array $vars Extra values.
  *
  * @return mixed
  */
 public function response(array $vars = [])
 {
     $this->dp->setNamedArgs($vars);
     $app = $this;
     foreach (array_reverse($this->router->getStacks()) as $stackClass) {
         $app = new $stackClass($app);
     }
     return $app->handle($this->req);
 }
コード例 #2
0
ファイル: RouteCondition.php プロジェクト: ranyuen/little
 /**
  * Dose the param match the condition?
  *
  * @param ParameterBag $bag Params.
  * @param Dispatcher   $dp  Dispatcher with params.
  *
  * @return bool
  *
  * @SuppressWarnings(PHPMD.StaticAccess)
  */
 public function isMatch(ParameterBag $bag, Dispatcher $dp)
 {
     if ($this->invokable) {
         try {
             return $dp->invoke($this->invokable);
         } catch (\Exception $ex) {
             // This exception must be ignored.
             return false;
         }
     }
     $value = $bag[$this->name];
     if (is_null($value)) {
         return false;
     }
     if (!Dispatcher::isRegex($this->pattern)) {
         return $this->pattern === $value;
     }
     $value = (string) $value;
     return !!preg_match($this->pattern, $value, $m) && $m[0] === $value;
 }
コード例 #3
0
ファイル: PathCompiler.php プロジェクト: ranyuen/little
 /**
  * @SuppressWarnings(PHPMD.StaticAccess)
  */
 private function compileParam($element)
 {
     $regex = '';
     if (isset($this->conditions[$element['val']]) && is_string($cond = $this->conditions[$element['val']])) {
         if (Dispatcher::isRegex($cond)) {
             preg_match($cond, '#\\A.(.*).[imsxeADSUXJu]*\\z#', $matches);
             $cond = $matches[1];
         } else {
             $cond = preg_quote($cond, '#');
         }
         $regex .= '(?<' . $element['val'] . '>' . $cond . ')';
     } elseif ($element['is_wildcard']) {
         $regex .= '(?<' . $element['val'] . '>.+?)';
     } else {
         $regex .= '(?<' . $element['val'] . '>\\w+?)';
     }
     if ($element['is_optional']) {
         $regex .= '?';
     }
     return $regex;
 }
コード例 #4
0
ファイル: RouteService.php プロジェクト: ranyuen/little
 /**
  * Run the controller.
  *
  * @param Dispatcher $dp DI container.
  *
  * @return mixed
  */
 public function response(Dispatcher $dp)
 {
     return $dp->invoke($this->controller);
 }
コード例 #5
0
ファイル: RouterService.php プロジェクト: ranyuen/little
 private function findNamedRoute($name, Request $req, $prefix = '')
 {
     if (isset($this->namedRoutes[$name])) {
         $dp = new Dispatcher($this->c);
         $bag = new ParameterBag();
         $bag->setRequest($req);
         $bag->addArray(['req' => $req, 'request' => $req, 'router' => $this->facade]);
         $dp->setNamedArgs($bag);
         $dp->setTypedArg('Ranyuen\\Little\\Request', $req);
         $dp->setTypedArg('Symfony\\Component\\HttpFoundation\\Request', $req);
         $dp->setTypedArg('Ranyuen\\Little\\Router', $this->facade);
         return new BoundRoute($this->namedRoutes[$name], $this->facade, $req, $dp);
     }
     foreach ($this->routes as $route) {
         if (!(is_array($route) && $route[1] instanceof Router)) {
             continue;
         }
         list($path, $router) = $route;
         if ($route = $router->findMatchedRoute($name, $req, $prefix . $path)) {
             return $route;
         }
     }
 }