本文整理匯總了PHP中Zend\Diactoros\ServerRequestFactory::normalizeFiles方法的典型用法代碼示例。如果您正苦於以下問題:PHP ServerRequestFactory::normalizeFiles方法的具體用法?PHP ServerRequestFactory::normalizeFiles怎麽用?PHP ServerRequestFactory::normalizeFiles使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Zend\Diactoros\ServerRequestFactory
的用法示例。
在下文中一共展示了ServerRequestFactory::normalizeFiles方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: fromGlobals
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));
}
示例2: testUpladedFiles
public function testUpladedFiles()
{
$rawFiles = array('file1' => array('name' => 'space-05.jpg', 'type' => 'image/jpeg', 'tmp_name' => '/tmp/2f588692b23b25fdd88f9ad4848dbd17', 'error' => 0, 'size' => 14620), 'myFiles' => array(array('name' => 'space-04.jpg', 'type' => 'image/png', 'tmp_name' => '/tmp/2794797237924797237d88f9ad4848dbd17', 'error' => 0, 'size' => 1620), array('name' => 'space-03.jpg', 'type' => 'image/png', 'tmp_name' => '/tmp/2794797237924797237d88f9ad4848d1237', 'error' => 0, 'size' => 620)));
$swooleRequest = $this->createSwooleRequest(array(), array(), $rawFiles);
$request = $this->createTransformer()->transform($swooleRequest);
$this->assertInstanceOf(ServerRequest::class, $request);
$files = ServerRequestFactory::normalizeFiles($rawFiles);
/* @var ServerRequest $request */
$this->assertEquals($files, $request->getUploadedFiles());
}
示例3: createRequest
/**
* 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);
}
示例4: createRequest
/**
* 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);
}
示例5: createRequest
/**
* {@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;
}
示例6: createRequest
/**
* 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;
}
示例7: testUpladedFiles
public function testUpladedFiles()
{
$f1 = fopen('php://memory', 'r');
$f2 = fopen('php://memory', 'r');
$f3 = fopen('php://memory', 'r');
$rawFiles = array('file1' => array('name' => 'space-05.jpg', 'type' => 'image/jpeg', 'stream' => $f1, 'error' => 0, 'size' => 14620), 'myFiles' => array(array('name' => 'space-04.jpg', 'type' => 'image/png', 'stream' => $f2, 'error' => 0, 'size' => 1620), array('name' => 'space-03.jpg', 'type' => 'image/png', 'stream' => $f3, 'error' => 0, 'size' => 620)));
$refFiles = array('file1' => array('name' => 'space-05.jpg', 'type' => 'image/jpeg', 'tmp_name' => $f1, 'error' => 0, 'size' => 14620), 'myFiles' => array(array('name' => 'space-04.jpg', 'type' => 'image/png', 'tmp_name' => $f2, 'error' => 0, 'size' => 1620), array('name' => 'space-03.jpg', 'type' => 'image/png', 'tmp_name' => $f3, 'error' => 0, 'size' => 620)));
try {
$reactRequest = $this->createReactRequest('POST');
$reactRequest->setFiles($rawFiles);
$request = $this->createTransformer()->transform($reactRequest);
$this->assertInstanceOf(ServerRequest::class, $request);
$files = ServerRequestFactory::normalizeFiles($refFiles);
/* @var ServerRequest $request */
$this->assertEquals($files, $request->getUploadedFiles());
} finally {
fclose($f1);
fclose($f2);
fclose($f3);
}
}
示例8: __construct
/**
* 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;
}