Example #1
1
 public static function Run(Request $request)
 {
     $controller = $request->getController() . 'Controller';
     $route = ROOT . '../' . 'app' . DS . 'Controllers' . DS . $controller . '.php';
     $method = $request->getMethod();
     if ($method == 'index.php') {
         $method = 'Index';
     }
     $parameters = $request->getParameters();
     if (is_readable($route)) {
         require_once $route;
         $function = "App\\Controllers\\" . $controller;
         $controller = new $function();
         if (!isset($parameters)) {
             $data = call_user_func(array($controller, $method));
         } else {
             $data = call_user_func_array(array($controller, $method), $parameters);
         }
     }
 }
 public function start()
 {
     \org\equinox\utils\debug\DebugBarFactory::init();
     //$this->request->analyseAskedRequest();
     $controller = $this->getController($this->request->getModule(), $this->request->getController());
     try {
         try {
             $action = $controller->doActionRequested($this->request->action, 'main');
         } catch (\org\equinox\exception\AccessDeniedException $e) {
             if ($controller->getReturnType() == \org\equinox\controller\Controller::RETURN_TYPE_HTML) {
                 $controller = $this->getController($this->request->accessDeniedModule, $this->request->accessDeniedController);
                 $controller->doActionRequested($this->request->accessDeniedAction, 'main');
             } else {
                 echo $this->getJsonException($e);
             }
         }
     } catch (\Exception $e) {
         if ($controller->getReturnType() == \org\equinox\controller\Controller::RETURN_TYPE_HTML) {
             $this->request->exception = $e;
             $controller = $this->getController($this->request->errorModule, $this->request->errorController);
             $controller->doActionRequested($this->request->errorAction, 'main');
         } else {
             echo $this->getJsonException($e);
         }
     }
     if ($controller->getReturnType() == \org\equinox\controller\Controller::RETURN_TYPE_HTML) {
         $layout = $this->getController($this->request->layoutModule, $this->request->layoutController);
         echo $layout->genereLayout();
     } else {
         echo json_encode($action->getAllAssigns());
     }
     return true;
 }
Example #3
0
 public static function run(Request $request)
 {
     /** get the Controller, Method, Arguments/Parameters and the URL of the Controller */
     $controller = $request->getController() . "Controller";
     $method = $request->getMethod();
     $args = $request->getArgs();
     $controllerUrl = ROOT . "controllers" . DS . $controller . ".php";
     if ($method == "index.php") {
         $method = "index";
     }
     /** if the Controller exists, call the Controller */
     if (is_readable($controllerUrl)) {
         require_once $controllerUrl;
         $fullController = "Controllers\\" . $controller;
         $controller = new $fullController();
         if (!isset($args)) {
             $data = call_user_func(array($controller, $method));
         } else {
             $data = call_user_func_array(array($controller, $method), $args);
         }
     }
     /** Render view */
     $controllerUrl = ROOT . "views" . DS . $request->getController() . DS . $request->getMethod() . ".php";
     if (is_readable($controllerUrl)) {
         require_once $controllerUrl;
     } else {
         print "No se encontró la ruta especificada.";
     }
 }
 public static function route(Request $request)
 {
     $controller = $request->getController() . 'Controller';
     $method = $request->getMethod();
     $args = $request->getArgs();
     //$controllerFile = SITE_PATH.'controllers/'.$controller.'.php';  //***Because autoload
     //if(is_readable($controllerFile)){ //***Because autoload
     //require_once $controllerFile; //***Because autoload
     $controller = new $controller();
     $method = is_callable(array($controller, $method)) ? $method : 'index';
     if (!empty($args)) {
         //call_user_func_array(array($controller,$method),$args);
         if (extension_loaded('newrelic')) {
             newrelic_name_transaction((string) $request->getController() . '/' . (string) $method);
         }
         call_user_func(array($controller, $method), $args);
     } else {
         if (extension_loaded('newrelic')) {
             newrelic_name_transaction((string) $request->getController() . '/' . (string) $method);
         }
         call_user_func(array($controller, $method), NULL);
     }
     return;
     //} //***Because autoload
     throw new Exception('404 - ' . $request->getController() . ' not found');
 }
Example #5
0
 public static function buildPath(Request $peticion)
 {
     $module = $peticion->getModule();
     $controller = $peticion->getController();
     $path = CONTROLLER_PATH . $module . DS . $controller . '.php';
     return $path;
 }
Example #6
0
 public static function run(Request $pedido)
 {
     $controller = ucfirst($pedido->getController());
     $caminho = ROOT . "controllers" . DS1 . $controller . DS1 . $controller . '.php';
     //        print $caminho;
     //        die;
     $metodo = $pedido->getMetodo();
     $parametro = $pedido->getParametros();
     if (is_readable($caminho)) {
         require $caminho;
         $controlador = ucfirst($controller);
         $namespace = "\\" . "controllers" . "\\" . $controlador;
         $controller = new $namespace();
         if (is_callable(array($controller, $metodo))) {
             $metodo = $pedido->getMetodo();
         } else {
             $metodo = "index";
         }
         if (isset($parametro)) {
             call_user_func_array(array($controller, $metodo), $parametro);
         } else {
             call_user_func(array($controller, $metodo));
         }
     } else {
         header("Location:" . URL . "error");
     }
 }
Example #7
0
 function __construct(Request $pedido)
 {
     //parent::__construct();
     $this->_controller = $pedido->getController();
     //        print $this->_controller; exit;
     $this->_js = array();
     $this->_css = array();
 }
Example #8
0
 public function __construct()
 {
     // initialisation du CORE
     parent::__construct();
     $class = self::$curent_class;
     // appel du controlleur
     echo $class::{Request::getController() . 'Controller'}();
 }
 function handlerRequest()
 {
     //require_once("C:\\xampp\\htdocs\\lesson3\\src\\core\\classes\\Request.php");
     //require_once("C:\\xampp\\htdocs\\lesson3\\src\\core\\classes\\Routing.php");
     var_dump("gtyftyftftf");
     $request = new Request();
     var_dump($request->getController());
     Routing::run($request);
 }
Example #10
0
 /**
  * Fonction qui recupere le bon controlleur et la fonction 
  * 
  * @param Request $request
  * @return type
  * @throws Exception
  */
 public static function route(Request $request)
 {
     $controller = $request->getController() . 'Controller';
     $method = $request->getMethod();
     $args = $request->getArgs();
     $controllerFile = SITE_PATH . 'controllers/' . $controller . '.php';
     if (is_readable($controllerFile)) {
         require_once $controllerFile;
         $controller = new $controller();
         $method = is_callable(array($controller, $method)) ? $method : 'index';
         if (!empty($args)) {
             call_user_func_array(array($controller, $method), $args);
         } else {
             call_user_func(array($controller, $method));
         }
         return;
     }
     throw new Exception('404 - ' . $request->getController() . ' not found');
 }
Example #11
0
 /**
  * Run the application 
  * @param type $appBasePath
  */
 public function run($appBasePath)
 {
     /**
      * Define application base path
      */
     defined('APP_BASE_PATH') or define('APP_BASE_PATH', $appBasePath);
     /**
      * get controller and action from from url
      */
     $controller = Request::getController();
     $action = Request::getAction();
     /**
      * prepare controller class and path according to convention
      */
     $controllerClass = $controller . 'Controller';
     $controllerPath = APP_BASE_PATH . '/controllers/' . $controllerClass . '.php';
     /**
      * check if requested controller file and class exists
      * @todo use error controller and action to display errors
      */
     if (file_exists($controllerPath)) {
         /**
          * Include requested controller
          */
         include_once $controllerPath;
         if (class_exists($controllerClass)) {
             $Controller = new $controllerClass();
         } else {
             $msg = $controllerClass . ' class not found!';
             exit($msg);
         }
     } else {
         $msg = $controllerPath . ' not found!';
         exit($msg);
     }
     /**
      * prepare method
      */
     $methodName = $action . 'Action';
     if (!method_exists($Controller, $methodName)) {
         $msg = " Method {$methodName} not found on {$controllerClass} Class ";
         exit($msg);
     }
     /**
      * execute appropriate contoller's action method
      */
     try {
         $Controller->{$methodName}();
     } catch (Exception $exc) {
         Debug::r($exc->getMessage(), 'application-exception.txt');
     }
 }
Example #12
0
 public static function route(Request $request)
 {
     $controller = $request->getController() . 'Controller';
     $method = $request->getMethod();
     $args = $request->getArgs();
     $controllerFile = SITE_PATH . 'controllers/' . $controller . '.php';
     if (is_readable($controllerFile)) {
         require_once $controllerFile;
         $controller = new $controller();
         $method = is_callable(array($controller, $method)) ? $method : 'index';
         call_user_func(array($controller, $method));
     }
 }
Example #13
0
 public static function run()
 {
     $request = new Request();
     $controller = $request->getController();
     $controllerPath = Router::buildPath($request);
     $action = $request->getAction();
     if (is_readable($controllerPath)) {
         require_once $controllerPath;
     } else {
         throw new Exception('no encontrado');
     }
     $controllerInstance = new $controller();
     $controllerInstance->{$action}();
 }
Example #14
0
 public static function route(Request $request)
 {
     $controller = $request->getController() . 'Controller';
     $method = $request->getMethod();
     $args = $request->getArgs();
     $controllerFile = APP . 'controllers/' . $controller . '.php';
     $controller = new $controller();
     $method = is_callable(array($controller, $method)) ? $method : 'index';
     if (!empty($args)) {
         call_user_func_array(array($controller, $method), $args);
     } else {
         call_user_func(array($controller, $method));
     }
     return;
 }
Example #15
0
 /**
  * Overriding parent
  *
  * @param string $name
  * @return mixed
  */
 public function __get($name)
 {
     if ($name == 'session') {
         if ($this->_session === null) {
             $req = $this->request;
             Loader::load('Session', 'core');
             $ns = $req->getController();
             $subdir = str_replace('/', '_', $req->getControllerSubDirectory());
             if ($subdir != '') {
                 $ns = $subdir . '_' . $ns;
             }
             $this->_session = new Session($ns);
         }
         return $this->_session;
     }
     if ($name == 'post') {
         if (!array_key_exists($name, $this->_caches)) {
             $this->_caches[$name] = $this->request->getPost();
         }
         return $this->_caches[$name];
     }
     if ($name == 'query') {
         if (!array_key_exists($name, $this->_caches)) {
             $this->_caches[$name] = $this->request->getQuery();
         }
         return $this->_caches[$name];
     }
     if ($name == 'params') {
         if (!array_key_exists($name, $this->_caches)) {
             $this->_caches[$name] = $this->request->getParams();
         }
         return $this->_caches[$name];
     }
     if ($name == 'controller') {
         if (!array_key_exists($name, $this->_caches)) {
             $this->_caches[$name] = $this->request->getController();
         }
         return $this->_caches[$name];
     }
     if ($name == 'action') {
         if (!array_key_exists($name, $this->_caches)) {
             $this->_caches[$name] = $this->request->getAction();
         }
         return $this->_caches[$name];
     }
     return parent::__get($name);
 }
Example #16
0
 public function dispatch()
 {
     $request = new Request($_SERVER['QUERY_STRING']);
     $this->_module = $request->getModule();
     $this->_controller = $request->getController();
     $this->_action = $request->getAction();
     foreach ($this->pre_request as $pre_request) {
         $result = Module::run($pre_request);
         if ($result) {
             $request = $result;
             break;
         }
     }
     while ($request) {
         $request = Module::run($request);
     }
 }
Example #17
0
 private static function runController()
 {
     $isAjax = Request::isAjax();
     if ($isAjax) {
         Autoload::includePath('mvc' . SEPARATOR . 'controller' . SEPARATOR . 'ajax');
     } else {
         Autoload::includePath('mvc' . SEPARATOR . 'controller' . SEPARATOR . 'web');
     }
     Layout::loadContent();
     $controller = Request::getController();
     $controller .= '_controller';
     if (class_exists($controller)) {
         $app = new $controller();
     } else {
         Request::redirect('notfound');
     }
     $app = null;
 }
Example #18
0
 public static function run(Request $request)
 {
     $controller = $request->getController();
     $adressController = ROOT . 'App' . DS . 'Controllers' . DS . $controller . 'Controller.php';
     $method = $request->getMethod();
     $argument = $request->getArgument();
     if (is_readable($adressController)) {
         require_once $adressController;
         $ctrl = 'App\\Controllers\\' . $controller;
         if (isset($argument)) {
             call_user_func_array(array(new $ctrl(), $method), array($argument));
         } else {
             call_user_func(array(new $ctrl(), $method));
         }
     } else {
         echo 'Controlador Inaccesible: <strong>' . $adressController . '</strong><br>';
         exit;
     }
 }
Example #19
0
 /**
  * @param Request $request
  * @return string
  * @throws Exception
  * @throws NotFoundException
  */
 public function run($request)
 {
     $controller = $request->getController();
     $action = $request->getAction();
     if (empty($controller) || empty($action)) {
         throw new Exception("Invalid request.");
     }
     // Sanitize $controller_class before autoloading.
     $controller_class = ucfirst($controller) . 'Controller';
     if (!in_array($controller_class, $this->_allowed_controllers)) {
         throw new NotFoundException("Controller not defined.");
     }
     ob_start();
     $controller_obj = new $controller_class($request);
     if (method_exists($controller_obj, 'init')) {
         $controller_obj->init();
     }
     $controller_obj->do_action($action);
     $output = ob_get_clean();
     return $output;
 }
Example #20
0
 public static function run(Request $request)
 {
     $controller = $request->getController() . 'Controller';
     $routeController = ROOT . 'Controllers' . DS . $controller . '.php';
     $method = $request->getMethod();
     $args = $request->getArgs();
     if (is_readable($routeController)) {
         require_once $routeController;
         $controller = new $controller();
         if (!is_callable(array($controller, $method))) {
             $method = 'index';
         }
         if ($args != null) {
             call_user_func_array(array($controller, $method), $args);
         } else {
             call_user_func(array($controller, $method));
         }
     } else {
         throw new Exception('no encontrado xD');
     }
 }
Example #21
0
 /**
  * Metodo para ejecutar la aplicacion.
  * 
  * Permite iniciar la aplicacion, analiza el objeto Request.
  * Valida que el controlador y la accion solicitada se puedan cargar de lo contrario genera
  * un error que luego es enviado al usuario.
  * 
  * @param Request $request
  * @throws Exception
  */
 public static function Run(Request $request)
 {
     $controllerName = '\\application\\controllers\\' . $request->getController() . 'Controller';
     $action = $request->getAction();
     $parameters = $request->getParameters();
     if (class_exists($controllerName)) {
         $controller = new $controllerName();
         if (is_callable(array($controller, $action))) {
             $action = $request->getAction();
         } else {
             throw new \core\AppException("Ruta no valida", 1002);
         }
         if (isset($parameters)) {
             call_user_func_array(array($controller, $action), $parameters);
         } else {
             call_user_func(array($controller, $action));
         }
     } else {
         throw new \core\AppException("Controlador solicitada no es valido.", 1002);
     }
 }
Example #22
0
 public function __construct()
 {
     Core::$curent_class = get_called_class();
     // initialisation de la variable locale time limit
     Core::setTimeLimit();
     // initialisation des constantes des chemins de l'application
     Core::setPathConst();
     // initialisation des constantes issus du fichier de parametres
     Core::SetParameters();
     // initialisation du DNS (PDO)
     Core::SetDns();
     // initialisation de l'autoloader de classe
     spl_autoload_register(array(__CLASS__, 'setAutoload'), true, false);
     //tret
     // initialisation des requetes serveur
     Request::init();
     /*Core::$abstract= new AbstractModel();*/
     // initialisation de la session
     Session::start();
     $_SESSION = array();
     /*session_destroy();
       exit;/**/
     // initialisation de l'instance PDO
     Core::$pdo = new PdoControllers(new PdoInstance(DSN, DB_USER, DB_PASS));
     // initialisation du filemanager
     //Core::$file_manager = new FileManager();
     // initialisation de la base de données
     if (DB_RESET) {
         Core::setTimeLimit(0);
         DbInit::init();
         Core::setTimeLimit();
     }
     // initialisation Twig
     $path = Request::getController() != 'asset' ? View : Asset;
     Core::$twig = new Twig_Environment(new Twig_Loader_Filesystem($path), array('cache' => TWIG_CACHE == 1 ? CACHE : false, 'auto_reload' => TWIG_AUTO_RELOAD == 1 ? true : false));
     Core::$twig->addExtension(new Project_Twig_Extension(Core::$curent_class));
     // initialisation du header de la page
     header(Request::getHeader());
 }
Example #23
0
 public static function route(Request $request)
 {
     $controller = $request->getController() . 'Controller';
     $method = $request->getMethod();
     $args = $request->getArguments();
     $controllerFile = SITE_PATH . 'controllers/' . $controller . '.php';
     /* Given that controllerFile exists and is readable,
        include the file, instantiate controller-class and call method
        (default 'index') */
     if (is_readable($controllerFile)) {
         require_once $controllerFile;
         $controller = new $controller();
         $method = is_callable([$controller, $method]) ? $method : 'index';
         if (!empty($args)) {
             call_user_func_array([$controller, $method], $args);
         } else {
             call_user_func([$controller, $method]);
         }
         return;
     }
     throw new Exception('404 -  ' . $controller . ' not found');
 }
Example #24
0
 public static function run(Request $request)
 {
     $nameController = $request->getController() . "Controller";
     $action = $request->getAction() . "Action";
     $filePath = "src/controller" . $nameController . "php";
     $className = $nameController;
     if (file_exists($filePath)) {
         require_once $filePath;
         if (class_exists($className)) {
             $controller = new $nameController();
             if (method_exists($controller, $action)) {
                 call_user_func(array($controller, $action));
             } else {
                 var_dump("Не существует экшена" . $action);
             }
         } else {
             var_dump("Структура не соответствует  framework");
         }
     } else {
         die("Controller doesn't exist");
     }
 }
Example #25
0
 public function __construct(Request $r)
 {
     $controller = $r->getController() . 'Controller';
     $controllerPath = ROOT . 'controllers' . DS . $controller . '.php';
     $method = $r->getMethod();
     $arguments = $r->getArguments();
     //			echo "<hr/>$controllerPath<hr/>";
     if (is_readable($controllerPath)) {
         require_once $controllerPath;
         $controller = new $controller();
         if (!is_callable(array($controller, $method))) {
             $method = 'index';
         }
         if (isset($arguments)) {
             call_user_func_array(array($controller, $method), $arguments);
         } else {
             call_user_func(array($controller, $method));
         }
     } else {
         throw new Exception("<b>El controlador no se encuentra: " . $controllerPath . "</b>");
     }
 }
/**
 * Contruct controller and execute specific action
 *
 * @param Request $request
 * @return null
 * @throws ControllerDnxError
 * @throws InvalidControllerActionError
 */
function execute_action($request)
{
    $controller_name = $request->getController();
    // we'll use this a lot
    $use_controller = use_controller($controller_name, $request->getModule());
    if (is_error($use_controller)) {
        return $use_controller;
    }
    // if
    $controller_class = get_controller_class($controller_name);
    if (!class_exists($controller_class)) {
        use_error('ControllerDnxError');
        return new ControllerDnxError($controller_name);
    }
    // if
    $controller = new $controller_class($request);
    if (!instance_of($controller, 'Controller')) {
        use_error('ControllerDnxError');
        return new ControllerDnxError($controller_name);
    }
    // if
    return $controller->execute($request->getAction());
}
Example #27
0
 public static function run(Request $request)
 {
     $controller = $request->getController() . "Controller";
     $rout_controller = ROOT . 'protected' . DS . 'controllers' . DS . $controller . '.php';
     $method = $request->getMethod();
     $arguments = $request->getArguments();
     if (is_readable($rout_controller)) {
         require_once $rout_controller;
         $controller = new $controller();
         if (is_callable(array($controller, $method))) {
             $metodo = $request->getMethod();
         } else {
             $metodo = 'index';
         }
         if (isset($arguments)) {
             call_user_func_array(array($controller, $method), $arguments);
         } else {
             call_user_func($controller, $method);
         }
     } else {
         throw new Exception('EL ARCHIVO: "' . $rout_controller . '" NO FUE ENCONTRADO');
     }
 }
Example #28
0
 public static function run(Request $request)
 {
     $nameController = $request->getController() . "Controller";
     $action = $request->getAction() . "Action";
     $filePath = "src\\controller\\" . $nameController . ".php";
     var_dump($filePath);
     $className = $nameController;
     if (file_exists($filePath)) {
         require_once $filePath;
         if (class_exists($className)) {
             $controller = new $nameController();
             if (method_exists($controller, $action)) {
                 call_user_func(array($controller, $action));
             } else {
                 var_dump("Action doesn't exist " . $action);
             }
         } else {
             var_dump("Site map doesn't correspond to framefork");
         }
     } else {
         die("Controller doesn't exist");
     }
 }
Example #29
0
 /**
  * @param Request $request
  * @param Response $response
  * @return string
  * @throws RuntimeException
  */
 public function render(Request $request, Response $response)
 {
     $view = $response->getView();
     if (!$view instanceof View) {
         throw new RuntimeException('No View object set; unable to render view');
     }
     $response->setContentTypeHeader('html');
     $dir = strtolower($request->getController());
     if (null !== $view->getScriptDir()) {
         $dir = $view->getScriptDir();
     }
     $filename = strtolower($request->getAction());
     if (null !== $view->getScript()) {
         $filename = $view->getScript();
     }
     $scriptFile = sprintf('%s/views/%s/%s.phtml', APP_DIR, $dir, $filename);
     $scriptFile = str_replace('/', DIRECTORY_SEPARATOR, $scriptFile);
     if (!file_exists($scriptFile)) {
         throw new RuntimeException('View script not found: ' . $scriptFile);
     }
     unset($dir, $filename);
     ob_start();
     include $scriptFile;
     $body = ob_get_clean();
     if (null !== $view->getLayout()) {
         $layoutFile = sprintf('%s/views/layout/%s.phtml', APP_DIR, $view->getLayout()->getScript());
         $layoutFile = str_replace('/', DIRECTORY_SEPARATOR, $layoutFile);
         if (file_exists($layoutFile)) {
             $view->layout()->content = $body;
             unset($viewScript, $body);
             ob_start();
             include $layoutFile;
             $body = ob_get_clean();
         }
     }
     return $body;
 }
 public static function run(Request $getRequest)
 {
     $controller = $getRequest->getController() . 'Controller';
     $rootController = ROOT . 'controllers' . DS . $controller . '.php';
     $method = $getRequest->getMethod();
     $args = $getRequest->getArgs();
     if (is_readable($rootController)) {
         require $rootController;
         $controller = new $controller();
         if (is_callable(array($controller, $method))) {
             $method = $getRequest->getMethod();
         } else {
             $method = 'index';
         }
         if (isset($args)) {
             call_user_func_array(array($controller, $method), $args);
         } else {
             call_user_func(array($controller, $method));
         }
     } else {
         include 'public/error/404.php';
         // SHOW ERROR 404
     }
 }