Пример #1
0
 public static function dispatchBundle(Container $route)
 {
     $bundle = $route->getBundle();
     $controller = $route->getController();
     $action = $route->getAction();
     $path = realpath(APPLICATION_PATH . '/../');
     $bundle = ucfirst(Inflector::lower($bundle));
     $viewsDir = $path . DS . 'bundles' . DS . $bundle . DS . 'views';
     $controllersDir = $path . DS . 'bundles' . DS . $bundle . DS . 'controllers';
     $tpl = $viewsDir . DS . Inflector::lower($controller) . ucfirst(Inflector::lower($action)) . '.phtml';
     $controllerFile = $controllersDir . DS . Inflector::lower($controller) . '.php';
     $file = $path . DS . 'bundles' . DS . $bundle . DS . $bundle . '.php';
     if (File::exists($file)) {
         $getNamespaceAndClassNameFromCode = getNamespaceAndClassNameFromCode(fgc($file));
         list($namespace, $class) = $getNamespaceAndClassNameFromCode;
         if (File::exists($controllerFile)) {
             if (File::exists($tpl)) {
                 $view = new View($tpl);
                 container()->setView($view);
             }
             require_once $controllerFile;
             $controllerClass = $namespace . '\\' . Inflector::lower($controller) . 'Controller';
             $controller = new $controllerClass();
             if (File::exists($tpl)) {
                 $controller->view = $view;
             }
             container()->setController($controller);
             $actions = get_class_methods($controllerClass);
             container()->setAction($action);
             if (strstr($action, '-')) {
                 $words = explode('-', $action);
                 $newAction = '';
                 for ($i = 0; $i < count($words); $i++) {
                     $word = trim($words[$i]);
                     if ($i > 0) {
                         $word = ucfirst($word);
                     }
                     $newAction .= $word;
                 }
                 $action = $newAction;
             }
             $actionName = $action . 'Action';
             if (Arrays::in('init', $actions)) {
                 $controller->init();
             }
             if (Arrays::in('preDispatch', $actions)) {
                 $controller->preDispatch();
             }
             if (!Arrays::in($actionName, $actions)) {
                 throw new Exception("The action '{$actionName}' does not exist.");
             }
             $controller->{$actionName}();
             if (File::exists($tpl)) {
                 $controller->view->render();
             }
             /* stats */
             if (File::exists($tpl) && null === container()->getNoShowStats() && null === $route->getNoShowStats()) {
                 echo View::showStats();
             }
             if (Arrays::in('postDispatch', $actions)) {
                 $controller->preDispatch();
             }
             if (Arrays::in('exit', $actions)) {
                 $controller->exit();
             }
         } else {
             context()->is404();
         }
     } else {
         context()->is404();
     }
 }
Пример #2
0
 /**
  * Load any plugins
  */
 private function loadPlugins()
 {
     $dir = realpath(APPLICATION_PATH . DS . '..' . DS . 'public' . DS . 'content' . DS . SITE_NAME . DS . 'plugins');
     $this->plugins = array();
     $plugins = $this->getFiles($dir, '.php');
     if (!empty($plugins)) {
         foreach ($plugins as $plugin) {
             $getNamespaceAndClassNameFromCode = getNamespaceAndClassNameFromCode(fgc($plugin));
             list($namespace, $class) = $getNamespaceAndClassNameFromCode;
             require_once $plugin;
             $actions = get_class_methods($namespace . '\\' . $class);
             $nsClass = '\\' . $namespace . '\\' . $class;
             $instance = new $nsClass();
             if (Arrays::in('init', $actions)) {
                 $instance::init();
             }
             array_push($this->plugins, $instance);
             $this->plugins[] = $obj;
         }
     }
 }
Пример #3
0
 function bundle($bundle)
 {
     $bundle = ucfirst(Inflector::lower($bundle));
     $path = realpath(APPLICATION_PATH . '/../');
     $file = $path . DS . 'bundles' . DS . $bundle . DS . $bundle . '.php';
     if (File::exists($file)) {
         $getNamespaceAndClassNameFromCode = getNamespaceAndClassNameFromCode(fgc($file));
         if (!is_null($getNamespaceAndClassNameFromCode) && Arrays::is($getNamespaceAndClassNameFromCode)) {
             list($namespace, $class) = $getNamespaceAndClassNameFromCode;
             Autoloader::registerNamespace($namespace, $path . DS . 'bundles' . DS . $bundle);
             require_once $file;
             $actions = get_class_methods($namespace . '\\' . $class);
             if (Arrays::in('init', $actions)) {
                 $nsClass = $namespace . '\\' . $class;
                 $nsClass::init();
             }
             return true;
         } else {
             throw new Exception("No namespace found in '{$file}'.");
         }
     } else {
         throw new Exception("Bundle File '{$file}' does not exist.");
     }
 }