Пример #1
0
 public function __construct()
 {
     $this->app = \Framework\App::getInstance();
     $this->view = \Framework\View::getInstance();
     $this->config = $this->app->getConfig();
     $this->input = \Framework\InputData::getInstance();
 }
 public function dispatch()
 {
     if ($this->router == null) {
         throw new \Exception('No valid router found', 500);
     }
     $configParams = null;
     $_uri = $this->router->getUri();
     $routes = App::getInstance()->getConfig()->routes;
     if (is_array($routes) && count($routes) > 0) {
         foreach ($routes as $key => $value) {
             if (stripos($_uri, $key) === 0 && ($_uri == $key || stripos($_uri, $key . '/') === 0) && $value['namespace']) {
                 $this->namespace = $value['namespace'];
                 $_uri = substr($_uri, strlen($key) + 1);
                 $configParams = $value;
                 break;
             }
         }
     } else {
         throw new \Exception('Default route missing', 500);
     }
     if ($this->namespace == null && $routes['*']['namespace']) {
         $this->namespace = $routes['*']['namespace'];
         $configParams = $routes['*'];
     } else {
         if ($this->namespace == null && !$routes['*']['namespace']) {
             throw new \Exception('Default route missing', 500);
         }
     }
     $this->input = InputData::getInstance();
     $_params = explode('/', $_uri);
     if ($_params[0]) {
         $this->controller = strtolower($_params[0]);
         if ($_params[1]) {
             $this->method = strtolower($_params[1]);
             unset($_params[0], $_params[1]);
             $this->params = array_values($_params);
             $this->input->setGet($this->params);
         } else {
             $this->method = $this->getDefaultMethod();
         }
     } else {
         $this->controller = $this->getDefaultController();
         $this->method = $this->getDefaultMethod();
     }
     if (is_array($configParams) && $configParams['controllers']) {
         if ($configParams['controllers'][$this->controller]['methods'][$this->method]) {
             $this->method = strtolower($configParams['controllers'][$this->controller]['methods'][$this->method]);
         }
         if (isset($configParams['controllers'][$this->controller]['to'])) {
             $this->controller = strtolower($configParams['controllers'][$this->controller]['to']);
         }
     }
     $this->input->setPost($this->router->getPost());
     $controller = $this->namespace . '\\' . ucfirst($this->controller);
     $newController = new $controller();
     $this->loadMethod($newController);
 }
Пример #3
0
 public function __construct()
 {
     $this->app = App::getInstance();
     $this->view = View::getInstance();
     $this->config = $this->app->getConfig();
     $this->input = InputData::getInstance();
     $this->session = $this->app->getSession();
     $this->db = new SimpleDB();
 }
Пример #4
0
 public function dispatch()
 {
     $router = new \Framework\Routers\DefaultRouter();
     if ($this->router == null) {
         throw new \Exception("No valid router found", 500);
     }
     $uri = $this->router->getUri();
     $routes = \Framework\App::getInstance()->getConfig()->routes;
     $rc = null;
     if (is_array($routes) && count($routes) > 0) {
         foreach ($routes as $key => $value) {
             if (stripos($uri, $key) === 0 && ($uri == $key || stripos($uri, $key . '/') === 0) && $value['namespace']) {
                 $this->ns = $value['namespace'];
                 $uri = substr($uri, strlen($key) + 1);
                 $rc = $value;
                 break;
             }
         }
     } else {
         throw new \Exception("No routes.", 500);
     }
     if ($this->ns == null && $routes['*']['namespace']) {
         $this->ns = $routes['*']['namespace'];
         $rc = $routes['*'];
     } else {
         if ($this->ns == null && !$routes['*']['namespace']) {
             throw new \Exception("Default routes missing", 500);
         }
     }
     $input = \Framework\InputData::getInstance();
     $params = explode('/', $uri);
     if ($params[0]) {
         $this->controller = strtolower($params[0]);
         if ($params[1]) {
             $this->method = strtolower($params[1]);
             unset($params[0], $params[1]);
             $input->setGet(array_values($params));
         } else {
             $this->method = $this->getDefaultMethod();
         }
     } else {
         $this->controller = $this->getDefaultController();
         $this->method = $this->getDefaultMethod();
     }
     if (is_array($rc) && $rc['controllers']) {
         if ($rc['controllers'][$this->controller]['methods'][$this->method]) {
             $this->method = strtolower($rc['controllers'][$this->controller]['methods'][$this->method]);
         }
         if (isset($rc['controllers'][$this->controller]['to'])) {
             $this->controller = strtolower($rc['controllers'][$this->controller]['to']);
         }
     }
     $input->setPost($this->router->getPost());
     $controllerClass = $this->ns . '\\' . ucfirst($this->controller);
     $newController = new $controllerClass();
     $newController->{$this->method}();
 }
 public function dispatch()
 {
     if ($this->_router == null) {
         throw new \Exception('No valid router found.', 500);
     }
     $uri = $this->_router->getURI();
     $routes = App::getInstance()->getConfig()->routes;
     $_rc = null;
     if (is_array($routes) && count($routes) > 0) {
         foreach ($routes as $route => $value) {
             if (stripos($uri, $route) === 0 && ($uri == $route || strpos($uri, $route . '/') === 0) && $value['namespace']) {
                 $this->_namespace = $value['namespace'];
                 $uri = substr($uri, strlen($route) + 1);
                 $_rc = $value;
                 break;
             }
         }
     } else {
         throw new \Exception('Default route missing', 500);
     }
     if ($this->_namespace == null && $routes['*']['namespace']) {
         $this->_namespace = $routes['*']['namespace'];
         $_rc = $routes['*'];
     } else {
         if ($this->_namespace == null && !$routes['*']['namespace']) {
             throw new \Exception('Default route missing', 500);
         }
     }
     $input = InputData::getInstance();
     $params = explode('/', $uri);
     if ($params[0]) {
         $this->_controller = strtolower($params[0]);
         if ($params[1]) {
             $this->_method = strtolower($params[1]);
             unset($params[0], $params[1]);
             $input->setGet(array_values($params));
         } else {
             $this->_method = $this->getDefaultMethod();
         }
     } else {
         $this->_controller = $this->getDefaultController();
         $this->_method = $this->getDefaultMethod();
     }
     if (is_array($_rc) && $_rc['controllers']) {
         if ($_rc['controllers'][$this->_controller]['methods'][$this->_method]) {
             $this->_method = strtolower($_rc['controllers'][$this->_controller]['methods'][$this->_method]);
         }
         if (isset($_rc['controllers'][$this->_controller]['to'])) {
             $this->_controller = strtolower($_rc['controllers'][$this->_controller]['to']);
         }
     }
     $input->setPost($this->_router->getPost());
     $contructed = $this->_namespace . '\\' . ucfirst($this->_controller);
     $newController = new $contructed();
     $newController->{$this->_method}();
 }
Пример #6
0
 public function __construct()
 {
     $this->app = App::getInstance();
     $this->view = View::getInstance();
     $this->config = $this->app->getConfig();
     $this->input = InputData::getInstance();
     $this->db = new SimpleDatabase();
     $this->session = $this->app->getSession();
     $this->path = isset($this->config->app['default_path']) ? $this->config->app['default_path'] : null;
 }
 public function __construct()
 {
     $this->app = App::getInstance();
     $this->view = View::getInstance();
     $this->config = $this->app->getConfig();
     $this->input = InputData::getInstance();
     if (is_null($this->session)) {
         $this->session = new NativeSession('session');
     }
 }
Пример #8
0
 private function processController()
 {
     $input = InputData::getInstance();
     $input->setGet($this->_params);
     $input->setPost($this->_router->GetPost());
     $file = ucfirst($this->_namespace) . '\\' . ucfirst($this->_controller);
     $this->_controller = $file;
     $realPath = str_replace('\\', DIRECTORY_SEPARATOR, '../' . $file . '.php');
     $realPath = realpath($realPath);
     if (file_exists($realPath) && is_readable($realPath)) {
         $calledController = new $file();
         if (method_exists($calledController, $this->_method)) {
             if ($this->isValidRequestMethod($calledController, $this->_method)) {
                 // Create binding model
                 $refMethod = new \ReflectionMethod($calledController, $this->_method);
                 $doc = $refMethod->getDocComment();
                 // Validate accessibility
                 $this->ValidateAuthorization($doc);
                 if (preg_match('/@param\\s+\\\\?([\\s\\S]+BindingModel)\\s+\\$/', $doc, $match)) {
                     $bindingModelName = $match[1];
                     $bindingModelsNamespace = App::getInstance()->getConfig()->app['namespaces']['Models'] . 'BindingModels/';
                     $bindingModelsNamespace = str_replace('../', '', $bindingModelsNamespace);
                     $bindingModelPath = str_replace('/', '\\', $bindingModelsNamespace . $bindingModelName);
                     $bindingReflection = new \ReflectionClass($bindingModelPath);
                     $properties = $bindingReflection->getProperties();
                     $params = array();
                     foreach ($properties as $property) {
                         $name = $property->getName();
                         $value = $input->postForDb($name);
                         if ($value === null) {
                             throw new \Exception("Invalid binding model! Property '{$name}' not found", 400);
                         } else {
                             $params[$name] = $value;
                         }
                     }
                     $bindingModel = new $bindingModelPath($params);
                     Injector::getInstance()->loadDependencies($calledController);
                     $calledController->{strtolower($this->_method)}($bindingModel);
                 } else {
                     Injector::getInstance()->loadDependencies($calledController);
                     $calledController->{strtolower($this->_method)}();
                 }
                 exit;
             } else {
                 throw new \Exception("Method does not allow '" . ucfirst($this->_requestMethod) . "' requests!", 500);
             }
         } else {
             throw new \Exception("'" . $this->_method . "' not found in '" . $file . '.php', 404);
         }
     } else {
         throw new \Exception("File '" . $file . '.php' . "' not found!", 404);
     }
 }