Example #1
0
 /**
  *
  *
  */
 public function __construct()
 {
     // set up references required in controllers
     $application = Application::getInstance();
     $this->request = Request::createFromGlobals();
     $this->currentDocument = basename($this->request->getScriptName());
     if ($path = trim($this->request->getPathInfo(), '/')) {
         $this->pathSegments = explode('/', $path);
     }
     $this->config = $application->getConfig();
     $this->route = $application->getCurrentRoute();
     if (is_null($this->route)) {
         $this->route = Router::getRouteFromPathInfo();
     }
     // skip script name
     if ($application->hasNiceUris() && $this->currentDocument != 'index.php') {
         array_shift($this->pathSegments);
     }
     // skip locale if one found
     if (count($this->pathSegments) && Application::getInstance()->hasLocale($this->pathSegments[0])) {
         array_shift($this->pathSegments);
     }
     $this->prepareForXhr();
 }
Example #2
0
 /**
  * sets active menu entries, allows addition of dynamic entries and
  * prints level $level of a menu, identified by $id
  *
  * $decorator identifies a decorator class - MenuDecorator{$decorator}
  * $renderArgs are additional parameters passed to Menu::render()
  *
  * @param string $id
  * @param integer $level (if NULL, the full menu tree is printed)
  * @param boolean $forceActiveMenu
  * @param string $decorator
  * @param mixed $renderArgs
  *
  * @return string html
  */
 public function __construct($id = NULL, $level = FALSE, $forceActiveMenu = NULL, $decorator = NULL, $renderArgs = NULL)
 {
     $application = Application::getInstance();
     $this->config = $application->getConfig();
     $this->useNiceUris = $application->hasNiceUris();
     if (empty($id) && !is_null($this->config->menus)) {
         throw new MenuGeneratorException();
     }
     $this->request = Request::createFromGlobals();
     $this->route = $application->getCurrentRoute();
     if (is_null($this->route)) {
         $this->route = Router::getRouteFromPathInfo();
     }
     if (empty($id)) {
         $id = array_shift(array_keys($this->config->menus));
     }
     if (!isset($this->config->menus[$id]) || !count($this->config->menus[$id]->getEntries()) && $this->config->menus[$id]->getType() == 'static') {
         throw new MenuGeneratorException("Menu '" . $id . "' not found or empty.");
     }
     $this->menu = $this->config->menus[$id];
     $this->id = $id;
     $this->level = $level;
     $this->decorator = $decorator;
     $this->renderArgs = is_null($renderArgs) ? [] : $renderArgs;
     // if $forceActiveMenu was initialized before, it will not be overwritten
     if (is_null(self::$forceActiveMenu)) {
         self::$forceActiveMenu = (bool) $forceActiveMenu;
     }
 }