/** * * @param Ajde_Core_Route $route * @return Ajde_Document */ public static function fromRoute(Route $route) { $format = $route->getFormat(); $documentClass = "Ajde_Document_Format_" . ucfirst($format); if (!Autoloader::exists($documentClass)) { $exception = new Routing("Document format {$format} not found", 90009); Ajde::routingError($exception); } return new $documentClass(); }
public function detectShopSlug(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::get('routes'); array_unshift($routes, array('%^(shop)/(' . preg_quote($lastSlugPart) . ')$%' => array('module', 'slug'))); Config::getInstance()->routes = $routes; } } }
public function process() { switch ($this->_attributeParse()) { case 'form': $controller = Controller::fromRoute(new 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 = Controller::fromRoute(new Route('_core/component:formAjax')); $formAction = new 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 = Controller::fromRoute(new Route('_core/component:formUpload')); if (!isset($this->attributes['options']) || !isset($this->attributes['options']['saveDir']) || !isset($this->attributes['options']['extensions'])) { // TODO: throw new 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 = Controller::fromRoute(new Route('form/view.html')); $controller->setId($this->attributes['id']); return $controller->invoke(); break; } // TODO: throw new Exception(); }
/** * * @param Ajde_Core_Route $route * @return Ajde_View */ public static function fromRoute($route) { if (!$route instanceof Route) { $route = new 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); }
/** * * @param Ajde_Core_Route $route * @return Ajde_Controller */ public static function fromRoute(Route $route) { if ($controller = $route->getController()) { $moduleController = ucfirst($route->getModule()) . ucfirst($controller) . 'Controller'; } else { $moduleController = ucfirst($route->getModule()) . 'Controller'; } if (!Autoloader::exists($moduleController)) { // Prevent resursive 404 routing if (isset(Config::getInstance()->responseCodeRoute[Response::RESPONSE_TYPE_NOTFOUND])) { $notFoundRoute = new Route(Config::getInstance()->responseCodeRoute[Response::RESPONSE_TYPE_NOTFOUND]); if ($route->buildRoute() == $notFoundRoute->buildRoute()) { 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::get('site_root') . '\';">Go back to homepage</button>'); } } if (Autoloader::exists('Ajde_Exception')) { $exception = new 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; }