예제 #1
0
 /**
  * ServerRequest constructor.
  *
  * @param array $get
  * @param array $post
  * @param array $files
  * @param array $cookie
  * @param array $server
  * @param SessionHandler|null $sessionHandler
  */
 public function __construct(array $get = [], array $post = [], array $files = [], array $cookie = [], array $server = [], SessionHandler $sessionHandler = null)
 {
     $this->query = new Bag($get);
     $this->body = new Bag($post);
     $this->server = new ServerBag($server);
     $this->cookie = new CookieBag($cookie);
     $this->file = new FileBag($files);
     $headers = [];
     array_walk($server, function ($value, $key) use(&$headers) {
         if (0 === strpos($key, 'HTTP_')) {
             $headers[$key] = $value;
         }
     });
     parent::__construct(sprintf('%s://%s', $this->server->getScheme(), $this->server->getHost() . $this->server->getBaseUrl() . $this->server->getPathInfo()), $headers, 'php://input');
     $this->withMethod($this->server->getMethod());
     unset($headers);
     try {
         $sessionKey = $this->getHeaderLine(Session::SESSION_KEY);
     } catch (InvalidArgumentException $e) {
         $sessionKey = null;
     }
     $this->session = Session::start($sessionKey, $sessionHandler);
     $this->withHeader(Session::SESSION_KEY, $this->session->getSessionId());
     $this->withCookieParams([Session::SESSION_KEY => $this->session->getSessionId()]);
 }
예제 #2
0
 public function testMethod()
 {
     $serverBag = new ServerBag($this->_server);
     $this->assertEquals('GET', $serverBag->getMethod());
     $this->assertTrue($serverBag->isMethod('get'));
     $this->assertTrue($serverBag->isMethod('GET'));
     $this->_server['REQUEST_METHOD'] = 'POST';
     $serverBag = new ServerBag($this->_server);
     $this->assertEquals('POST', $serverBag->getMethod());
     $this->assertTrue($serverBag->isMethod('post'));
     $this->assertTrue($serverBag->isMethod('POST'));
 }