コード例 #1
0
ファイル: App.php プロジェクト: cyantree/grout
 /** @param $task Task
  * @param $route Route
  */
 public function redirectTaskToRoute($task, $route)
 {
     $task->setRoute($route);
     if (strpos($task->route->page, '@')) {
         $type = explode('@', $task->route->page, 2);
         $class = $type[0];
         $action = $type[1];
     } else {
         $class = $task->route->page;
         $action = 'parseTask';
     }
     $classData = AppTools::decodeUri($class, $this, $task->route->module, $task->route->plugin);
     if ($classData[1]) {
         $class = NamespaceTools::getNamespaceOfInstance($classData[1]) . '\\' . $classData[2];
     } elseif ($classData[0]) {
         $class = NamespaceTools::getNamespaceOfInstance($classData[0]) . '\\' . $classData[2];
     } else {
         trigger_error('No page class found for "' . $task->request->url . '" with "' . $task->route->page . '"');
         $class = null;
     }
     $task->setPage(new $class());
     if (!$task->page) {
         trigger_error('No page was set', E_USER_ERROR);
     }
     $task->page->task = $task;
     $task->page->beforeParsing();
     $task->page->{$action}();
     $task->page->afterParsing();
 }
コード例 #2
0
ファイル: Module.php プロジェクト: cyantree/grout
 public function importPlugin($type, $config = null, $id = null)
 {
     if ($id === null) {
         $id = str_replace('\\', '', $type);
     }
     if ($this->getPluginById($id)) {
         return null;
     }
     $pos = strrpos($type, '\\');
     if ($pos === false) {
         $class = $type;
     } else {
         $class = substr($type, strrpos($type, '\\') + 1);
     }
     if ($config === null || is_array($config)) {
         $config = new ArrayFilter($config);
     }
     //        $directory = str_replace('\\', '/', $type);
     //        $path = $this->app->path . 'plugins/' . $directory . '/';
     $this->app->importPluginNamespace($type);
     $class = 'Grout\\' . $type . '\\' . $class;
     $reflection = new \ReflectionClass($class);
     $path = dirname($reflection->getFileName()) . '/';
     /** @var $p Plugin */
     $p = new $class();
     $p->type = $type;
     $p->config = $config;
     $p->path = $path;
     $p->namespace = NamespaceTools::getNamespaceOfInstance($p) . '\\';
     $p->module = $this;
     $p->app = $this->app;
     $p->id = $id;
     $this->pluginIds[$p->id] = $p;
     $this->plugins[] = $p;
     if (!isset($this->pluginTypes[$type])) {
         $this->pluginTypes[$type] = array($p);
     } else {
         $this->pluginTypes[$type][] = $p;
     }
     $this->app->plugins[] = $p;
     $this->app->pluginIds[$p->id] = $p;
     if (!isset($this->app->pluginTypes[$type])) {
         $this->app->pluginTypes[$type] = array($p);
     } else {
         $this->app->pluginTypes[$type][] = $p;
     }
     $p->init();
     return $p;
 }