Exemple #1
0
 public static function getIncomeRequest()
 {
     if (!self::$_incomeRequestInstance) {
         self::$_incomeRequestInstance = new Request();
         self::$_incomeRequestInstance->processEnvironment();
     }
     return self::$_incomeRequestInstance;
 }
Exemple #2
0
 public function testRequestServer()
 {
     $_SERVER['REQUEST_METHOD'] = Request::METHOD_GET;
     $_SERVER['REQUEST_URI'] = '/products/2/';
     $_SERVER['QUERY_STRING'] = 'id=12';
     $_SERVER['HTTP_HOST'] = 'test.com';
     $_SERVER['DOCUMENT_ROOT'] = '/';
     $request = new Request();
     $request->processEnvironment();
     $this->assertEquals(12, $request->getVar('id'), 'parsing query string');
 }
Exemple #3
0
 public function getRequestVars()
 {
     if (!$this->_request) {
         return null;
     }
     return $this->_request->getVars();
 }
Exemple #4
0
 public function detectApplication()
 {
     DC::getEventDispatcher()->dispatchEvent('route.buildRequest', Request::getIncomeRequest());
     $this->_name = 'console';
     $this->_config = array('uri' => 'solve/', 'path' => 'SolveConsole/');
     $this->_namespace = 'SolveConsole';
     $this->_root = realpath(__DIR__ . '/../SolveConsole/') . '/';
     DC::getAutoloader()->registerNamespacePath($this->_namespace, realpath(__DIR__ . '/../') . '/');
     ControllerService::setActiveNamespace($this->_namespace);
     return $this->_name;
 }
Exemple #5
0
 public function testRequestProcess()
 {
     $router = Router::getMainInstance();
     $_SERVER['REQUEST_METHOD'] = Request::METHOD_GET;
     $_SERVER['REQUEST_URI'] = '/products/2/?id=12';
     $_SERVER['QUERY_STRING'] = 'id=12';
     $_SERVER['HTTP_HOST'] = 'test.com';
     $_SERVER['DOCUMENT_ROOT'] = '/';
     $request = Request::getIncomeRequest();
     $route = $router->processRequest($request)->getCurrentRoute();
     $this->assertTrue($route->isNotFound(), 'route not found without subfolder');
     $_SERVER['REQUEST_URI'] = 'project1/products/2/?id=12';
     $newIncomeRequest = Request::createInstance()->processEnvironment();
     $route = $router->processRequest($newIncomeRequest)->getCurrentRoute();
     $this->assertEquals('Product', $route->getVar('controller'), 'Route detected');
     $this->assertEquals(12, $route->getRequestVar('id'), 'request var detected');
 }
Exemple #6
0
 public function processIncomeRequest()
 {
     return $this->processRequest(Request::getIncomeRequest());
 }
Exemple #7
0
 public function detectApplication()
 {
     DC::getEventDispatcher()->dispatchEvent('route.buildRequest', Request::getIncomeRequest());
     /**
      * @var ArrayStorage $appList
      */
     $appList = DC::getProjectConfig('applications');
     if (empty($appList)) {
         throw new \Exception('Empty application list');
     }
     $defaultAppName = DC::getProjectConfig('defaultApplication', 'frontend');
     $this->_name = $defaultAppName;
     $uri = (string) Request::getIncomeRequest()->getUri();
     $uriParts = explode('/', $uri);
     $webRoot = DC::getRouter()->getWebRoot();
     if (strlen($webRoot) > 1) {
         if (strpos($uri, substr($webRoot, 1)) === 0) {
             $uriParts = explode('/', substr($uri, strlen($webRoot)));
         }
     }
     if (!empty($uriParts) && (count($uriParts) > 0 && $uriParts[0] != '/')) {
         foreach ($appList as $appName => $appParams) {
             if ($appName == $defaultAppName) {
                 continue;
             }
             $appUri = !empty($appParams['uri']) ? $appParams['uri'] : $appName;
             if (strpos($uriParts[0], $appUri) === 0) {
                 array_shift($uriParts);
                 Request::getIncomeRequest()->setUri((strlen($webRoot) > 1 ? $webRoot . '/' : '') . implode('/', $uriParts));
                 $this->_name = $appName;
                 break;
             }
         }
     }
     $this->_config = DC::getProjectConfig('applications/' . $this->_name);
     if (!is_array($this->_config)) {
         $this->_config = array('uri' => $this->_name);
     }
     if (empty($this->_config['path'])) {
         $this->_config['path'] = Inflector::camelize($this->_name) . '/';
     }
     $this->_namespace = Inflector::camelize($this->_name);
     $this->_root = DC::getEnvironment()->getApplicationRoot() . $this->_config['path'];
     DC::getAutoloader()->registerNamespacePath($this->_namespace, DC::getEnvironment()->getApplicationRoot());
     ControllerService::setActiveNamespace($this->_namespace);
     return $this->_name;
 }