Example #1
0
 /**
  * Make route from object
  * @param Zoombi_Route $a_route
  * @return Zoombi_Route
  */
 public function &fromObject($a_route)
 {
     $this->clear();
     if ($a_route instanceof Zoombi_Route) {
         $this->m_segments = $a_route->getSegments();
         $this->m_query->setData($a_route->getQuery());
     }
     return $this;
 }
Example #2
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;
 }
 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;
 }