예제 #1
0
파일: Route.php 프로젝트: nebiros/yasc
 /**
  *
  * @param Yasc_Function $function
  * @return bool
  */
 protected function _lookup(Yasc_Function $function)
 {
     $annotationPattern = $function->getAnnotation()->getPattern();
     // stripslashes because we need to scape some of them when we use wildcards
     // like * or **.
     $annotationParts = explode($this->_request->getUrlDelimiter(), stripcslashes($annotationPattern));
     // regex route.
     if ($annotationPattern[0] == "^") {
         if (substr($annotationPattern, -1) != "\$") {
             $annotationPattern .= "\$";
         }
         $pattern = "#" . $annotationPattern . "#i";
         // slash route.
     } else {
         if ($annotationPattern == $this->_request->getUrlDelimiter()) {
             $pattern = "#^" . self::OPTIONAL_SLASH_SUBPATTERN . "\$#";
         } else {
             $parsed = array();
             $paramsList = array();
             $paramsCounter = 0;
             foreach ($annotationParts as $part) {
                 if (true === empty($part)) {
                     continue;
                 }
                 $param = null;
                 // extracting double asterisk **.
                 if ($part == "**") {
                     $parsed[] = self::DOUBLE_ASTERISK_SUBPATTERN;
                     $param = $paramsCounter;
                     // extracting single asterisk *.
                 } else {
                     if ($part == "*") {
                         $parsed[] = self::SINGLE_ASTERISK_SUBPATTERN;
                         $param = $paramsCounter;
                         // extracting named parameters :my_param.
                     } else {
                         if ($part[0] == ":") {
                             if (true == preg_match("/^:([^\\:]+)\$/", $part, $matches)) {
                                 $parsed[] = self::SINGLE_ASTERISK_SUBPATTERN;
                                 $param = $matches[1];
                             }
                             // *.* pattern.
                         } else {
                             if (false !== strpos($part, "*")) {
                                 $subParts = explode("*", $part);
                                 $subParsed = array();
                                 foreach ($subParts as $subPart) {
                                     $subParsed[] = preg_quote($subPart, "#");
                                 }
                                 $parsed[] = "/" . implode(self::NO_SLASH_ASTERISK_SUBPATTERN, $subParsed);
                                 // everything else.
                             } else {
                                 $parsed[] = "/" . preg_quote($part, "#");
                             }
                         }
                     }
                 }
                 if (null === $param) {
                     continue;
                 }
                 if (false === array_key_exists($paramsCounter, $paramsList) || true === is_null($paramsList[$paramsCounter])) {
                     $paramsList[$paramsCounter] = $param;
                 }
                 $paramsCounter++;
             }
             $pattern = "#^" . implode("", $parsed) . self::OPTIONAL_SLASH_SUBPATTERN . "?\$#i";
         }
     }
     if (true == preg_match($pattern, $this->_request->getUrlPattern(), $matches)) {
         $this->_pattern = $pattern;
         $this->_matches = $matches;
         $this->_paramsList = isset($paramsList) ? $paramsList : array();
         return true;
     }
     return false;
 }
예제 #2
0
파일: App.php 프로젝트: nebiros/yasc
 /**
  * Process application functions.
  *
  * @return void
  */
 protected function _processFunctions()
 {
     $userFunctions = self::$_instance->getUserDefinedFunctions();
     if ($userFunctions === null) {
         throw new Yasc_Exception("No user defined functions");
     }
     $namespaces = self::$_instance->getNamespaces();
     foreach ($userFunctions as $name) {
         $func = new Yasc_Function($name);
         if ($namespaces !== null) {
             if (!in_array($func->getNamespaceName(), $namespaces)) {
                 continue;
             }
         }
         if (false === $func->getAnnotation()->hasAnnotation()) {
             continue;
         }
         self::$_instance->_functions[] = $func;
     }
 }