normalizeServer() 공개 정적인 메소드

Pre-processes and returns the $_SERVER superglobal.
public static normalizeServer ( array $server ) : array
$server array
리턴 array
예제 #1
0
 public static function fromGlobals(array $server = null, array $query = null, array $body = null, array $cookies = null, array $files = null)
 {
     $server = parent::normalizeServer($server);
     $files = parent::normalizeFiles($files);
     $headers = parent::marshalHeaders($server);
     return new ServerRequest($server, $files, parent::marshalUriFromServer($server, $headers), parent::get('REQUEST_METHOD', $server, 'GET'), 'php://input', $headers, $cookies, $query, $body, self::marshalProtocolVersion($server));
 }
 public function testServerParams()
 {
     $swooleRequest = $this->createSwooleRequest(array('request_method' => 'GET', 'request_uri' => '/', 'path_info' => '/', 'request_time' => 123456789, 'server_port' => 9100, 'remote_port' => 49648, 'remote_addr' => '127.0.0.1', 'server_protocol' => 'HTTP/1.1', 'server_software' => 'swoole-http-server'), array('authorization' => 'Basic dXNlcm5hbWU6cGFzc3dvcmQ=', 'host' => 'syrma.local', 'connection' => 'close', 'user-agent' => 'curl/7.35.0', 'accept' => '*/*'));
     $request = $this->createTransformer()->transform($swooleRequest);
     $expServerParams = new ServerRequest(ServerRequestFactory::normalizeServer(array('REQUEST_METHOD' => 'GET', 'REQUEST_URI' => '/', 'PATH_INFO' => '/', 'REQUEST_TIME' => 123456789, 'SERVER_PORT' => 9100, 'REMOTE_PORT' => 49648, 'REMOTE_ADDR' => '127.0.0.1', 'SERVER_PROTOCOL' => 'HTTP/1.1', 'SERVER_SOFTWARE' => 'swoole-http-server', 'HTTP_AUTHORIZATION' => 'Basic dXNlcm5hbWU6cGFzc3dvcmQ=', 'HTTP_HOST' => 'syrma.local', 'HTTP_CONNECTION' => 'close', 'HTTP_USER-AGENT' => 'curl/7.35.0', 'HTTP_ACCEPT' => '*/*')));
     $this->assertInstanceOf(ServerRequest::class, $request);
     /* @var  ServerRequest $request */
     $this->assertSame($expServerParams->getServerParams(), $request->getServerParams());
 }
 public function testServerParams()
 {
     $reactRequest = $this->createReactRequest('GET', '/', array(), '1.1', array('Host' => 'syrma.local', 'Connection' => 'close', 'User-Agent' => 'curl/7.35.0', 'Accept' => '*/*', 'Authorization' => 'Basic dXNlcm5hbWU6cGFzc3dvcmQ='));
     $reactRequest->remoteAddress = '127.0.0.1';
     $request = $this->createTransformer()->transform($reactRequest);
     $expServerParams = new ServerRequest(ServerRequestFactory::normalizeServer(array('REQUEST_METHOD' => 'GET', 'REQUEST_URI' => '/', 'SERVER_PROTOCOL' => 'HTTP/1.1', 'SERVER_SOFTWARE' => 'reactphp-http', 'REMOTE_ADDR' => '127.0.0.1', 'HTTP_AUTHORIZATION' => 'Basic dXNlcm5hbWU6cGFzc3dvcmQ=', 'HTTP_HOST' => 'syrma.local', 'HTTP_CONNECTION' => 'close', 'HTTP_USER-AGENT' => 'curl/7.35.0', 'HTTP_ACCEPT' => '*/*')));
     $this->assertInstanceOf(ServerRequest::class, $request);
     /* @var  ServerRequest $request */
     $this->assertEquals($expServerParams->getServerParams(), $request->getServerParams());
 }
예제 #4
0
파일: Flow.php 프로젝트: aimeos/ai-flow
 /**
  * Creates a PSR-7 compatible request
  *
  * @param \TYPO3\Flow\Http\Request $nativeRequest Flow request object
  * @param array $files List of uploaded files like in $_FILES
  * @param array $query List of uploaded files like in $_GET
  * @param array $post List of uploaded files like in $_POST
  * @param array $cookies List of uploaded files like in $_COOKIES
  * @param array $server List of uploaded files like in $_SERVER
  * @return \Psr\Http\Message\ServerRequestInterface PSR-7 request object
  */
 protected function createRequest(\TYPO3\Flow\Http\Request $nativeRequest, array $files, array $query, array $post, array $cookies, array $server)
 {
     $server = ServerRequestFactory::normalizeServer($server);
     $files = ServerRequestFactory::normalizeFiles($files);
     $headers = $nativeRequest->getHeaders()->getAll();
     $uri = (string) $nativeRequest->getUri();
     $method = $nativeRequest->getMethod();
     $body = new Stream('php://temp', 'wb+');
     $body->write($nativeRequest->getContent());
     return new ServerRequest($server, $files, $uri, $method, $body, $headers, $cookies, $query, $post);
 }
예제 #5
0
파일: Typo3.php 프로젝트: aimeos/ai-typo3
 /**
  * Creates a PSR-7 compatible request
  *
  * @param \TYPO3\Flow\Http\Request $nativeRequest Flow request object
  * @param array $files List of uploaded files like in $_FILES
  * @param array $query List of uploaded files like in $_GET
  * @param array $post List of uploaded files like in $_POST
  * @param array $cookies List of uploaded files like in $_COOKIES
  * @param array $server List of uploaded files like in $_SERVER
  * @return \Psr\Http\Message\ServerRequestInterface PSR-7 request object
  */
 protected function createRequest(array $files, array $query, array $post, array $cookies, array $server)
 {
     if (!isset($server['HTTP_HOST'])) {
         $server['HTTP_HOST'] = 'localhost';
     }
     $files = ServerRequestFactory::normalizeFiles($files);
     $server = ServerRequestFactory::normalizeServer($server);
     $headers = ServerRequestFactory::marshalHeaders($server);
     $uri = ServerRequestFactory::marshalUriFromServer($server, $headers);
     $method = ServerRequestFactory::get('REQUEST_METHOD', $server, 'GET');
     return new ServerRequest($server, $files, $uri, $method, 'php://input', $headers, $cookies, $query, $post);
 }
 /**
  * {@inheritdoc}
  */
 public function createRequest(Request $symfonyRequest)
 {
     $server = DiactorosRequestFactory::normalizeServer($symfonyRequest->server->all());
     $headers = $symfonyRequest->headers->all();
     $body = new DiactorosStream('php://temp', 'wb+');
     $body->write($symfonyRequest->getContent());
     $request = new ServerRequest($server, DiactorosRequestFactory::normalizeFiles($this->getFiles($symfonyRequest->files->all())), $symfonyRequest->getUri(), $symfonyRequest->getMethod(), $body, $headers);
     $request = $request->withCookieParams($symfonyRequest->cookies->all())->withQueryParams($symfonyRequest->query->all())->withParsedBody($symfonyRequest->request->all());
     foreach ($symfonyRequest->attributes->all() as $key => $value) {
         $request = $request->withAttribute($key, $value);
     }
     return $request;
 }
예제 #7
0
 /**
  * Transforms a Symfony request into a PSR-7 request object
  *
  * @param \Illuminate\Http\Request $nativeRequest Laravel request object
  * @return \Psr\Http\Message\ServerRequestInterface PSR-7 request object
  */
 protected function createRequest(\Illuminate\Http\Request $nativeRequest)
 {
     $files = ServerRequestFactory::normalizeFiles($this->getFiles($nativeRequest->files->all()));
     $server = ServerRequestFactory::normalizeServer($nativeRequest->server->all());
     $headers = $nativeRequest->headers->all();
     $cookies = $nativeRequest->cookies->all();
     $post = $nativeRequest->request->all();
     $query = $nativeRequest->query->all();
     $method = $nativeRequest->getMethod();
     $uri = $nativeRequest->getUri();
     $body = new Stream('php://temp', 'wb+');
     $body->write($nativeRequest->getContent());
     $request = new ServerRequest($server, $files, $uri, $method, $body, $headers, $cookies, $query, $post);
     foreach ($nativeRequest->attributes->all() as $key => $value) {
         $request = $request->withAttribute($key, $value);
     }
     return $request;
 }
예제 #8
0
 /**
  * Sapi constructor.
  *
  * @param EmitterInterface                $sapiEmitter
  * @param array|null                      $server
  * @param array|null                      $queryParams
  * @param array|object|null               $parsedBody
  * @param array|null                      $cookies
  * @param array|null                      $files
  * @param string|resource|StreamInterface $messageBody
  *
  * @SuppressWarnings(PHPMD.StaticAccess)
  * @SuppressWarnings(PHPMD.Superglobals)
  */
 public function __construct(EmitterInterface $sapiEmitter, array $server = null, array $queryParams = null, array $parsedBody = null, array $cookies = null, array $files = null, $messageBody = 'php://input')
 {
     $this->sapiEmitter = $sapiEmitter;
     // returns value if not null or $fallback otherwise
     $get = function ($nullable, $fallback) {
         return $nullable !== null ? $nullable : $fallback;
     };
     // Code below based on ServerRequestFactory::fromGlobals
     $this->server = ServerRequestFactory::normalizeServer($get($server, $_SERVER));
     $this->files = ServerRequestFactory::normalizeFiles($get($files, $_FILES));
     $this->headers = ServerRequestFactory::marshalHeaders($this->server);
     $this->uri = ServerRequestFactory::marshalUriFromServer($this->server, $this->headers);
     $this->method = ServerRequestFactory::get('REQUEST_METHOD', $this->server, 'GET');
     $this->cookies = $get($cookies, $_COOKIE);
     $this->queryParams = $get($queryParams, $_GET);
     $this->parsedBody = $get($parsedBody, $_POST);
     $this->messageBody = $messageBody;
 }
예제 #9
0
 /**
  * {@inheritdoc}
  */
 public function getServerRequest()
 {
     $query = $this->getQuery();
     $post = $this->getPost();
     $cookies = $this->getCookies();
     $server = ServerRequestFactory::normalizeServer($this->params);
     $headers = ServerRequestFactory::marshalHeaders($server);
     $uri = ServerRequestFactory::marshalUriFromServer($server, $headers);
     $method = ServerRequestFactory::get('REQUEST_METHOD', $server, 'GET');
     $request = new ServerRequest($server, [], $uri, $method, $this->stdin, $headers);
     return $request->withCookieParams($cookies)->withQueryParams($query)->withParsedBody($post);
 }