protected function addTimeoutWarning() { // Add timeout warning to layout if ($this->getLoggedInUser() !== false) { Dispatcher::register('Ajde_Layout', 'beforeGetContents', 'requireTimeoutWarning'); } }
public function __bootstrap() { Dispatcher::register('Ajde_Core_Route', 'onAfterLangSet', array($this, 'setHomepage')); Dispatcher::register('Ajde_Core_Route', 'onAfterRouteSet', array($this, 'detectNodeSlug')); Dispatcher::register('Ajde_Core_Route', 'onAfterRouteSet', array($this, 'detectShopSlug')); return true; }
public function __fallback($method, $arguments) { if (Dispatcher::has('Ajde_Controller', 'call')) { return Dispatcher::trigger('Ajde_Controller', 'call', array($method, $arguments)); } throw new AjdeException("Call to undefined method " . get_class($this) . "::{$method}()", 90006); }
public function __construct() { /* * We add the resources before the template is included, otherwise the * layout resources never make it into the <head> section. */ Dispatcher::register('Ajde_Template', 'beforeGetContents', array($this, 'autoAddResources')); parent::__construct(); }
public static function register($controller) { // Extend Ajde_Controller if (!Dispatcher::has('Ajde_Controller', 'call', 'Ajde_Collection::extendController')) { Dispatcher::register('Ajde_Controller', 'call', 'Ajde_Collection::extendController'); } // Extend autoloader if ($controller instanceof Controller) { Autoloader::addDir(MODULE_DIR . $controller->getModule() . '/model/'); } elseif ($controller === '*') { self::registerAll(); } else { Autoloader::addDir(MODULE_DIR . $controller . '/model/'); } }
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 = Lang::getInstance(); if ($lang = $langInstance->getAvailableLang($shortLang)) { $this->set("lang", $lang); $route = substr($route, 3); // set global lang $langInstance->setGlobalLang($lang); } } Dispatcher::trigger($this, 'onAfterLangSet'); 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; } Dispatcher::trigger($this, 'onAfterRouteSet'); // Get route parts $routeParts = $this->_extractRouteParts(); if (empty($routeParts)) { $exception = new Routing(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); } }
public function fireCrudLoadedOnModel($model) { Dispatcher::trigger($model, 'afterCrudLoaded'); }
public static function registerDocumentProcessor($format, $registerOn = 'layout') { $documentProcessors = Config::get('documentProcessors'); if (is_array($documentProcessors) && isset($documentProcessors[$format])) { foreach ($documentProcessors[$format] as $processor) { $processorClass = 'Ajde_Document_Processor_' . ucfirst($format) . '_' . $processor; if (!Autoloader::exists($processorClass)) { // TODO: throw new Exception('Processor ' . $processorClass . ' not found', 90022); } if ($registerOn == 'layout') { Dispatcher::register('Ajde_Layout', 'beforeGetContents', $processorClass . '::preProcess'); Dispatcher::register('Ajde_Layout', 'afterGetContents', $processorClass . '::postProcess'); } elseif ($registerOn == 'compressor') { Dispatcher::register('Ajde_Resource_Local_Compressor', 'beforeCompress', $processorClass . '::preCompress'); Dispatcher::register('Ajde_Resource_Local_Compressor', 'afterCompress', $processorClass . '::postCompress'); } else { // TODO: throw new Exception('Document processor must be registered on either \'layout\' or \'compressor\''); } } } }
public function saveCache() { // Bind document processors to compressor Document::registerDocumentProcessor($this->getType(), 'compressor'); // Prepare content $this->_contents = ''; foreach ($this->_resources as $resource) { /* @var $resource Ajde_Resource_Local */ $this->_contents .= $resource->getContents() . PHP_EOL; } if (!is_writable($this->getBase())) { throw new Exception(sprintf("Directory %s is not writable", $this->getBase()), 90014); } // Execute compression Dispatcher::trigger($this, 'beforeCompress'); $this->compress(); Dispatcher::trigger($this, 'afterCompress'); // Save file to cache folder file_put_contents($this->getFilename(), $this->_contents); }
public function getContents() { if (!isset($this->_contents)) { Dispatcher::trigger($this, 'beforeGetContents'); Cache::getInstance()->addFile($this->getFilename()); $contents = $this->getParser()->parse($this); $this->setContents($contents); Dispatcher::trigger($this, 'afterGetContents'); } return $this->_contents; }
public function run() { // For debugger $this->addTimer('<i>Application</i>'); // Create fresh response $timer = $this->addTimer('Create response'); $response = new Response(); $this->setResponse($response); $this->endTimer($timer); Dispatcher::trigger($this, 'onAfterResponseCreated'); // Bootstrap init $timer = $this->addTimer('Run bootstrap queue'); $bootstrap = new Bootstrap(); $bootstrap->run(); $this->endTimer($timer); Dispatcher::trigger($this, 'onAfterBootstrap'); // Get request $timer = $this->addTimer('Read in global request'); $request = Request::fromGlobal(); $this->setRequest($request); $this->endTimer($timer); Dispatcher::trigger($this, 'onAfterRequestCreated'); // Get route $timer = $this->addTimer('Initialize route'); $route = $request->initRoute(); $this->setRoute($route); $this->endTimer($timer); Dispatcher::trigger($this, 'onAfterRouteInitialized'); // Load document $timer = $this->addTimer('Create document'); $document = Document::fromRoute($route); $this->setDocument($document); $this->endTimer($timer); Dispatcher::trigger($this, 'onAfterDocumentCreated'); // Load controller $timer = $this->addTimer('Load controller'); $controller = Controller::fromRoute($route); $this->setController($controller); $this->endTimer($timer); Dispatcher::trigger($this, 'onAfterControllerCreated'); // Invoke controller action $timer = $this->addTimer('Invoke controller'); $actionResult = $controller->invoke(); $document->setBody($actionResult); $this->endTimer($timer); Dispatcher::trigger($this, 'onAfterControllerInvoked'); // Get document contents $timer = $this->addTimer('Render document'); $contents = $document->render(); $this->endTimer($timer); Dispatcher::trigger($this, 'onAfterDocumentRendered'); // Let the cache handle the contents and have it saved to the response $timer = $this->addTimer('Save to response'); $cache = Cache::getInstance(); $cache->setContents($contents); $cache->saveResponse(); $this->endTimer($timer); Dispatcher::trigger($this, 'onAfterResponseCreated'); // Output the buffer $response->send(); Dispatcher::trigger($this, 'onAfterResponseSent'); }