Ejemplo n.º 1
0
 public function getAppTool($tool)
 {
     $t = $this->_tools->get($tool);
     if ($t) {
         return $t;
     }
     if (method_exists($this, $tool)) {
         return $this->{$tool}();
     }
     $event = $this->events->trigger($tool);
     if ($event->data) {
         $this->_tools->set($tool, $event->data);
         return $event->data;
     }
     return null;
 }
Ejemplo n.º 2
0
 /**
  * @param $type
  * @param string $urlPrefix
  * @param array $config
  * @param string $id
  * @param int $priority
  * @return Module|null
  */
 public function importModule($type, $urlPrefix = null, $config = null, $id = null, $priority = 0)
 {
     if ($id === null) {
         $id = str_replace('\\', '', $type);
         if ($this->getModuleById($id)) {
             $id .= '_' . count($this->modules);
         }
     }
     if ($this->getModuleById($id)) {
         return null;
     }
     $pos = strrpos($type, '\\');
     if ($pos === false) {
         $class = $type;
     } else {
         $class = substr($type, strrpos($type, '\\') + 1);
     }
     //        $directory = str_replace('\\', '/', $type);
     //        $path = $this->path . 'modules/' . $directory . '/';
     if ($config === null || is_array($config)) {
         $config = new ArrayFilter($config);
     }
     $config->set('_priority', $priority);
     // Add module path to auto loading
     $this->importModuleNamespace($type);
     /** @var $m Module */
     $c = 'Grout\\' . $type . '\\' . $class;
     $reflection = new \ReflectionClass($c);
     $path = dirname($reflection->getFileName()) . '/';
     $m = new $c();
     $m->type = $type;
     $m->events = new Events();
     $m->app = $this;
     $m->config =& $config;
     $m->urlPrefix = $urlPrefix !== null ? $urlPrefix : '';
     $m->path = $path;
     $m->namespace = NamespaceTools::getNamespaceOfInstance($m) . '\\';
     $m->id = $id;
     $this->modules[] = $m;
     if (!isset($this->moduleTypes[$type])) {
         $this->moduleTypes[$type] = array($m);
     } else {
         $this->moduleTypes[$type][] = $m;
     }
     $this->moduleIds[$m->id] = $m;
     if ($this->_initiated) {
         $m->init();
         /* TODO: War aus nicht mehr bekanntem Grund auskommentiert, weil irgendetwas doppelt aufgerufen wurde */
         if ($this->currentTask) {
             $m->initTask($this->currentTask);
         }
     }
     return $m;
 }
Ejemplo n.º 3
0
 /** @return Route */
 public function addErrorRoute($code, $page, $pageData = null)
 {
     $f = new ArrayFilter($pageData);
     if (!$f->has('responseCode')) {
         $f->set('responseCode', $code);
     }
     $url = null;
     $activated = false;
     $priority = 0;
     if ($code == ResponseCode::CODE_404) {
         $url = '%%url,.*%%';
         $activated = true;
         $priority = -1;
     }
     $codeDigit = substr($code, 0, 3);
     return $this->addNamedRoute('GroutError' . $codeDigit, $url, $page, $f->getData(), $priority, $activated);
 }