Exemplo n.º 1
0
 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);
 }
Exemplo n.º 2
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 = 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);
     }
 }
Exemplo n.º 3
0
 public function fireCrudLoadedOnModel($model)
 {
     Dispatcher::trigger($model, 'afterCrudLoaded');
 }
Exemplo n.º 4
0
 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);
 }
Exemplo n.º 5
0
 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;
 }
Exemplo n.º 6
0
 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');
 }