Exemplo n.º 1
0
 /**
  * @param $path
  * @param Request $request
  * @param Response $response
  * @return \Closure|bool
  */
 public function apply(&$path, Request &$request, Response &$response)
 {
     list($param_names, $rule_segments) = $this->extractFromRuleStr();
     if (empty($param_names)) {
         return false;
     }
     $path_segments = explode(self::SEGMENT_DELIMITER, $path);
     array_shift($rule_segments);
     array_shift($path_segments);
     $contextParams = array();
     if (count($rule_segments) == count($path_segments)) {
         foreach ($rule_segments as $k => $v) {
             if (false !== strpos($v, self::RULE_PARAM_PREFIX)) {
                 $param_name = array_shift($param_names);
                 $contextParams[$param_name] = $path_segments[$k];
             } elseif ($v === $path_segments[$k]) {
                 continue;
             } else {
                 return false;
             }
         }
         $request->withAttributes($contextParams);
         $this->performCallback($request, $response);
         return true;
     }
     return false;
 }