本文整理汇总了PHP中GuzzleHttp\Psr7\stream_for函数的典型用法代码示例。如果您正苦于以下问题:PHP stream_for函数的具体用法?PHP stream_for怎么用?PHP stream_for使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了stream_for函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct($environment, $output, $input, $headers)
{
$this->stdOut = Psr7\stream_for($output);
$this->environment = $environment;
list($protocolName, $protocolVersion) = explode('/', $environment['SERVER_PROTOCOL']);
$this->request = new Psr7\Request($environment['REQUEST_METHOD'], $environment['REQUEST_SCHEME'] . '://' . $environment['HTTP_HOST'] . $environment['REQUEST_URI'], $headers, $input, $protocolVersion);
}
示例2: makeHttpRequest
/**
* @param string $uri
* @param string $method
* @param array $data
* @param array $query_params
* @param string $resource
* @param string $action
* @return mixed
* @throws StreamFeedException
*/
public function makeHttpRequest($uri, $method, $data = [], $query_params = [], $resource = '', $action = '')
{
$query_params['api_key'] = $this->api_key;
$client = $this->getHttpClient();
$headers = $this->getHttpRequestHeaders($resource, $action);
$Uri = new Psr7\Uri($this->client->buildRequestUrl($uri));
$Uri = $Uri->withQuery(http_build_query($query_params));
$request = new Request($method, $Uri, $headers, null, $this->guzzleOptions);
if ($method === 'POST' || $method === 'POST') {
$json_data = json_encode($data);
$request = $request->withBody(Psr7\stream_for($json_data));
}
try {
$response = $client->send($request);
} catch (Exception $e) {
if ($e instanceof ClientException) {
throw new StreamFeedException($e->getResponse()->getBody());
} else {
throw $e;
}
}
$body = $response->getBody()->getContents();
$json_body = json_decode($body, true);
return $json_body;
}
示例3: __construct
/**
* @param mixed $value A binary value compatible with Guzzle streams.
*
* @see GuzzleHttp\Stream\Stream::factory
*/
public function __construct($value)
{
if (!is_string($value)) {
$value = Psr7\stream_for($value);
}
$this->value = (string) $value;
}
示例4: testPUT
public function testPUT()
{
$request = new Request('PUT', 'http://local.example', [], Psr7\stream_for('foo=bar&hello=world'));
$curl = $this->curlFormatter->format($request);
$this->assertContains("-d 'foo=bar&hello=world'", $curl);
$this->assertContains('-X PUT', $curl);
}
示例5: testInflatesStreamsWithFilename
public function testInflatesStreamsWithFilename()
{
$content = $this->getGzipStringWithFilename('test');
$a = Psr7\stream_for($content);
$b = new InflateStream($a);
$this->assertEquals('test', (string) $b);
}
示例6: testInflatesStreams
public function testInflatesStreams()
{
$content = gzencode('test');
$a = Psr7\stream_for($content);
$b = new InflateStream($a);
$this->assertEquals('test', (string) $b);
}
示例7: testHasStream
public function testHasStream()
{
$s = Psr7\stream_for('foo');
$e = new SeekException($s, 10);
$this->assertSame($s, $e->getStream());
$this->assertContains('10', $e->getMessage());
}
示例8: valueProvider
public function valueProvider()
{
$fh = fopen('php://temp', 'r+');
fwrite($fh, $this->value);
rewind($fh);
return [[$this->value], [$fh], [Psr7\stream_for($this->value)]];
}
示例9: testHandlesClose
/**
* @expectedException \RuntimeException
* @expectedExceptionMessage Cannot write to a non-writable stream
*/
public function testHandlesClose()
{
$s = Psr7\stream_for('foo');
$wrapped = new NoSeekStream($s);
$wrapped->close();
$wrapped->write('foo');
}
示例10: test_it_builds_http_errors
public function test_it_builds_http_errors()
{
$request = new Request('POST', '/servers');
$response = new Response(400, [], stream_for('Invalid parameters'));
$requestStr = trim($this->builder->str($request));
$responseStr = trim($this->builder->str($response));
$errorMessage = <<<EOT
HTTP Error
~~~~~~~~~~
The remote server returned a "400 Bad Request" error for the following transaction:
Request
~~~~~~~
{$requestStr}
Response
~~~~~~~~
{$responseStr}
Further information
~~~~~~~~~~~~~~~~~~~
Please ensure that your input values are valid and well-formed. Visit http://docs.php-opencloud.com/en/latest/http-codes for more information about debugging HTTP status codes, or file a support issue on https://github.com/php-opencloud/openstack/issues.
EOT;
$e = new BadResponseError($errorMessage);
$e->setRequest($request);
$e->setResponse($response);
$this->assertEquals($e, $this->builder->httpError($request, $response));
}
示例11: formatProvider
public function formatProvider()
{
$request = new Request('PUT', '/', ['x-test' => 'abc'], Psr7\stream_for('foo'));
$response = new Response(200, ['X-Baz' => 'Bar'], Psr7\stream_for('baz'));
$err = new RequestException('Test', $request, $response);
return [['{request}', [$request], Psr7\str($request)], ['{response}', [$request, $response], Psr7\str($response)], ['{request} {response}', [$request, $response], Psr7\str($request) . ' ' . Psr7\str($response)], ['{request} {response}', [$request], Psr7\str($request) . ' '], ['{req_headers}', [$request], "PUT / HTTP/1.1\r\nx-test: abc"], ['{res_headers}', [$request, $response], "HTTP/1.1 200 OK\r\nX-Baz: Bar"], ['{res_headers}', [$request], 'NULL'], ['{req_body}', [$request], 'foo'], ['{res_body}', [$request, $response], 'baz'], ['{res_body}', [$request], 'NULL'], ['{method}', [$request], $request->getMethod()], ['{url}', [$request], $request->getUri()], ['{target}', [$request], $request->getRequestTarget()], ['{req_version}', [$request], $request->getProtocolVersion()], ['{res_version}', [$request, $response], $response->getProtocolVersion()], ['{res_version}', [$request], 'NULL'], ['{host}', [$request], $request->getHeaderLine('Host')], ['{hostname}', [$request, $response], gethostname()], ['{hostname}{hostname}', [$request, $response], gethostname() . gethostname()], ['{code}', [$request, $response], $response->getStatusCode()], ['{code}', [$request], 'NULL'], ['{phrase}', [$request, $response], $response->getReasonPhrase()], ['{phrase}', [$request], 'NULL'], ['{error}', [$request, $response, $err], 'Test'], ['{error}', [$request], 'NULL'], ['{req_header_x-test}', [$request], 'abc'], ['{req_header_x-not}', [$request], ''], ['{res_header_X-Baz}', [$request, $response], 'Bar'], ['{res_header_x-not}', [$request, $response], ''], ['{res_header_X-Baz}', [$request], 'NULL']];
}
示例12: onDeletedResource
public static final function onDeletedResource($response)
{
$data = (array) json_decode($response->getBody(), true);
Arr::forget($data, ['code', 'message']);
$data = json_encode($data);
return $response->withBody(Psr7\stream_for($data));
}
示例13: testProcess
public function testProcess()
{
$client = $this->getClient();
$data = 'foo';
// Test data *only* uploads.
$request = new Request('POST', 'http://www.example.com');
$media = new Google_Http_MediaFileUpload($client, $request, 'image/png', $data, false);
$request = $media->getRequest();
$this->assertEquals($data, (string) $request->getBody());
// Test resumable (meta data) - we want to send the metadata, not the app data.
$request = new Request('POST', 'http://www.example.com');
$reqData = json_encode("hello");
$request = $request->withBody(Psr7\stream_for($reqData));
$media = new Google_Http_MediaFileUpload($client, $request, 'image/png', $data, true);
$request = $media->getRequest();
$this->assertEquals(json_decode($reqData), (string) $request->getBody());
// Test multipart - we are sending encoded meta data and post data
$request = new Request('POST', 'http://www.example.com');
$reqData = json_encode("hello");
$request = $request->withBody(Psr7\stream_for($reqData));
$media = new Google_Http_MediaFileUpload($client, $request, 'image/png', $data, false);
$request = $media->getRequest();
$this->assertContains($reqData, (string) $request->getBody());
$this->assertContains(base64_encode($data), (string) $request->getBody());
}
示例14: __invoke
/**
* Specter JSON Fake Data
*
* The route should return json data of Specter format, and this middleware
* will substitute fake data into it.
*
* @param RequestInterface $request PSR7 request
* @param ResponseInterface $response PSR7 response
* @param callable $next Next middleware
*
* @return ResponseInterface
* @throws InvalidArgumentException
* @throws LogicException
*/
public function __invoke(RequestInterface $request, ResponseInterface $response, callable $next)
{
/**
* We are a post processor, and so we run the $next immediately
*
* @var ResponseInterface $response
*/
$response = $next($request, $response);
// Decode the json returned by the route and prepare it for mock data
// processing.
$fixture = @json_decode($response->getBody()->getContents(), true);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new LogicException('Failed to parse json string. Error: ' . json_last_error_msg());
}
// We will not process files without the Specter trigger, and instead
// return an unchanged response.
if (!array_key_exists($this->specterTrigger, $fixture)) {
return $response;
}
// Process the fixture data, using a seed in case the designer wants
// a repeatable result.
$seed = $request->getHeader('SpecterSeed');
$specter = new Specter(array_shift($seed));
$json = $specter->substituteMockData($fixture);
// Prepare a fresh body stream
$data = json_encode($json);
$stream = Psr7\stream_for($data);
// Return an immutable body in a cloned $request object
return $response->withBody($stream);
}
示例15: createStream
/**
* {@inheritdoc}
*/
public function createStream($body = null) : StreamInterface
{
try {
return stream_for($body);
} catch (Exception $exception) {
throw new DomainException($exception->getMessage(), $exception->getCode(), $exception);
}
}