Example #1
0
 public function &setData($a_data)
 {
     $c = new ZConfig($a_data);
     $data = $c->toArray();
     unset($c);
     return $this->add($data);
 }
 /**
  * Execute application
  */
 public final function execute()
 {
     $_errtype = E_ALL;
     // 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 ZEvent($this, 'preExecute'));
         // Attach error and exception handlers if applicatio execution mode is 'debug'
         if ($this->isMode(self::MODE_DEBUG)) {
             $old_errr = error_reporting($_errtype);
             set_error_handler(array($this, '_error_handler'), $_errtype);
             //set_exception_handler(array( $this, '_exception_handler' ));
         }
         // Notify befor route start
         //$this->emit(new ZEvent($this, 'preRoute'));
         if (!$this->getFlag(self::FLAG_NO_ROUTE)) {
             $request = null;
             $rvar = $_SERVER['REQUEST_URI'];
             // Attach routing rules to router
             $routes = new ZConfig();
             $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);
             $router->setRequest($rvar);
             $this->emit(new ZEvent($this, 'preRoute', $router->getRequest()));
             $redir = $router->rewrite($router->getRequest());
             $router->setRedirect($redir)->setCurrent($redir)->setForward($redir);
             $this->emit(new ZEvent($this, 'postRoute', $redir));
             $path = $router->getRedirect();
             if ($path->getSegment(0) == $this->getName()) {
                 $path->pop_start();
             }
             $curr = null;
             $fpath = $this->routePath($path, $curr, true);
             $router->setCurrent($curr)->setForward($curr);
             if ($fpath->isInvalid()) {
                 throw new ZException('Page not found', ZControllerException::EXC_ACTION);
             }
             if ($curr->getSegment(0) == $this->getName()) {
                 $curr->pop_start();
             }
             $this->route($curr);
         }
     } catch (ZException $e) {
         switch ($e->getCode()) {
             case ZControllerException::EXC_QUIT:
                 $this->getConfig()->setValue('output', false);
                 break;
             case ZControllerException::EXC_QUIT_OUTPUT:
                 $this->getConfig()->setValue('output', true);
                 break;
             case ZControllerException::EXC_LOAD:
             case ZControllerException::EXC_NO_FILE:
             case ZControllerException::EXC_ACTION:
                 $this->emit(new ZEvent($this, 'onError', 404, $e));
                 $this->emit(new ZEvent($this, 'on404', $this->getRoute()));
                 break;
             case ZControllerException::EXC_DENY:
                 $this->emit(new ZEvent($this, 'onError', 403, $e));
                 $this->emit(new ZEvent($this, 'on403', $this->getRoute()));
                 break;
             case ZControllerException::EXC_AUTH:
                 $this->emit(new ZEvent($this, 'onError', 401, $e));
                 $this->emit(new ZEvent($this, 'on401', $this->getRoute()));
                 break;
             default:
                 $this->emit(new ZEvent($this, 'onError', 500, $e));
                 $this->emit(new ZEvent($this, 'on500', $e));
                 break;
         }
     }
     $responce = ZResponse::getInstance();
     if (Zoombi::ack($this->getConfig()->getValue('output', false))) {
         ob_start();
         $this->emit(new ZEvent($this, 'onOutput'));
         if ($this->outputLength() > 0) {
             $this->outputFlush();
         }
         if (Zoombi::ack($this->getConfig()->get('showtrace', false))) {
             ZDebug::printTraces();
         }
         if (Zoombi::ack($this->getConfig()->get('showerror', false))) {
             $this->showErrors();
         }
         $cnt = ob_get_contents();
         ob_end_clean();
         $responce->appendContent($cnt);
     }
     $this->emit(new ZEvent($this, 'postExecute'));
     if ($this->isMode(self::MODE_DEBUG)) {
         restore_error_handler();
         error_reporting($old_errr);
     }
     $responce->output();
 }
 /**
  * Execute application
  */
 private final function _execute()
 {
     $_errtype = E_ALL;
     // 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 ZEvent($this, 'preExecute'));
         // Attach error and exception handlers if applicatio execution mode is 'debug'
         if ($this->isMode(self::MODE_DEBUG)) {
             $old_errr = error_reporting($_errtype);
             set_error_handler(array($this, '_error_handler'), $_errtype);
             //set_exception_handler(array( $this, '_exception_handler' ));
         }
         // Notify befor route start
         //$this->emit(new ZEvent($this, 'preRoute'));
         if (!$this->getFlag(self::FLAG_NO_ROUTE)) {
             $request = null;
             // Process request info
             $req_qry = explode('?', $_SERVER['REQUEST_URI'], 2);
             $request = array_shift($req_qry);
             // Get content rewrite variabe
             $rt = $this->getConfig()->getValue('routevar', 'rt');
             $rvar = null;
             if (isset($_GET[$rt])) {
                 $rvar = $_GET[$rt];
                 unset($_GET[$rt]);
             }
             if ($req_qry) {
                 $rvar .= '?' . $req_qry[0];
             }
             // Attach routing rules to router
             $routes = new ZConfig();
             $rs = $this->getConfig()->getValue('routes', null);
             switch (gettype($rs)) {
                 case 'array':
                 case 'object':
                     $routes->setData($rs);
                     break;
                 case 'string':
                     $routes->fromFile($this->fromBaseDir($rs));
                     break;
             }
             $this->getRouter()->setRules($routes->toArray());
             unset($routes);
             $this->emit(new ZEvent($this, 'preRoute', $rvar));
             $this->getRouter()->setRequest($rvar);
             $redir = $this->getRouter()->route($rvar);
             $p = new ZRoute($redir);
             if (!$this->getLoader()->hasModule($p->getModule()) and $p->getModule() != $this->getName()) {
                 $p->push_start($this->getName());
             }
             $fix = $this->fixroute($p);
             $this->getRouter()->setRedirect($fix)->setCurrent($fix)->setForward($fix);
             $this->emit(new ZEvent($this, 'postRoute', $fix));
             $approute = true;
             if ($p->getModule() == $this->getName()) {
                 $p->pop_start();
             }
             $this->route($p, array('approute'));
             $approute = false;
         }
     } catch (ZException $e) {
         switch ($e->getCode()) {
             case ZControllerException::EXC_QUIT:
                 $this->getConfig()->setValue('output', false);
                 break;
             case ZControllerException::EXC_QUIT_OUTPUT:
                 $this->getConfig()->setValue('output', true);
                 break;
             case ZControllerException::EXC_LOAD:
             case ZControllerException::EXC_NO_FILE:
             case ZControllerException::EXC_ACTION:
                 $this->emit(new ZEvent($this, 'onError', 404, $e));
                 $this->emit(new ZEvent($this, 'on404', $this->getRoute()));
                 break;
             case ZControllerException::EXC_DENY:
                 $this->emit(new ZEvent($this, 'onError', 403, $e));
                 $this->emit(new ZEvent($this, 'on403', $this->getRoute()));
                 break;
             case ZControllerException::EXC_AUTH:
                 $this->emit(new ZEvent($this, 'onError', 401, $e));
                 $this->emit(new ZEvent($this, 'on401', $this->getRoute()));
                 break;
             default:
                 $this->emit(new ZEvent($this, 'onError', 500, $e));
                 $this->emit(new ZEvent($this, 'on500', $e));
                 break;
         }
     }
     if (Zoombi::ack($this->getConfig()->getValue('output', false))) {
         ob_start();
         if (Zoombi::ack($this->getConfig()->get('showerror', 'false'))) {
             foreach ($this->m_errors as $e) {
                 $this->showError($e);
             }
         }
         $this->emit(new ZEvent($this, 'onOutput'));
         $cnt = ob_get_contents();
         ob_end_clean();
         ZResponse::getInstance()->setContent(ZResponse::getInstance()->getContent() . $cnt);
     }
     $this->emit(new ZEvent($this, 'postExecute'));
     if ($this->isMode(self::MODE_DEBUG)) {
         restore_error_handler();
         error_reporting($old_errr);
     }
     ZResponse::getInstance()->output();
 }
Example #4
0
 /**
  * Set module config
  * @param mixed $a_config
  * @return ZModule
  */
 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 ZConfig($a_config);
                 $this->getConfig()->merge($c->getData());
                 unset($c);
             }
             break;
         case 'array':
         case 'object':
             if ($a_config instanceof ZRegistry) {
                 $c = new ZConfig($a_config);
                 $this->getConfig()->merge($c->getData());
                 unset($c);
                 break;
             } else {
                 if ($a_config instanceof ZModule) {
                     $c = new ZConfig($a_config);
                     $this->getConfig()->merge($a_config->getConfig()->getData());
                     unset($c);
                     break;
                 }
             }
     }
     $this->setMode($this->getConfig()->getValue('mode', self::MODE_NORMAL));
     $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;
 }
 /**
  * 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'));
     // 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 ZEvent($this, 'preExecute'));
         // Notify befor route start
         if (!$this->getFlag(self::FLAG_NO_ROUTE)) {
             // Attach routing rules to router
             $routes = new ZConfig();
             $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 ZUrl($this->getConfig()->getValue('baseurl'));
             if (strstr($request, $url->path) == 0) {
                 $request = substr($request, strlen($url->path));
             }
             $router->setRequest($request);
             $this->emit(new ZEvent($this, 'preRoute', $router->getRequest()));
             $redirect = $router->rewrite((string) $router->getRequest());
             $router->setRedirect($redirect);
             $this->emit(new ZEvent($this, 'postRoute', $router->getRedirect()));
             $path = clone $router->getRedirect();
             $s = $path->getSegment(0);
             if ($s == $this->getName() or $s == ZModule::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 ZControllerException::EXC_QUIT:
                 $this->getConfig()->setValue('output', false);
                 $this->emit(new ZEvent($this, 'onQuit'));
                 break;
             case ZControllerException::EXC_QUIT_OUTPUT:
                 $this->getConfig()->setValue('output', true);
                 $this->emit(new ZEvent($this, 'onQuit'));
                 break;
             case ZControllerException::EXC_AUTH:
                 $this->emit(new ZEvent($this, 'onError', 401, $e));
                 $this->emit(new ZEvent($this, 'on401', $this->getRoute()));
                 break;
             case ZControllerException::EXC_DENY:
                 $this->emit(new ZEvent($this, 'onError', 403, $e));
                 $this->emit(new ZEvent($this, 'on403', $this->getRoute()));
                 break;
             case ZControllerException::EXC_LOAD:
             case ZControllerException::EXC_NO_FILE:
             case ZControllerException::EXC_ACTION:
                 $this->emit(new ZEvent($this, 'onError', 404, $e));
                 $this->emit(new ZEvent($this, 'on404', $this->getRoute()));
                 break;
             default:
                 $this->emit(new ZEvent($this, 'onError', 500, $e));
                 $this->emit(new ZEvent($this, 'on500', $e));
                 break;
         }
     }
     restore_error_handler();
     restore_exception_handler();
     if (Zoombi::ack($this->getConfig()->getValue('output', false))) {
         ob_start();
         if ($this->outputLength() > 0) {
             $this->outputFlush();
         }
         if (Zoombi::ack($this->getConfig()->get('showtrace', false))) {
             ZDebug::printTraces();
         }
         if (Zoombi::ack($this->getConfig()->get('showerror', false))) {
             $this->showErrors();
         }
         ZResponse::getInstance()->appendContent(ob_get_contents());
         ob_end_clean();
         $this->emit(new ZEvent($this, 'onOutput'));
         ZResponse::getInstance()->output();
     }
     $this->emit(new ZEvent($this, 'postExecute'));
     error_reporting($olderr);
 }
 /**
  * Execute application
  */
 protected final function _execute()
 {
     // Start output collection
     ob_start();
     // Get application execution mode from config
     $this->setMode(strtolower(strval($this->getConfig()->getValue('mode', self::MODE_NORMAL))));
     // Attach error and exception handlers if applicatio execution mode is 'debug'
     if ($this->isMode(self::MODE_DEBUG)) {
         $old_errr = error_reporting(E_ALL);
         set_error_handler(array($this, '_error_handler'), E_ALL);
         set_exception_handler(array($this, '_exception_handler'));
     }
     // Set application plugin manager listen global event dispatcher
     $this->getPluginManager()->setTarget(Zoombi::getDispatcher());
     // Notify for start execution
     $this->emit(new ZEvent($this, 'preExecute'));
     // Notify befor route start
     $this->emit(new ZEvent($this, 'preRoute'));
     if (!$this->getFlag(self::FLAG_NO_ROUTE)) {
         $request = null;
         // Process request info
         $req_qry = explode('?', $_SERVER['REQUEST_URI'], 2);
         //if( count($req_qry) > 1 )
         $request = array_shift($req_qry);
         // Get content rewrite variabe
         $rt = $this->getConfig()->getValue('routevar', 'rt');
         $rvar = null;
         if (isset($_GET[$rt])) {
             $rvar = $_GET[$rt];
             unset($_GET[$rt]);
         }
         if ($req_qry) {
             $rvar .= '?' . $req_qry[0];
         }
         // Attach routing rules to router
         $rc = new ZConfig($this->fromApplicationBaseDir($this->getConfig()->getValue('routes', null)));
         $router = new ZRouter($rvar, $rc->toArray());
         unset($rc);
         $this->setRouter($router);
         //$router->route();
         if ($this->isMode(self::MODE_DEBUG)) {
             Zoombi::log('Request route: ' . $router->getRequest(), 'FrontController');
         }
         // Get routing result
         $route = $router->getRedirect();
         if ($this->isMode(self::MODE_DEBUG)) {
             Zoombi::log('Redirect route: ' . $route, 'FrontController');
         }
         // Notify for end of routing process
         $this->emit(new ZEvent($this, 'postRoute', $route));
         // Notify before controller has created
         $this->emit(new ZEvent($this, 'preController', $route->getController()));
         if (!$this->getFlag(self::FLAG_NO_CONTROLLER)) {
             // Check if we have requested controller
             if (!$this->_processRoute($route, $_code, $_message)) {
                 if ($_code == ZLoader::EXC_NO_FILE) {
                     $this->emit(new ZEvent($this, 'onError', 404, $route, $_code, $_message));
                     $this->emit(new ZEvent($this, 'on404', $route, $_code, $_message));
                 } else {
                     $this->emit(new ZEvent($this, 'onError', 500, $route, $_code, $_message));
                     $this->emit(new ZEvent($this, 'on500', $route, $_code, $_message));
                 }
             }
             $route = $this->getRouter()->getRedirect();
             // Notify after controller be created
             $this->emit(new ZEvent($this, 'postController', $route->getController()));
             // Processing controller
             $ctl = $this->getController();
             if ($ctl) {
                 if (!$ctl->hasAction($route->getAction())) {
                     $route->action = $this->getConfig()->getValue('controller.default_action', 'index');
                 }
                 $router->setCurrent($route)->setForward($route);
                 if ($this->isMode(self::MODE_DEBUG)) {
                     Zoombi::log('Current route: ' . (string) $router->getCurrent(), 'FrontController');
                 }
                 $this->emit(new ZEvent($this, 'preAction', $route->action));
                 if (!$this->getFlag(self::FLAG_NO_ACTION)) {
                     try {
                         $this->m_return = $ctl->requestAction($route->action, $route->params);
                         $this->emit(new ZEvent($this, 'postAction'));
                     } catch (ZControllerException $e) {
                         if ($e->getCode() != ZControllerException::EXC_QUIT_OUTPUT) {
                             $this->emit(new ZEvent($this, 'onError', 500, $e->getMessage()));
                             $this->emit(new ZEvent($this, 'on500', $e->getMessage()));
                             if ($this->isMode(self::MODE_DEBUG)) {
                                 trigger_error($e->getMessage(), Zoombi::EXC_ERROR);
                             }
                         } else {
                             $this->getConfig()->setValue('output', false);
                         }
                     }
                 }
             }
         }
     }
     $this->setOutput(ob_get_contents());
     ob_end_clean();
     $flag = $this->getConfig()->getValue('output', false);
     switch (strtolower(trim(strval($flag)))) {
         case '1':
         case 'ok':
         case 'on':
         case 'yes':
         case 'true':
             $this->emit(new ZEvent($this, 'onOutput'));
             $this->outputFlush();
             if ($this->isMode(self::MODE_DEBUG)) {
                 $c = new ZDummyController($this, 'DummyController');
                 $c->renderEach(Zoombi::fromFrameworkDir('Views' . Zoombi::DS . 'view_error.php'), $this->m_errors);
                 unset($c);
             }
             break;
     }
     $this->emit(new ZEvent($this, 'postExecute'));
     if ($this->isMode(self::MODE_DEBUG)) {
         restore_exception_handler();
         restore_error_handler();
         error_reporting($old_errr);
     }
 }