• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Psr7\stream_for函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中GuzzleHttp\Psr7\stream_for函数的典型用法代码示例。如果您正苦于以下问题:PHP stream_for函数的具体用法?PHP stream_for怎么用?PHP stream_for使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了stream_for函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
 }
开发者ID:gamringer,项目名称:php-rest,代码行数:7,代码来源:HTTPEnvironment.php


示例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;
 }
开发者ID:pranipat,项目名称:stream-php,代码行数:35,代码来源:Feed.php


示例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;
 }
开发者ID:Air-Craft,项目名称:air-craft-www,代码行数:12,代码来源:BinaryValue.php


示例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);
 }
开发者ID:namshi,项目名称:cuzzle,代码行数:7,代码来源:RequestTest.php


示例5: testInflatesStreamsWithFilename

 public function testInflatesStreamsWithFilename()
 {
     $content = $this->getGzipStringWithFilename('test');
     $a = Psr7\stream_for($content);
     $b = new InflateStream($a);
     $this->assertEquals('test', (string) $b);
 }
开发者ID:Roc4rdho,项目名称:app,代码行数:7,代码来源:InflateStreamTest.php


示例6: testInflatesStreams

 public function testInflatesStreams()
 {
     $content = gzencode('test');
     $a = Psr7\stream_for($content);
     $b = new InflateStream($a);
     $this->assertEquals('test', (string) $b);
 }
开发者ID:shomimn,项目名称:builder,代码行数:7,代码来源:InflateStreamTest.php


示例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());
 }
开发者ID:nystudio107,项目名称:instantanalytics,代码行数:7,代码来源:SeekExceptionTest.php


示例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)]];
 }
开发者ID:GoogleCloudPlatform,项目名称:gcloud-php,代码行数:7,代码来源:BytesTest.php


示例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');
 }
开发者ID:hilmysyarif,项目名称:sic,代码行数:11,代码来源:NoSeekStreamTest.php


示例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));
    }
开发者ID:php-opencloud,项目名称:openstack,代码行数:28,代码来源:BuilderTest.php


示例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']];
 }
开发者ID:nystudio107,项目名称:instantanalytics,代码行数:7,代码来源:MessageFormatterTest.php


示例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));
 }
开发者ID:loduis,项目名称:alegra-php,代码行数:7,代码来源:Resource.php


示例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());
 }
开发者ID:andytan2624,项目名称:andytan.net,代码行数:25,代码来源:MediaFileUploadTest.php


示例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);
 }
开发者ID:helpscout,项目名称:specter,代码行数:44,代码来源:SpecterPsr7.php


示例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);
     }
 }
开发者ID:novuso,项目名称:common-bundle,代码行数:11,代码来源:GuzzleStreamFactory.php


示例16: __doRequest

 public function __doRequest($request, array $headers = array())
 {
     $this->headers = $headers;
     $this->emit('before.request', array(&$request, &$headers));
     $xml = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:enc="http://www.w3.org/2003/05/soap-encoding">' . '<soap:Body xmlns:rpc="http://www.w3.org/2003/05/soap-rpc">' . '<TestResponse>' . '<foo>foo</foo>' . '<bar>bar</bar>' . '</TestResponse>' . '</soap:Body>' . '</soap:Envelope>';
     $stream = Psr7\stream_for($xml);
     return new HttpResponse(200, array(), $stream);
 }
开发者ID:nucleus-be,项目名称:zimbra-api,代码行数:8,代码来源:LocalClientHttp.php


示例17: saveToFile

 public function saveToFile($path)
 {
     $resource = fopen($path, 'w');
     /* @var $fileStream \GuzzleHttp\Psr7\Stream */
     $fileStream = Psr7\stream_for($resource);
     $fileStream->write($this->getByte());
     fclose($resource);
 }
开发者ID:gong023,项目名称:pixiv,代码行数:8,代码来源:Image.php


示例18: authenticateRequest

 private function authenticateRequest(HttpRequest $request)
 {
     $body = JsonRpc\json_decode((string) $request->getBody()->getContents(), true);
     $body['auth'] = $this->auth_token;
     $json_body = JsonRpc\json_encode($body);
     $request = $request->withBody(Psr7\stream_for($json_body));
     return $request;
 }
开发者ID:kamermans,项目名称:zabbix-client,代码行数:8,代码来源:ZabbixClient.php


示例19: testShouldReturnTokenInfo

 public function testShouldReturnTokenInfo()
 {
     $wantedTokens = ['access_token' => '1/abdef1234567890', 'expires_in' => '57', 'token_type' => 'Bearer'];
     $jsonTokens = json_encode($wantedTokens);
     $httpHandler = getHandler([buildResponse(200, [GCECredentials::FLAVOR_HEADER => 'Google']), buildResponse(200, [], Psr7\stream_for($jsonTokens))]);
     $g = new GCECredentials();
     $this->assertEquals($wantedTokens, $g->fetchAuthToken($httpHandler));
 }
开发者ID:tsuyog,项目名称:gmailcontactextractor,代码行数:8,代码来源:GCECredentialsTest.php


示例20: testReverseOk

 /**
  * Test reverse, ok
  */
 public function testReverseOk()
 {
     $client = new NominatimClient();
     $mock = new MockHandler([new Response(200, [], Psr7\stream_for('ABC'))]);
     $client->getGuzzleClient()->getConfig('handler')->setHandler($mock);
     $response = $client->reverse(0.01, 0.01);
     $this->assertEquals('ABC', $response->getBody()->getContents());
 }
开发者ID:mauro-moreno,项目名称:openstreetmap-api-client,代码行数:11,代码来源:NominatimClientTest.php



注:本文中的GuzzleHttp\Psr7\stream_for函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Psr7\uri_for函数代码示例发布时间:2022-05-23
下一篇:
PHP Psr7\parse_query函数代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap