Exemplo n.º 1
0
 /**
  * todo: psr0 need fix
  *
  * @param string $controller 'controller_name' or 'controller_name:action_name'
  * @param array $input
  * @param string $action
  * @return \Floxim\Floxim\System\Controller initialized controller
  */
 public static function controller($controller, $input = null, $action = null)
 {
     /**
      * vendor.module.component - front component controller
      * vendor.module.component:action - front component controller with action
      * todo: vendor.module.component.admin - component admin controller
      * todo: vendor.module.admin - module admin
      * todo: vendor.module.widget - widget controller
      * layout - layout controller
      * admin.controller - admin controller site
      */
     $c_parts = explode(":", $controller);
     if (count($c_parts) == 2) {
         $controller = $c_parts[0];
         $action = $c_parts[1];
     }
     if ($controller == 'layout') {
         return new Controller\Layout($input, $action);
     }
     /**
      * Vendor component
      */
     $c_class = fx::getComponentNamespace($controller) . '\\Controller';
     if (class_exists($c_class)) {
         return new $c_class($input, $action);
     }
     $c_parts = explode(".", $controller);
     /**
      * Admin controllers
      */
     if ($c_parts[0] == 'admin') {
         $c_name = isset($c_parts[1]) ? $c_parts[1] : 'Admin';
         $c_class = 'Admin\\Controller\\' . ucfirst($c_name);
         if (class_exists($c_class)) {
             $controller_instance = new $c_class($input, $action);
             return $controller_instance;
         }
         die("Failed loading controller class " . $c_class);
     }
     die("Failed loading class controller " . $controller);
 }