Beispiel #1
0
 /**
  *
  * @param Symfony\Component\BrowserKit\Request $request
  * @return \Symfony\Component\BrowserKit\Response
  */
 public function doRequest($request)
 {
     $this->_headers = array();
     $_COOKIE = array_merge($_COOKIE, $request->getCookies());
     $_SERVER = array_merge($_SERVER, $request->getServer());
     $_FILES = $request->getFiles();
     $_REQUEST = $request->getParameters();
     if (strtoupper($request->getMethod()) == 'GET') {
         $_GET = $request->getParameters();
     } else {
         $_POST = $request->getParameters();
     }
     // Parse url parts
     $uriPath = trim(parse_url($request->getUri(), PHP_URL_PATH), '/');
     $uriQuery = ltrim(parse_url($request->getUri(), PHP_URL_QUERY), '?');
     $scriptName = trim(parse_url($this->url, PHP_URL_PATH), '/');
     if (!empty($uriQuery)) {
         $uriPath .= "?{$uriQuery}";
         parse_str($uriQuery, $params);
         foreach ($params as $k => $v) {
             $_GET[$k] = $v;
         }
     }
     // Add script name to request if none
     if (strpos($uriPath, $scriptName) === false) {
         $uriPath = "/{$scriptName}/{$uriPath}";
     }
     // Add forward slash if not exists
     if (strpos($uriPath, '/') !== 0) {
         $uriPath = "/{$uriPath}";
     }
     $_SERVER['REQUEST_METHOD'] = strtoupper($request->getMethod());
     $_SERVER['REQUEST_URI'] = $uriPath;
     /**
      * Hack to be sure that CHttpRequest will resolve route correctly
      */
     $_SERVER['SCRIPT_NAME'] = "/{$scriptName}";
     $_SERVER['SCRIPT_FILENAME'] = $this->appPath;
     ob_start();
     Yii::setApplication(null);
     Yii::createApplication($this->appSettings['class'], $this->appSettings['config']);
     Yii::app()->onEndRequest->add(array($this, 'setHeaders'));
     Yii::app()->run();
     $content = ob_get_clean();
     $headers = $this->getHeaders();
     $statusCode = 200;
     foreach ($headers as $header => $val) {
         if ($header == 'Location') {
             $statusCode = 302;
         }
     }
     $response = new Response($content, $statusCode, $this->getHeaders());
     return $response;
 }
Beispiel #2
0
 /**
  *
  * @param Symfony\Component\BrowserKit\Request $request
  * @return \Symfony\Component\BrowserKit\Response
  */
 public function doRequest($request)
 {
     $this->_headers = array();
     $_COOKIE = array_merge($_COOKIE, $request->getCookies());
     $_SERVER = array_merge($_SERVER, $request->getServer());
     $_FILES = $request->getFiles();
     $_REQUEST = $request->getParameters();
     if (strtoupper($request->getMethod()) == 'GET') {
         $_GET = $request->getParameters();
     } else {
         $_POST = $request->getParameters();
     }
     $uri = str_replace('http://localhost', '', $request->getUri());
     $scriptName = str_replace('http://localhost', '', $this->url);
     $queryString = parse_url($uri, PHP_URL_QUERY);
     parse_str($queryString, $params);
     if (strpos($uri, $scriptName) === false) {
         $uri = $scriptName . $queryString;
     }
     foreach ($params as $k => $v) {
         $_GET[$k] = $v;
     }
     $_SERVER['REQUEST_METHOD'] = strtoupper($request->getMethod());
     $_SERVER['REQUEST_URI'] = $uri;
     /**
      * Hack to be sure that CHttpRequest will resolve route correctly
      */
     $_SERVER['SCRIPT_NAME'] = $scriptName;
     $_SERVER['SCRIPT_FILENAME'] = $this->appPath;
     ob_start();
     Yii::setApplication(null);
     Yii::createApplication($this->appSettings['class'], $this->appSettings['config']);
     Yii::app()->onEndRequest->add(array($this, 'setHeaders'));
     Yii::app()->run();
     $content = ob_get_clean();
     $headers = $this->getHeaders();
     $statusCode = 200;
     foreach ($headers as $header => $val) {
         if ($header == 'Location') {
             $statusCode = 302;
         }
     }
     $response = new Response($content, $statusCode, $this->getHeaders());
     return $response;
 }