Example #1
0
 /**
  * @param PathCompiler $compiler
  * @return array
  */
 public function compile(PathCompiler $compiler)
 {
     $data = $compiler->compile($this->path);
     $data += array('callback' => $this->callback, 'methods' => (array) $this->methods);
     return $data;
 }
Example #2
0
 /**
  * Checks that given path matches root's path.
  *
  * @param string $path
  *
  * @return boolean
  */
 public function matchPath($path)
 {
     $path = "/" . trim($path, "/");
     // copy requisites, so we can change them temporary
     $requisites = array_merge($this->requisites);
     // special {_format} parameter
     if (strpos($this->path, ".{_format}") !== false) {
         if ($requisite = $this->getRequisite("_format")) {
             $requisites["_format"] = "\\.(" . $requisite . ")";
         } else {
             $requisites["_format"] = "\\.\\w+";
         }
         $routePath = str_replace(".{_format}", "{_format}", $this->path);
     } else {
         $routePath = $this->path;
     }
     $regEx = PathCompiler::compile($routePath, $this->defaults, $requisites);
     if (preg_match($regEx, $path, $matches)) {
         // add matches in array to know variables in path name
         foreach ($matches as $var => $value) {
             if (!is_int($var) && $value) {
                 $this->variables[$var] = $value;
             }
         }
         return true;
     }
     return false;
 }