Exemple #1
0
 /**
  * @param $path
  *
  * @return array
  */
 public function getRoute($path)
 {
     /* Get route information for the url */
     $route = $this->router->routeUrl($path, $this->request->getMethod());
     if (empty($route['page']) || !file_exists($route['page']['path'] . $route['page']['value'])) {
         $route = $this->pageNotFound($path);
     }
     if (isset($route['model']['file'])) {
         global $autoloader;
         $autoloader->addClassMap(["Leap\\Plugins\\" . ucfirst($route['model']['plugin']) . "\\Models\\" . $route['model']['class'] => $route['model']['file']]);
     }
     if (isset($route['controller']['file'])) {
         global $autoloader;
         $autoloader->addClassMap(["Leap\\Plugins\\" . ucfirst($route['controller']['plugin']) . "\\Controllers\\" . $route['controller']['class'] => $route['controller']['file']]);
     }
     /* If the controller class name does not contain the namespace yet, add it */
     if (strpos($route['controller']['class'], "\\") === false && isset($route['controller']['plugin'])) {
         $namespace = getNamespace($route['controller']['plugin'], "controller");
         $route['controller']['class'] = $namespace . $route['controller']['class'];
     }
     /* If the model name does not contain the namespace yet, add it */
     if (strpos($route['model']['class'], "\\") === false && isset($route['model']['plugin'])) {
         $namespace = getNamespace($route['model']['plugin'], "model");
         $route['model']['class'] = $namespace . $route['model']['class'];
     }
     return $route;
 }
Exemple #2
0
 private static function setController($controller = null, $method = null, $parameter = null)
 {
     if (is_null($controller)) {
         return;
     }
     $file = __APP_PATH . '/' . Config::get('app')->controller_folder . '/' . $controller . '.php';
     if (!file_exists($file)) {
         return false;
     }
     $namespace = getNamespace($file);
     $class = explode('/', $controller);
     $class = $namespace . '\\' . $class[count($class) - 1];
     $cl = new $class();
     if (is_null($method)) {
         if (!method_exists($cl, 'index')) {
             return false;
         }
         return $cl->index();
     }
     if (!method_exists($cl, $method)) {
         if (method_exists($cl, 'index')) {
             return $cl->index();
         }
         return false;
     }
     if (count($parameter) > 0) {
         return call_user_func_array([$cl, $method], $parameter);
     }
     return $cl->{$method}();
 }