Exemplo n.º 1
0
 public function __call($a_name, $a_args)
 {
     if (method_exists($this->query, $a_name)) {
         $r = call_user_func_array(array(&$this->query, $a_name), $a_args);
         if ($r instanceof Zoombi_SqlBuilder) {
             return $this;
         }
         return $r;
     }
     if (Zoombi::getApplication()->isModeDebug()) {
         $this->triggerError('Bad model method: ' . $a_name);
     }
 }
 public function &__get($a_property)
 {
     switch ($a_property) {
         default:
             break;
         case 'application':
             return Zoombi::getApplication();
         case 'database':
             return Zoombi::getApplication()->getDatabase();
         case 'router':
             return $this->getModule()->getRouter();
         case 'session':
             return Zoombi::getApplication()->getSession();
         case 'request':
             return ZRequest::getInstance();
         case 'response':
             return ZResponse::getInstance();
         case 'module':
             return $this->getModule();
         case 'route':
             return $this->getModule()->getRoute();
         case 'registry':
             return $this->getModule()->getRegistry();
         case 'config':
             return $this->getModule()->getConfig();
         case 'language':
             return $this->getModule()->getLanguage();
         case 'load':
             return $this->getModule()->getLoader();
         case 'acl':
             return $this->getModule()->getAcl();
     }
     try {
         return $this->getProperty($a_property);
     } catch (ZException $e) {
         if ($e->getCode() == ZException::EXC_NO_PROPERTY) {
             return Zoombi::$null;
         }
     }
     return Zoombi::$null;
 }
Exemplo n.º 3
0
 /**
  * Log message
  * @param string $a_message
  * @param string $a_prefix
  * @return ZLog
  */
 public function log($a_message, $a_prefix = null)
 {
     if ($this->m_path === null) {
         $this->m_path = Zoombi::config('path.log');
     }
     $filename = 'log.txt';
     if ($a_prefix) {
         $filename = $a_prefix . '-' . $filename;
     }
     $filepath = Zoombi::getApplication()->fromApplicationBaseDir($filename);
     $message = (string) $a_message;
     $header = '';
     if (!file_exists($filepath)) {
         $head = array();
         $head[] = "# Software:\tZoombi PHP Framework";
         $head[] = "# File name:\t" . $filename;
         $head[] = "# Version:\t1.0";
         $head[] = "# File creation date:\t" . date("d.m.Y");
         $head[] = "# File creation time:\t" . date("H:i:s");
         $head[] = "#";
         $header = implode("\n", $head) . "\n";
     }
     $fp = @fopen($filepath, 'a');
     if (!$fp) {
         return false;
     }
     $msg = array();
     $msg[] = "[" . date("d.m.Y") . "]";
     $msg[] = "[" . date("H:i:s") . "]";
     $msg[] = "[" . $_SERVER['REMOTE_ADDR'] . "]";
     $msg[] = '- ' . $message;
     $message = implode(" ", $msg) . "\n";
     flock($fp, LOCK_EX);
     fwrite($fp, $header . $message);
     flock($fp, LOCK_UN);
     fclose($fp);
 }
Exemplo n.º 4
0
 public static final function route()
 {
     return Zoombi::getApplication()->getRouter()->getCurrent();
 }
Exemplo n.º 5
0
 public function __get($a_property)
 {
     switch ($a_property) {
         default:
             break;
         case 'application':
             return Zoombi::getApplication();
         case 'database':
             return Zoombi::getApplication()->getDatabase();
         case 'registry':
             return Zoombi::getApplication()->getRegistry();
         case 'language':
             return Zoombi::getApplication()->getLanguage();
         case 'router':
             return Zoombi::getApplication()->getRouter();
         case 'load':
             return ZLoader::getInstance();
         case 'name':
             return $this->getName();
     }
     return $this->getProperty($a_property);
 }
Exemplo n.º 6
0
 public function __call($a_name, $a_args)
 {
     if (Zoombi::getApplication()->isModeDebug()) {
         $this->triggerError('Bad model method: ' . $a_name);
     }
 }
Exemplo n.º 7
0
 function put($a_key, $a_data)
 {
     $f = new Zoombi_File();
     if (Zoombi_Folder::notexist($this->m_dir)) {
         if (!mkdir($this->m_dir)) {
             Zoombi::getApplication()->triggerError('Failed when create directory');
             return;
         }
     }
     $time = time();
     $key = (string) $a_key;
     $cache = $this->m_dir . $key . '.cache';
     $info = $this->m_dir . $key . '.info';
     if (file_put_contents($cache, $a_data) === false) {
         Zoombi::getApplication()->triggerError('Cache file "' . $cache . '", not written');
         return;
     }
     if (file_put_contents($info, $time) === false) {
         Zoombi::getApplication()->triggerError('Cache info file "' . $info . '", not written');
         return;
     }
 }
Exemplo n.º 8
0
 public final function &factory($a_name)
 {
     $n = 'Zoombi_' . ucfirst($a_name);
     $c = Zoombi::null();
     try {
         $c = new $n();
     } catch (Exception $e) {
         Zoombi::getApplication()->triggerError($e);
     }
     return $c;
 }
Exemplo n.º 9
0
 private function &_route($a_path)
 {
     if (substr($a_path, 0, 1) == Zoombi::SS) {
         $rewrite = Zoombi::getApplication()->getName() . Zoombi::SS . substr($a_path, 1);
         $a_path = $rewrite;
     }
     $rewrite = $this->getRouter()->rewrite($a_path);
     if (empty($rewrite)) {
         $rewrite = implode(Zoombi::SS, array(Zoombi_Module::DEFAULT_MODULE_NAME, Zoombi_Module::DEFAULT_CONTROLLER_NAME, Zoombi_Module::DEFAULT_ACTION_NAME));
     }
     $path = new Zoombi_Route($rewrite);
     $epath = new Zoombi_RoutePath();
     $epath->parents[] = $this;
     if ($path->getSegment(0) == $this->getName() and $this->getLoader()->hasController($path->getSegment(1))) {
         $path->pop_start();
     }
     $m = $this;
     do {
         $s = $path->getSegment(0);
         if ($m->hasModule($s)) {
             $m = $m->getLoader()->module($s);
             $epath->parents[] = $m;
             $path->pop_start();
         } else {
             break;
         }
     } while ($m);
     $mod = $epath->module;
     if (!$mod) {
         throw new Zoombi_Exception('Application router can\'t find module start', Zoombi_Exception_Controller::EXC_LOAD);
     }
     $sc = $path->getSegment(0);
     $path->pop_start();
     if (empty($sc)) {
         $sc = $this->getConfig()->getValue('controller.default_name', 'iii');
     }
     if (!$mod->hasController($sc)) {
         throw new Zoombi_Exception('Application router can\'t find controller "' . $sc . '" in module ' . $mod->getName() . '"', Zoombi_Exception_Controller::EXC_LOAD);
     }
     $ctl = $mod->getLoader()->controller($sc);
     $epath->controller = $ctl;
     $sa = $path->getSegment(0);
     $path->pop_start();
     if (empty($sa)) {
         $sa = Zoombi_Module::DEFAULT_ACTION_NAME;
     }
     if (!$ctl->hasAction($sa)) {
         throw new Zoombi_Exception('Application router can\'t find action "' . $sa . '" in controller "' . $sc . '" of module "' . $mod->getName() . '"', Zoombi_Exception_Controller::EXC_ACTION);
     }
     $action = $mod->getConfig()->getValue('controller.action_prefix', Zoombi_Module::DEFAULT_CONTROLLER_METHOD_PREFIX) . $sa;
     if (substr($action, 0, 1) == '_') {
         throw new Zoombi_Exception('External routes to private action requies is disallowed', Zoombi_Exception_Controller::EXC_LOAD);
     }
     $epath->action = $sa;
     $_r = implode(Zoombi::SS, array_merge($epath->toArray(), $path->getSegments())) . $path->queryString();
     return $_r;
 }
Exemplo n.º 10
0
 /**
  * Display current view
  * @param bool $a_return
  * @return mixed
  */
 public function display($a_return = false)
 {
     if (!file_exists($this->m_view) or !is_file($this->m_view)) {
         $this->m_view = Zoombi::getApplication()->getLoader()->view($this->m_view);
     }
     return $this->renderFile($this->m_view, null, $a_return);
 }
Exemplo n.º 11
0
 /**
  * Boot framework
  * @param string $a_application
  * @return bool
  */
 public static final function boot($a_application)
 {
     $i = Zoombi::getInstance();
     $path = realpath((string) $a_application);
     if (file_exists($path) == false) {
         throw new Exception("Application path not exist: '{$path}'");
         return false;
     }
     if (is_dir($path) == false) {
         throw new Exception("Application directory not exist: '{$path}'");
         return false;
     }
     if (is_readable($path) == false) {
         throw new Exception("Application directory not accessable: '{$path}'");
         return false;
     }
     $i->m_application_base = $path;
     require_once ZOOMBI_BASE_PATH . self::DS . 'Class' . self::DS . 'registry.php';
     require_once ZOOMBI_BASE_PATH . self::DS . 'Base' . self::DS . 'config.php';
     require_once ZOOMBI_BASE_PATH . self::DS . 'Class' . self::DS . 'route.php';
     require_once ZOOMBI_BASE_PATH . self::DS . 'Base' . self::DS . 'router.php';
     require_once ZOOMBI_BASE_PATH . self::DS . 'Base' . self::DS . 'controller.php';
     require_once ZOOMBI_BASE_PATH . self::DS . 'Controllers' . self::DS . 'dummycontroller.php';
     require_once ZOOMBI_BASE_PATH . self::DS . 'Base' . self::DS . 'action.php';
     require_once ZOOMBI_BASE_PATH . self::DS . 'Base' . self::DS . 'model.php';
     require_once ZOOMBI_BASE_PATH . self::DS . 'Base' . self::DS . 'view.php';
     require_once ZOOMBI_BASE_PATH . self::DS . 'Error' . self::DS . 'profiler.php';
     require_once ZOOMBI_BASE_PATH . self::DS . 'Net' . self::DS . 'headers.php';
     require_once ZOOMBI_BASE_PATH . self::DS . 'Event' . self::DS . 'dispatcher.php';
     require_once ZOOMBI_BASE_PATH . self::DS . 'Base' . self::DS . 'plugin.php';
     require_once ZOOMBI_BASE_PATH . self::DS . 'Base' . self::DS . 'pluginmanager.php';
     require_once ZOOMBI_BASE_PATH . self::DS . 'Base' . self::DS . 'acl.php';
     require_once ZOOMBI_BASE_PATH . self::DS . 'Base' . self::DS . 'module.php';
     require_once ZOOMBI_BASE_PATH . self::DS . 'Base' . self::DS . 'application.php';
     spl_autoload_register(array(ZLoader::getInstance(), 'autoload'));
     if (self::ack(Zoombi::getApplication()->getConfig()->get(ZModule::CONFIG_KEY_AUTO_EXECUTE, false))) {
         self::getApplication()->execute();
     }
     return true;
 }
Exemplo n.º 12
0
 public static final function _loadFile($a_name, $a_section, $a_title = 'ZLoader')
 {
     $file_base = null;
     $file_name = (string) $a_name;
     $section = ucfirst(trim((string) $a_section));
     $exp = explode(self::SEPARATOR, $file_name);
     if (count($exp) > 1) {
         $file_name = array_pop($exp);
         $file_base = implode(Zoombi::DS, $exp);
     }
     $file_file = Zoombi::config($a_section . '.file_prefix') . $file_name . Zoombi::config($a_section . '.file_suffix', $section) . '.' . Zoombi::config($a_section . '.file_extension', 'php');
     $file_dir = Zoombi::getApplication()->fromApplicationBaseDir(Zoombi::config('path.' . $a_section, $section));
     if ($file_base) {
         $file_dir .= Zoombi::DS . $file_base;
     }
     $file_path = $file_dir . Zoombi::DS . $file_file;
     if (!file_exists($file_path)) {
         throw new Exception("{$a_title}: file '{$file_path}' is not exist", ZLoader::EXC_NO_FILE);
     }
     if (!is_readable($file_path)) {
         throw new Exception("{$a_title}: file '{$file_path}' is not readable", ZLoader::EXC_NO_READ);
     }
     return $file_path;
 }
Exemplo n.º 13
0
 /**
  * Load helper file
  * @param string $a_helper
  * @return string
  */
 public static final function helper($a_helper)
 {
     $v = null;
     try {
         $v = ZLoader::helper($a_helper);
     } catch (ZHelperException $e) {
         if (Zoombi::getApplication()->isMode(ZApplication::MODE_DEBUG)) {
             throw $e;
         }
     } catch (Exception $e) {
         if (Zoombi::getApplication()->isMode(ZApplication::MODE_DEBUG)) {
             throw $e;
         }
     }
     return $v;
 }
Exemplo n.º 14
0
 /**
  * Add ZModel instance
  * @param string|array $a_model
  * @return ZController
  */
 function &addModel($a_model)
 {
     switch (gettype($a_model)) {
         case 'string':
             if ($this->hasModel($a_model)) {
                 break;
             }
             $m = null;
             if (substr($a_model, 0, 1) == Zoombi::SS) {
                 $a_model = substr($a_model, 1);
                 $m = Zoombi::getApplication()->getLoader()->model($a_model);
             } else {
                 $m = $this->getModule()->getLoader()->model($a_model);
             }
             if ($m && $m instanceof ZModel) {
                 $this->setModel($m->getName(), $m);
             }
             break;
         case 'array':
             foreach ($a_model as $model) {
                 $this->addModel($model);
             }
             break;
     }
     return $this;
 }
Exemplo n.º 15
0
 /**
  * Route path
  * @param string $a_path
  * @return ZModule
  */
 public final function &route($a_path, $a_args = array())
 {
     Zoombi::getApplication()->m_route_deep++;
     switch (gettype($a_path)) {
         case 'string':
             if (substr($a_path, 0, 1) == Zoombi::SS) {
                 return $this->_reRoute(Zoombi::getApplication(), substr($a_path, 1), $a_args);
             }
             break;
         case 'object':
             if (!$a_path instanceof ZRoute) {
                 return $this;
             }
             break;
         default:
             return $this;
             break;
     }
     $p = new ZRoute($a_path);
     $m = $p->getModule();
     if (empty($m)) {
         $m = $this->getConfig()->getValue('module.default_name', self::DEFAULT_MODULE_NAME);
     }
     $this->emit(new ZEvent($this, 'preModule', $m));
     if ($this->getLoader()->hasModule($m)) {
         $mod = $this->getLoader()->module($m);
         if (!$mod) {
             throw new ZModuleException('Bad module');
         }
         $this->emit(new ZEvent($this, 'postModule', $mod));
         return $this->_reRoute($mod, $p->pop_start(), $a_args);
     }
     $this->emit(new ZEvent($this, 'postModule', $this));
     $p->push_start($this->getName());
     $route = $p;
     $c = $route->getController();
     $a = $route->getAction();
     if (empty($c)) {
         $route->setController($this->getConfig()->getValue('controller.default_name', self::DEFAULT_CONTROLLER_NAME));
     }
     if (empty($a)) {
         $route->setAction($this->getConfig()->getValue('controller.default_action', self::DEFAULT_ACTION_NAME));
     }
     $c = $route->getController();
     $a = $route->getAction();
     $this->emit(new ZEvent($this, 'preController', $c));
     $ctl = null;
     $ctl = $this->getLoader()->controller($c);
     if (!$ctl) {
         throw new ZModuleException('Module "' . $this->getName() . '" can\'t find controller "' . $c . '".');
     }
     $this->emit(new ZEvent($this, 'postController', $c, $ctl));
     if (!$ctl->hasAction($a)) {
         throw new ZModuleException('Module "' . $this->getName() . '" can\'t find controller "' . $c . '" action "' . $a . '".');
     }
     $this->emit(new ZEvent($this, 'preAction', $a));
     $this->setRoute($route)->setArgs($a_args);
     $this->m_return = $ctl->requestAction($a, $this->getRoute()->getParamsArray(), $this->m_output);
     return $this->emit(new ZEvent($this, 'postAction', $a));
 }
Exemplo n.º 16
0
 /**
  * Boot framework
  * @param string $a_application
  * @return bool
  */
 public static final function boot($a_application)
 {
     if (!is_string($a_application)) {
         throw new Exception("Boot method apply only string as first argument");
     }
     $i = Zoombi::getInstance();
     $path = realpath((string) $a_application);
     if (file_exists($path) == false) {
         throw new Exception("Application path not exist: '{$path}'");
     }
     if (is_dir($path) == false) {
         throw new Exception("Application directory not exist: '{$path}'");
     }
     if (is_readable($path) == false) {
         throw new Exception("Application directory not accessable: '{$path}'");
     }
     $i->m_application_base = $path;
     if (self::ack(Zoombi::getApplication()->getConfig()->get(Zoombi_Module::CONFIG_KEY_AUTO_EXECUTE, false))) {
         self::getApplication()->execute();
     }
     return true;
 }
Exemplo n.º 17
0
 /**
  * Load model
  * @param string|Zoombi_Model $a_model
  * @return Zoombi_Model 
  */
 function loadModel($a_model)
 {
     if ($a_model instanceof Zoombi_Model) {
         return $a_model;
     }
     if (!is_string($a_model)) {
         $this->triggerError("Controller '{$this->getName()}':  has wrong model type", Zoombi_Exception_Controller::EXC_MODEL);
         return;
     }
     $name = Zoombi_String::normalize($a_model);
     if (empty($name)) {
         $this->triggerError("Controller '{$this->getName()}':  has try load empty model", Zoombi_Exception_Controller::EXC_MODEL);
         return;
     }
     if (is_numeric($name)) {
         $this->triggerError("Controller '{$this->getName()}':  has try load model with numeric name", Zoombi_Exception_Controller::EXC_MODEL);
         return;
     }
     $m = null;
     try {
         if (substr($name, 0, 1) == Zoombi::SS) {
             $m = Zoombi::getApplication()->getLoader()->model(substr($name, 1), true);
         } else {
             $m = $this->getModule()->getLoader()->model($name, true);
         }
         if ($m instanceof Zoombi_Model) {
             $this->setModel($m->getName(), $m);
         } else {
             if ($this->getModule()->isMode(Zoombi_Module::MODE_DEBUG)) {
                 $this->triggerError('Model: ' . $name . 'not loaded');
             }
         }
     } catch (Zoombi_Exception_Model $e) {
         if ($this->getModule()->isMode(Zoombi_Module::MODE_DEBUG)) {
             $this->triggerError($e);
         }
     }
     return $m;
 }
Exemplo n.º 18
0
 function put($a_key, $a_data, $a_expire = self::EXPIRE_MINUTE)
 {
     if (Zoombi_Folder::notexist($this->m_dir)) {
         if (!mkdir($this->m_dir)) {
             Zoombi::getApplication()->triggerError('Failed when create directory');
             return;
         }
     }
     $key = (string) $a_key;
     $cache = $this->m_dir . $key . '.cache';
     $info = $this->m_dir . $key . '.info';
     $time = time();
     $age = intval($a_expire);
     if (file_put_contents($cache, $a_data) === false) {
         Zoombi::getApplication()->triggerError('Cache file "' . $cache . '", not written');
         return;
     }
     if (file_put_contents($info, $time . ':' . $age) === false) {
         Zoombi::getApplication()->triggerError('Cache info file "' . $info . '", not written');
         return;
     }
     return array($time, $age);
 }
Exemplo n.º 19
0
 /**
  * Forward controller/action call to another
  * @return ZController
  */
 protected function &forward($a_to)
 {
     $route = new ZRoute($a_to);
     //$route = clone $this->router->getCurrent();
     //$route->setController($rt->controller)->setAction($rt->action);
     $ret = null;
     try {
         $ctl = $this->load->controller($route->controller);
     } catch (ZControllerException $e) {
         if (Zoombi::getApplication()->isMode(ZApplication::MODE_DEBUG)) {
             trigger_error($e->getMessage(), Zoombi::EXC_ERROR);
         }
     }
     if (!$ctl) {
         return;
     }
     $old = clone $this->router->setForward($route)->getCurrent();
     $this->router->setCurrent($route);
     try {
         $ret = $ctl->setForwarder($this)->requestAction($route->getAction(), $route->getParams());
     } catch (ZControllerException $e) {
         if ($e->getCode() == ZControllerException::EXC_ACTION) {
             trigger_error($e->getMessage());
         } else {
             if ($this->application->isMode(ZApplication::MODE_DEBUG)) {
                 throw $e;
             }
         }
     }
     $this->router->setCurrent($old);
     return $ret;
 }
Exemplo n.º 20
0
 public function __get($a_property)
 {
     switch ($a_property) {
         default:
             break;
         case 'application':
             return Zoombi::getApplication();
         case 'database':
             return Zoombi::getApplication()->getDatabase();
         case 'router':
             return Zoombi::getApplication()->getRouter();
         case 'module':
             if ($this instanceof ZModule) {
                 return $this;
             } else {
                 return $this->getParent();
             }
         case 'registry':
             if ($this instanceof ZModule) {
                 return $this->getRegistry();
             } else {
                 return $this->getParent()->getRegistry();
             }
             break;
         case 'language':
             if ($this instanceof ZModule) {
                 return $this->getLanguage();
             } else {
                 return $this->getParent()->getLanguage();
             }
             break;
         case 'load':
             if ($this instanceof ZModule) {
                 return $this->getLoader();
             } else {
                 return $this->getParent()->getLoader();
             }
             break;
         case 'name':
             return $this->getName();
     }
     return $this->getProperty($a_property);
 }
Exemplo n.º 21
0
 /**
  * Render view
  * @param ZView $a_view
  * @param array $a_data
  * @param bool $a_return
  * @return midex
  */
 private function renderView(ZView &$a_view, $a_return = false)
 {
     $view = $a_view->getView();
     if (file_exists($view)) {
         return $a_view->display($a_return);
     }
     $oldload = $this->getModule()->getLoader();
     if (substr($view, 0, 1) == Zoombi::SS) {
         $view = substr($view, 1);
         $this->getModule()->setLoader(Zoombi::getApplication()->getLoader());
     }
     $a_view->setThis($this);
     if (!file_exists($view)) {
         try {
             $a_view->setView($this->getModule()->getLoader()->view($view));
         } catch (ZViewException $e) {
             $this->getModule()->setLoader($oldload);
             $this->triggerError($e);
             return;
         }
     }
     $o = $a_view->display($a_return);
     $this->getModule()->setLoader($oldload);
     return $o;
 }
Exemplo n.º 22
0
 /**
  * Route path
  * @param string $a_path
  * @return ZRoute
  */
 public function route($a_path)
 {
     $route = (string) $a_path;
     $rt = new ZRoute($route);
     if ($rt->module) {
         $cp = Zoombi::getApplication()->fromApplicationBaseDir(Zoombi::config('path.module', 'module') . Zoombi::DS . $rt->module);
         if (!file_exists($cp)) {
             $route = 'default' . Zoombi::US . $rt;
         }
     }
     $this->setRequest($route);
     $this->setRedirect(clone $this->getRequest());
     for ($i = 0; $i < 10; $i++) {
         $tmp = $this->_parse((string) $this->getRedirect());
         if ($tmp) {
             $this->setRedirect($tmp);
         }
     }
 }
Exemplo n.º 23
0
 /**
  * Route path
  * @param string $a_path
  * @return ZModule
  */
 public final function &route($a_path, $a_args = array())
 {
     Zoombi::getApplication()->m_route_deep++;
     switch (gettype($a_path)) {
         case 'string':
             if (substr($a_path, 0, 1) == Zoombi::SS) {
                 Zoombi::getApplication()->route(substr($a_path, 1), $a_args);
                 $this->m_output = Zoombi::getApplication()->outputGet();
                 $this->m_return = Zoombi::getApplication()->getReturn();
                 return $this;
             }
             break;
         case 'object':
             if (!$a_path instanceof ZRoute) {
                 return $this;
             }
             break;
         default:
             return $this;
     }
     $this->setArgs($a_args);
     try {
         $path = $this->routePath($this->getRouter()->rewrite($a_path), $route, true);
     } catch (Exception $e) {
         //return $this->triggerError('Invalid route path: ' . $a_path, 91);
         return $this->triggerError($e);
     }
     /*if( $path->isInvalid() )
     		return $this->triggerError('Invalid route path: ' . $path, 91);*/
     $this->setRoute($route);
     $path->controller->requestAction($path->action, $route->getParams());
     $this->m_output = $path->controller->getOutput();
     $this->m_return = $path->controller->getReturn();
     return $this;
 }
Exemplo n.º 24
0
 public function getDebug()
 {
     $d = new ZDummyController(Zoombi::getApplication(), '__dummy_ctl__');
     $o = $d->render(Zoombi::fromFrameworkDir('Views/view_route_debug.php'), array('route' => &$this), true);
     unset($d);
     return $o;
 }
Exemplo n.º 25
0
 /**
  * Route path
  * @param string $a_path
  * @return Zoombi_Module
  */
 public final function &route($a_path, $a_args = array())
 {
     if (substr($a_path, 0, 1) == Zoombi::SS) {
         return Zoombi::getApplication()->route(substr($a_path, 1));
     }
     if (substr($a_path, 0, 3) == '../' . Zoombi::SS) {
         $parent = $this->getModule();
         if (!$parent) {
             $parent = Zoombi::getApplication();
         }
         return $parent->route(substr($a_path, 3));
     }
     $rewrite = $this->getRouter()->rewrite($a_path);
     $path = new Zoombi_Route($rewrite);
     $epath = new Zoombi_RoutePath();
     if ($path->getSegment(0) == $this->getName()) {
         $seg = $path->getSegment(1);
         if ($this->getLoader()->hasController($seg) or $this->getLoader()->hasModule($path->getSegment($seg))) {
             $path->pop_start();
         }
     }
     $epath->parents[] = $this;
     $m = $this;
     do {
         $s = $path->getSegment(0);
         //$m = $m->getLoader()->module($s, false);
         if ($m->hasModule($s)) {
             $m = $m->getLoader()->module($s, false);
             $epath->parents[] = $m;
             $path->pop_start();
         } else {
             break;
         }
     } while ($m);
     $mod = $epath->module;
     if (!$mod) {
         $this->triggerError(new Zoombi_Exception('Application router can\'t find module "' . $path->getSegment(0) . '" -> ' . $rewrite, Zoombi_Exception_Controller::EXC_LOAD));
     }
     $sc = $path->getSegment(0);
     $path->pop_start();
     if (!$mod->hasController($sc)) {
         return $this->triggerError(new Zoombi_Exception('Application router can\'t find controller "' . $sc . '" in module "' . $mod->getName() . '" -> ' . $rewrite, Zoombi_Exception_Controller::EXC_LOAD));
     }
     $ctl = $mod->getLoader()->controller($sc, false);
     $epath->controller = $ctl;
     $sa = $path->getSegment(0);
     $path->pop_start();
     if (!$epath->controller->hasAction($sa)) {
         return $this->triggerError(new Zoombi_Exception('Application router can\'t find action "' . $sa . '" in controller "' . $sc . '" of module "' . $mod->getName() . '" -> ' . $rewrite, Zoombi_Exception_Controller::EXC_ACTION));
     }
     $epath->action = $sa;
     Zoombi_Request::getInstance()->setExecPath($epath);
     Zoombi_Request::getInstance()->setRoutePath($epath);
     $old_args = $this->getArgs();
     $old_route = $this->getRoute();
     $old_current = $this->getRouter()->getForward();
     $nr = new Zoombi_Route(implode(Zoombi::SS, array_merge($epath->toArray(), $path->getSegments())) . $path->queryString());
     $this->setArgs($a_args);
     $this->setRoute($nr);
     $this->getRouter()->setForward($nr);
     $epath->controller->requestAction($epath->action, $path->getSegments());
     foreach ($epath->parents as $mod) {
         if ($mod and $mod instanceof Zoombi_Module) {
             $mod->setReturn($epath->controller->getReturn());
             $mod->setOutput($epath->controller->getOutput());
         }
     }
     $this->setArgs($old_args);
     $this->setRoute($old_route);
     $this->getRouter()->setForward($old_current);
     return $this;
 }
Exemplo n.º 26
0
 /**
  * Set application instance
  * @param ZApplication $a_application
  */
 public static final function setApplication(ZApplication &$a_application)
 {
     $i = Zoombi::getInstance();
     $a_application->setName('CoreApplication');
     $a_application->setApplicationBaseDir($i->m_application_base);
     $a_application->setBaseDir($i->m_application_base);
     $i->m_application =& $a_application;
     $run = strtolower(strval(Zoombi::config('autorun')));
     switch ($run) {
         case '1':
         case 'ok':
         case 'on':
         case 'yes':
         case 'true':
             Zoombi::getApplication()->execute();
             break;
     }
     return true;
 }