public function &setData($a_data) { $c = new Zoombi_Config($a_data); $data = $c->toArray(); unset($c); return $this->add($data); }
/** * Execute application */ public final function execute($a_route_url = null) { // Attach error and exception handlers $olderr = error_reporting(E_ALL); set_error_handler(array(&$this, '_error_handler')); set_exception_handler(array(&$this, '_exception_handler')); register_shutdown_function(array(&$this, '_shutdown')); // Set application plugin manager listen global event dispatcher $this->getPluginManager()->setTarget(Zoombi::getDispatcher()); $this->getDispatcher()->connect('_triggerError', array($this, '_error_trigger')); try { // Notify for start execution $this->emit(new Zoombi_Event($this, 'preExecute')); // Notify befor route start if (!$this->getFlag(self::FLAG_NO_ROUTE)) { // Attach routing rules $routes = new Zoombi_Config(); $router = $this->getRouter(); $rs = $this->getConfig()->getValue('routes', null); switch (gettype($rs)) { case 'array': case 'object': $routes->setData($rs); break; case 'string': $cf = $rs; if (!file_exists($cf)) { $cf = $this->fromBaseDir($cf); } if (file_exists($cf)) { $routes->fromFile($cf); } break; } $ra = $routes->toArray(); $router->setRules($ra); unset($routes); $request = $a_route_url ? $a_route_url : $_SERVER['REQUEST_URI']; $url = new Zoombi_Url($this->getConfig()->getValue('baseurl')); if (strstr($request, $url->path) == 0) { $request = substr($request, strlen($url->path)); } $router->setRequest($request); $this->emit(new Zoombi_Event($this, 'preRoute', $router->getRequest())); $r_path = (string) $router->getRequest(); if (empty($r_path)) { $r_path = '_root_'; } //Do route rewriting $redirect = $router->rewrite($r_path); $router->setRedirect($redirect); $this->emit(new Zoombi_Event($this, 'postRoute', $router->getRedirect())); $path = clone $router->getRedirect(); $s = $path->getSegment(0); if ($s == $this->getName() or $s == Zoombi_Module::DEFAULT_MODULE_NAME) { if (!$this->getLoader()->hasController($s)) { $path->pop_start(); } } $this->exec_route = $this->_route((string) $path); if ($this->exec_route) { $this->getRouter()->setCurrent($this->exec_route); $this->route($this->exec_route); } } } catch (Exception $e) { switch ($e->getCode()) { case Zoombi_Exception_Controller::EXC_QUIT: $this->getConfig()->setValue('output', false); $this->emit(new Zoombi_Event($this, 'onQuit')); break; case Zoombi_Exception_Controller::EXC_QUIT_OUTPUT: $this->getConfig()->setValue('output', true); $this->emit(new Zoombi_Event($this, 'onQuit')); break; case Zoombi_Exception_Controller::EXC_AUTH: $this->emit(new Zoombi_Event($this, 'onError', 401, $e)); $this->emit(new Zoombi_Event($this, 'on401', $this->getRoute())); $this->route('_401_'); break; case Zoombi_Exception_Controller::EXC_DENY: $this->emit(new Zoombi_Event($this, 'onError', 403, $e)); $this->emit(new Zoombi_Event($this, 'on403', $this->getRoute())); $this->route('_403_'); break; case Zoombi_Exception_Controller::EXC_LOAD: case Zoombi_Exception_Controller::EXC_NO_FILE: case Zoombi_Exception_Controller::EXC_ACTION: $this->triggerError($e); $this->emit(new Zoombi_Event($this, 'onError', 404, $e)); $this->emit(new Zoombi_Event($this, 'on404', $this->getRoute())); $this->route('_404_'); break; default: $this->triggerError($e); $this->emit(new Zoombi_Event($this, 'onError', 500, $e)); $this->emit(new Zoombi_Event($this, 'on500', $e)); $this->route('_500_'); break; } } restore_error_handler(); restore_exception_handler(); if (Zoombi::ack($this->getConfig()->getValue('output', false))) { ob_start(); if ($this->outputLength() > 0) { $this->outputFlush(); } Zoombi_Response::getInstance()->appendContent(ob_get_contents()); ob_end_clean(); $this->emit(new Zoombi_Event($this, 'onOutput')); Zoombi_Response::getInstance()->output(); } $this->emit(new Zoombi_Event($this, 'postExecute')); error_reporting($olderr); }