Example #1
0
 /**
  * @param Ajde_Core_Route $route
  *
  * @return Ajde_Controller
  */
 public static function fromRoute(Ajde_Core_Route $route)
 {
     if ($controller = $route->getController()) {
         $moduleController = ucfirst($route->getModule()) . ucfirst($controller) . 'Controller';
     } else {
         $moduleController = ucfirst($route->getModule()) . 'Controller';
     }
     if (!class_exists($moduleController)) {
         // Prevent resursive 404 routing
         $errorRoutes = config('routes.errors');
         if (isset($errorRoutes[Ajde_Http_Response::RESPONSE_TYPE_NOTFOUND])) {
             $notFoundRoute = new Ajde_Core_Route($errorRoutes[Ajde_Http_Response::RESPONSE_TYPE_NOTFOUND]);
             if ($route->buildRoute() == $notFoundRoute->buildRoute()) {
                 Ajde_Http_Response::setResponseType(404);
                 die('<h2>Ouch, something broke.</h2><p>This is serious. We tried to give you a nice error page, but even that failed.</p><button onclick="location.href=\'' . config('app.rootUrl') . '\';">Go back to homepage</button>');
             }
         }
         if (class_exists('Ajde_Exception')) {
             $exception = new Ajde_Core_Exception_Routing("Controller {$moduleController} for module {$route->getModule()} not found", 90008);
         } else {
             // Normal exception here to prevent [Class 'Ajde_Exception' not found] errors...
             $exception = new Exception("Controller {$moduleController} for module {$route->getModule()} not found");
         }
         Ajde::routingError($exception);
     }
     $controller = new $moduleController($route->getAction(), $route->getFormat());
     $controller->_route = $route;
     foreach ($route->values() as $part => $value) {
         $controller->set($part, $value);
     }
     return $controller;
 }
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
File: Cms.php Project: nabble/ajde
 public function detectShopSlug(Ajde_Core_Route $route)
 {
     $slug = $route->getRoute();
     $slug = trim($slug, '/');
     $lastSlash = strrpos($slug, '/');
     if ($lastSlash !== false) {
         $lastSlugPart = substr($slug, $lastSlash + 1);
         $product = ProductModel::fromSlug($lastSlugPart);
         if ($product) {
             $route->setRoute($slug);
             $routes = config('routes.list');
             array_unshift($routes, ['%^(shop)/(' . preg_quote($lastSlugPart) . ')$%' => ['module', 'slug']]);
             Config::set('routes.list', $routes);
         }
     }
 }
Example #4
0
File: Form.php Project: nabble/ajde
 public function process()
 {
     switch ($this->_attributeParse()) {
         case 'form':
             $controller = Ajde_Controller::fromRoute(new Ajde_Core_Route('_core/component:form'));
             $controller->setFormAction($this->attributes['route']);
             $controller->setFormId(issetor($this->attributes['id'], spl_object_hash($this)));
             $controller->setExtraClass(issetor($this->attributes['class'], ''));
             $controller->setInnerXml($this->innerXml);
             return $controller->invoke();
             break;
         case 'ajax':
             $controller = Ajde_Controller::fromRoute(new Ajde_Core_Route('_core/component:formAjax'));
             $formAction = new Ajde_Core_Route($this->attributes['route']);
             $formAction->setFormat(issetor($this->attributes['format'], 'json'));
             $controller->setFormAction($formAction->__toString());
             $controller->setFormFormat(issetor($this->attributes['format'], 'json'));
             $controller->setFormId(issetor($this->attributes['id'], spl_object_hash($this)));
             $controller->setExtraClass(issetor($this->attributes['class'], ''));
             $controller->setInnerXml($this->innerXml);
             return $controller->invoke();
             break;
         case 'upload':
             $controller = Ajde_Controller::fromRoute(new Ajde_Core_Route('_core/component:formUpload'));
             if (!isset($this->attributes['options']) || !isset($this->attributes['options']['saveDir']) || !isset($this->attributes['options']['extensions'])) {
                 // TODO:
                 throw new Ajde_Component_Exception('Options saveDir and extensions must be set for AC.Form.Upload');
             }
             $controller->setName($this->attributes['name']);
             $controller->setOptions($this->attributes['options']);
             $controller->setInputId(issetor($this->attributes['id'], spl_object_hash($this)));
             $controller->setExtraClass(issetor($this->attributes['class'], ''));
             return $controller->invoke();
             break;
         case 'embed':
             $controller = Ajde_Controller::fromRoute(new Ajde_Core_Route('form/view.html'));
             $controller->setId($this->attributes['id']);
             return $controller->invoke();
             break;
     }
     // TODO:
     throw new Ajde_Component_Exception();
 }
Example #5
0
File: View.php Project: nabble/ajde
 /**
  * @param Ajde_Core_Route $route
  *
  * @return Ajde_View
  */
 public static function fromRoute($route)
 {
     if (!$route instanceof Ajde_Core_Route) {
         $route = new Ajde_Core_Route($route);
     }
     $base = MODULE_DIR . $route->getModule() . '/';
     $action = $route->getController() ? $route->getController() . '/' . $route->getAction() : $route->getAction();
     $format = $route->getFormat();
     return new self($base, $action, $format);
 }
Example #6
0
 /**
  * @return Ajde_Core_Route
  */
 public function getRoute()
 {
     if (!isset($this->_route)) {
         $route = $this->extractRoute();
         $this->_route = new Ajde_Core_Route($route);
         foreach ($this->_route->values() as $part => $value) {
             if (!$this->hasNotEmpty($part)) {
                 $this->set($part, $value);
             }
         }
     }
     return $this->_route;
 }
Example #7
0
 /**
  * @return Ajde_Core_Route
  */
 public function getRoute()
 {
     if (!isset($this->_route)) {
         $routeKey = '_route';
         if (!$this->has($routeKey)) {
             $this->set($routeKey, false);
         }
         $this->_route = new Ajde_Core_Route($this->getRaw($routeKey));
         foreach ($this->_route->values() as $part => $value) {
             $this->set($part, $value);
         }
     }
     return $this->_route;
 }
Example #8
0
 /**
  *
  * @param Ajde_Core_Route $route
  * @return Ajde_Controller
  */
 public static function fromRoute(Ajde_Core_Route $route)
 {
     if ($controller = $route->getController()) {
         $moduleController = ucfirst($route->getModule()) . ucfirst($controller) . 'Controller';
     } else {
         $moduleController = ucfirst($route->getModule()) . 'Controller';
     }
     if (!Ajde_Core_Autoloader::exists($moduleController)) {
         $exception = new Ajde_Exception("Controller {$moduleController} for module {$route->getModule()} not found", 90008);
         Ajde::routingError($exception);
     }
     $controller = new $moduleController($route->getAction(), $route->getFormat());
     $controller->_route = $route;
     foreach ($route->values() as $part => $value) {
         $controller->set($part, $value);
     }
     return $controller;
 }
Example #9
0
 public function getCanonicalUrl()
 {
     return $this->_route->buildRoute();
 }