示例#1
0
 public function &setData($a_data)
 {
     $c = new Zoombi_Config($a_data);
     $data = $c->toArray();
     unset($c);
     return $this->add($data);
 }
示例#2
0
 /**
  * Set module config
  * @param mixed $a_config
  * @return Zoombi_Module
  */
 public final function &setConfig($a_config)
 {
     switch (gettype($a_config)) {
         case 'string':
             if (!file_exists($a_config) or !is_file($a_config)) {
                 $a_config = $this->fromBaseDir($a_config);
             }
             if (file_exists($a_config) and is_file($a_config) and is_readable($a_config)) {
                 $c = new Zoombi_Config($a_config);
                 $this->getConfig()->merge($c->getData());
                 unset($c);
             }
             break;
         case 'array':
         case 'object':
             if ($a_config instanceof Zoombi_Registry) {
                 $c = new Zoombi_Config($a_config);
                 $this->getConfig()->merge($c->getData());
                 unset($c);
             } else {
                 if ($a_config instanceof Zoombi_Module) {
                     $c = new Zoombi_Config($a_config);
                     $this->getConfig()->merge($a_config->getConfig()->getData());
                     unset($c);
                 }
             }
             break;
     }
     $this->setMode($this->getConfig()->getValue('mode', self::MODE_NORMAL));
     $plugins = $this->getConfig()->getValue('load.plugin');
     switch (gettype($plugins)) {
         case 'string':
             foreach (explode(' ', $plugins) as $p) {
                 $this->addPlugin($p);
             }
             break;
         case 'array':
             foreach ($plugins as $p) {
                 $this->addPlugin($p);
             }
             break;
     }
     $aclsource = $this->getConfig()->getValue('acl');
     switch (gettype($aclsource)) {
         case 'array':
         case 'object':
             $this->getAcl()->setData($aclsource);
             break;
         case 'string':
             $this->getAcl()->setData($this->fromBaseDir($aclsource));
             break;
         default:
             break;
     }
     return $this;
 }
示例#3
0
 public static final function getDefault($a_key)
 {
     return self::$defaults->get($a_key);
 }
示例#4
0
 /**
  * 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);
 }