Example #1
0
 public function __construct($route)
 {
     // See if first part is language code (i.e. first part is exactly
     // two characters in length)
     if (strlen($route) === 2 || substr($route, 2, 1) === '/') {
         $shortLang = substr($route, 0, 2);
         $langInstance = Ajde_Lang::getInstance();
         if ($lang = $langInstance->getAvailableLang($shortLang)) {
             $this->set("lang", $lang);
             $route = substr($route, 3);
         }
     }
     if (!$route) {
         $route = Config::get('homepageRoute');
     }
     // Check for route aliases
     $aliases = Config::get("aliases");
     if (array_key_exists($route, $aliases)) {
         $this->_route = $aliases[$route];
     } else {
         $this->_route = $route;
     }
     // Get route parts
     $routeParts = $this->_extractRouteParts();
     if (empty($routeParts)) {
         $exception = new Ajde_Exception(sprintf("Invalid route: %s", $route), 90021);
         Ajde::routingError($exception);
     }
     $defaultParts = Config::get('defaultRouteParts');
     $parts = array_merge($defaultParts, $routeParts);
     foreach ($parts as $part => $value) {
         $this->set($part, $value);
     }
 }
Example #2
0
 /**
  *
  * @param Ajde_Core_Route $route
  * @return Ajde_Document
  */
 public static function fromRoute(Ajde_Core_Route $route)
 {
     $format = $route->getFormat();
     $documentClass = "Ajde_Document_Format_" . ucfirst($format);
     if (!Ajde_Core_Autoloader::exists($documentClass)) {
         $exception = new Ajde_Exception("Document format {$format} not found", 90009);
         Ajde::routingError($exception);
     }
     return new $documentClass();
 }
Example #3
0
    protected function setFileinfo()
    {
        if (($fileInfo = $this->getFileInfo()) === false) {
            $exception = new Ajde_Core_Exception_Routing(sprintf('Template file in %s,
					for action %s with format %s not found', $this->getBase(), $this->getAction(), $this->getFormat()), 90010);
            Ajde::routingError($exception);
        }
        $className = 'Ajde_Template_Parser_' . $fileInfo['parser'];
        $parser = new $className($this);
        $this->setFilename($fileInfo['filename']);
        $this->setParser($parser);
    }
Example #4
0
 public function __construct($base, $action, $format = 'html')
 {
     $this->setBase($base);
     $this->setAction($action);
     $this->setFormat($format);
     if (($fileInfo = $this->getFileInfo()) === false) {
         $exception = new Ajde_Exception(sprintf("Template file in %s,\n\t\t\t\t\tfor action %s with format %s not found", $base, $action, $format), 90010);
         Ajde::routingError($exception);
     }
     $className = 'Ajde_Template_Parser_' . $fileInfo['parser'];
     $parser = new $className($this);
     $this->setFilename($fileInfo['filename']);
     $this->setParser($parser);
 }
Example #5
0
 public function __construct($route)
 {
     $this->_originalRoute = $route;
     // See if first part is language code (i.e. first part is exactly
     // two characters in length)
     if (strlen($route) === 2 || substr($route, 2, 1) === '/') {
         $shortLang = substr($route, 0, 2);
         $langInstance = Ajde_Lang::getInstance();
         if ($lang = $langInstance->getAvailableLang($shortLang)) {
             $this->set('lang', $lang);
             $route = substr($route, 3);
             // set global lang
             $langInstance->setGlobalLang($lang);
         }
     }
     Ajde_Event::trigger($this, 'onAfterLangSet');
     if (!$route) {
         $route = config('routes.homepage');
     }
     // Check for route aliases
     $aliases = config('routes.aliases');
     if (array_key_exists($route, $aliases)) {
         $this->_route = $aliases[$route];
     } else {
         $this->_route = $route;
     }
     Ajde_Event::trigger($this, 'onAfterRouteSet');
     // Get route parts
     $routeParts = $this->_extractRouteParts();
     if (empty($routeParts)) {
         $exception = new Ajde_Core_Exception_Routing(sprintf('Invalid route: %s', $route), 90021);
         Ajde::routingError($exception);
     }
     $defaultParts = config('routes.default');
     $parts = array_merge($defaultParts, $routeParts);
     foreach ($parts as $part => $value) {
         $this->set($part, $value);
     }
 }
Example #6
0
 /**
  * @param string|null $action
  * @param string|null $format
  *
  * @throws Ajde_Exception
  * @throws Exception
  *
  * @return mixed
  */
 public function invoke($action = null, $format = null)
 {
     $timerKey = Ajde::app()->addTimer((string) $this->_route);
     $action = issetor($action, $this->getAction());
     $format = issetor($format, $this->getFormat());
     $method = strtolower($_SERVER['REQUEST_METHOD']);
     $tryTheseFunctions = [];
     $formatFunction = $action . ucfirst($format);
     $defaultFunction = $action . 'Default';
     $emptyFunction = $action;
     $tryTheseFunctions[] = $formatFunction . ucfirst($method);
     $tryTheseFunctions[] = $defaultFunction . ucfirst($method);
     $tryTheseFunctions[] = $emptyFunction . ucfirst($method);
     $tryTheseFunctions[] = $formatFunction;
     $tryTheseFunctions[] = $defaultFunction;
     $tryTheseFunctions[] = $emptyFunction;
     $invokeFunction = '';
     foreach ($tryTheseFunctions as $tryFunction) {
         if (method_exists($this, $tryFunction)) {
             $invokeFunction = $tryFunction;
             break;
         }
     }
     //        dump(get_class($this) . '::' .  $invokeFunction);
     if (!$invokeFunction) {
         $exception = new Ajde_Core_Exception_Routing(sprintf('Action %s for module %s not found', $this->getAction(), $this->getModule()), 90011);
         Ajde::routingError($exception);
     }
     $return = true;
     if (method_exists($this, 'beforeInvoke')) {
         $return = $this->beforeInvoke();
         if ($return !== true && $return !== false) {
             // TODO:
             throw new Ajde_Exception(sprintf('beforeInvoke() must return either TRUE or FALSE'));
         }
     }
     if ($return === true) {
         $return = $this->{$invokeFunction}();
         if (method_exists($this, 'afterInvoke')) {
             $this->afterInvoke();
         }
     }
     Ajde::app()->endTimer($timerKey);
     return $return;
 }
Example #7
0
 public function invoke($action = null, $format = null)
 {
     $timerKey = Ajde::app()->addTimer((string) $this->_route);
     $action = issetor($action, $this->getAction());
     $format = issetor($format, $this->getFormat());
     $emptyFunction = $action;
     $defaultFunction = $action . "Default";
     $formatFunction = $action . ucfirst($format);
     if (method_exists($this, $formatFunction)) {
         $actionFunction = $formatFunction;
     } elseif (method_exists($this, $defaultFunction)) {
         $actionFunction = $defaultFunction;
     } elseif (method_exists($this, $emptyFunction)) {
         $actionFunction = $emptyFunction;
     } else {
         $exception = new Ajde_Exception(sprintf("Action %s for module %s not found", $this->getAction(), $this->getModule()), 90011);
         Ajde::routingError($exception);
     }
     $return = true;
     if (method_exists($this, 'beforeInvoke')) {
         $return = $this->beforeInvoke();
         if ($return !== true && $return !== false) {
             // TODO:
             throw new Ajde_Exception(sprintf("beforeInvoke() must return either TRUE or FALSE"));
         }
     }
     if ($return === true) {
         $return = $this->{$actionFunction}();
         if (method_exists($this, 'afterInvoke')) {
             $this->afterInvoke();
         }
     }
     Ajde::app()->endTimer($timerKey);
     return $return;
 }