Example #1
0
 /**
  * @param array $server
  * @param array $get
  * @param array $post
  * @param array $cookies
  * @param array $files
  * @param \Psr\Http\Message\StreamInterface $stream
  * @return \Psr\Http\Message\ServerRequestInterface
  */
 public function factory(array $server, array $get, array $post, array $cookies, array $files, StreamInterface $stream = null)
 {
     if (!isset($stream)) {
         $stream = new Stream('php://memory');
     }
     $headers = $this->getHeadersFromServerParams($server);
     if (isset($headers['content-type']) && strpos($headers['content-type'][0], 'application/json') === 0) {
         $post = json_decode($stream->__toString(), true);
     }
     return new ServerRequest($server, $cookies, $get, $this->fileFactory->fromFiles($files), $post, [], isset($server['REQUEST_METHOD']) ? $server['REQUEST_METHOD'] : 'GET', $this->getUri($server), '1.1', $headers, $stream);
 }
Example #2
0
 public function testCloseAndException()
 {
     $stream = new Stream('php://memory', 'w+');
     $stream->close();
     $stream->close();
     $this->assertFalse($stream->isWritable());
     $this->assertFalse($stream->isReadable());
     $this->assertFalse($stream->isSeekable());
     $this->assertSame('', $stream->__toString());
     $this->assertNull($stream->getSize());
     $this->assertTrue($stream->eof());
     try {
         $stream->write('...?');
         $this->fail();
     } catch (RuntimeException $e) {
         $this->assertEquals('No resource available.', $e->getMessage());
     }
 }
Example #3
0
 /**
  * @param array $server
  * @param array $get
  * @param array $post
  * @param array $cookies
  * @param array $files
  * @param \Psr\Http\Message\StreamInterface $stream
  * @return \Psr\Http\Message\ServerRequestInterface
  */
 public function create(array $server, array $get, array $post, array $cookies, array $files, StreamInterface $stream = null)
 {
     if (!isset($stream)) {
         $stream = new Stream('php://memory');
     }
     $headers = $this->getPsrHeadersFromServerParams($server);
     // exists body, but not exists posts
     $bodyContent = $stream->__toString();
     if ($bodyContent !== '' && count($post) === 0) {
         if (isset($headers['content-type'])) {
             // do not define multipart/form-data
             // because, it use only in POST method.
             // ref. en: https://issues.apache.org/jira/browse/FILEUPLOAD-197#comment-13595136
             // ref. kr: https://blog.outsider.ne.kr/1001
             if (strpos($headers['content-type'], 'application/json') === 0) {
                 $jsonBody = json_decode($bodyContent, true);
                 $post = $jsonBody ? $jsonBody : $post;
             } elseif (strpos($headers['content-type'], 'application/x-www-form-urlencoded') === 0) {
                 parse_str($bodyContent, $post);
             }
         }
     }
     return new ServerRequest($server, $get, $post, $cookies, $this->fileFactory->createFromFiles($files), [], isset($server['REQUEST_METHOD']) ? $server['REQUEST_METHOD'] : 'GET', $this->getUri($server), $stream, $headers, '1.1');
 }
Example #4
0
 public function __construct()
 {
     $stream = new Stream('php://input');
     parent::__construct($stream->__toString());
 }