Beispiel #1
0
 public function afterRoute(&$className, &$method)
 {
     if ($this->handle) {
         // Check if method allow json output
         $reflection = new ReflectionMethod($className, $method);
         $markers = ReflectionHelper::parseDocComment($reflection);
         if ($markers['JSONP']) {
             $this->allowCallback = true;
         }
         if (!$markers['JSON'] && !$markers['JSONP']) {
             throw new Error('The request URL is not available', 403);
         }
     }
 }
Beispiel #2
0
 public function generateRouterList()
 {
     $this->StaticRoute = array();
     $this->DynamicRoute = array();
     $this->FallbackRouter = array();
     try {
         self::includeDir(LIBRARY_PATH . 'Controller');
         $classList = get_declared_classes();
         foreach ($classList as $className) {
             if (substr($className, 0, 10) != 'Controller') {
                 continue;
             }
             $reflectionClass = new \ReflectionClass($className);
             $methods = $reflectionClass->getMethods();
             foreach ($methods as $reflectionMethod) {
                 $markers = ReflectionHelper::parseDocComment($reflectionMethod);
                 $callback = array($reflectionClass->getName(), $reflectionMethod->getName());
                 if ($markers['Home']) {
                     $this->StaticRoute['@home'] = $callback;
                 }
                 if ($markers['Route']) {
                     $path = strtolower(trim($markers['Route'], ' /'));
                     $this->StaticRoute[$path] = $callback;
                 }
                 if ($markers['DynamicRoute']) {
                     // Convert wildcard to regular expression
                     $regexp = '/^' . preg_quote(trim($markers['DynamicRoute'], ' /'), '/') . '$/i';
                     $regexp = str_replace('\\{any\\}', '(.+)', $regexp);
                     $regexp = str_replace('\\{string\\}', '(\\w+)', $regexp);
                     $regexp = str_replace('\\{int\\}', '(\\d+)', $regexp);
                     $this->DynamicRoute[] = array('callback' => $callback, 'regexp' => $regexp);
                 }
                 if ($markers['FallbackRoute'] || $markers['FallBackRoute']) {
                     if ($this->FallbackRouter) {
                         throw new Error('Fallback route was already defined in ' . $this->FallbackRouter[0] . '->' . $this->FallbackRouter[1]);
                     }
                     $this->FallbackRouter = $callback;
                 }
             }
         }
     } catch (\Exception $e) {
         if (DEBUG_ENABLE) {
             throw $e;
         } else {
             throw new Error('Internal Error: Cannot parse router file');
         }
     }
 }