当前位置: 首页>>代码示例>>PHP>>正文


PHP RequestInterface::withMethod方法代码示例

本文整理汇总了PHP中Psr\Http\Message\RequestInterface::withMethod方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestInterface::withMethod方法的具体用法?PHP RequestInterface::withMethod怎么用?PHP RequestInterface::withMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Psr\Http\Message\RequestInterface的用法示例。


在下文中一共展示了RequestInterface::withMethod方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testMissingToken

 public function testMissingToken()
 {
     $storage = [];
     // <-- Missing token name and value
     $request = $this->request->withMethod('POST')->withParsedBody(['csrf_name' => 'csrf_123', 'csrf_value' => 'xyz']);
     $response = $this->response;
     $next = function ($req, $res) {
         return $res;
     };
     $mw = new Guard('csrf', $storage);
     $newResponse = $mw($request, $response, $next);
     $this->assertEquals(400, $newResponse->getStatusCode());
 }
开发者ID:biomassives,项目名称:Slim-Csrf,代码行数:13,代码来源:CsrfTest.php

示例2: testWithMethod

 public function testWithMethod()
 {
     $this->assertNotSame($this->request, $this->request->withMethod('post'));
     $this->assertEquals('POST', $this->request->withMethod('post')->getMethod());
     try {
         $this->request->withMethod([]);
         $this->fail();
     } catch (InvalidArgumentException $e) {
         $this->assertEquals('Unsupported HTTP method. It must be a string.', $e->getMessage());
     }
     try {
         $this->request->withMethod('UNKNOWN');
         $this->fail();
     } catch (InvalidArgumentException $e) {
         $this->assertEquals('Unsupported HTTP method. "UNKNOWN" provided.', $e->getMessage());
     }
 }
开发者ID:Golpha,项目名称:Http,代码行数:17,代码来源:RequestTestTrait.php

示例3: convertGetToPost

 /**
  * Converts default GET request to a POST request
  *
  * Avoiding length restriction in query
  *
  * @param RequestInterface $r GET request to be converted
  * @return RequestInterface $req converted POST request
  */
 public static function convertGetToPost(RequestInterface $r)
 {
     if ($r->getMethod() === 'POST') {
         return $r;
     }
     $query = $r->getUri()->getQuery();
     $req = $r->withMethod('POST')->withBody(Psr7\stream_for($query))->withHeader('Content-Length', strlen($query))->withHeader('Content-Type', 'application/x-www-form-urlencoded')->withUri($r->getUri()->withQuery(''));
     return $req;
 }
开发者ID:Afrozaar,项目名称:wp-api-v2-afrozaar-extras,代码行数:17,代码来源:CloudSearchDomainClient.php

示例4: convertPostToGet

 /**
  * Converts a POST request to a GET request by moving POST fields into the
  * query string.
  *
  * Useful for pre-signing query protocol requests.
  *
  * @param RequestInterface $request Request to clone
  *
  * @return RequestInterface
  * @throws \InvalidArgumentException if the method is not POST
  */
 public static function convertPostToGet(RequestInterface $request)
 {
     if ($request->getMethod() !== 'POST') {
         throw new \InvalidArgumentException('Expected a POST request but ' . 'received a ' . $request->getMethod() . ' request.');
     }
     $sr = $request->withMethod('GET')->withBody(Psr7\stream_for(''))->withoutHeader('Content-Type')->withoutHeader('Content-Length');
     // Move POST fields to the query if they are present
     if ($request->getHeaderLine('Content-Type') === 'application/x-www-form-urlencoded') {
         $body = (string) $request->getBody();
         $sr = $sr->withUri($sr->getUri()->withQuery($body));
     }
     return $sr;
 }
开发者ID:Afrozaar,项目名称:wp-api-v2-afrozaar-extras,代码行数:24,代码来源:SignatureV4.php

示例5: testExternalStorageOfAnArrayPersists

 public function testExternalStorageOfAnArrayPersists()
 {
     $storage = [];
     $request = $this->request->withMethod('POST')->withParsedBody(['csrf_name' => 'csrf_123', 'csrf_value' => 'xyz']);
     $response = $this->response;
     $next = function ($req, $res) {
         return $res;
     };
     $mw = new Guard('csrf', $storage);
     $this->assertEquals(0, count($storage));
     $newResponse = $mw($request, $response, $next);
     $this->assertEquals(1, count($storage));
 }
开发者ID:juliangut,项目名称:Slim-Csrf,代码行数:13,代码来源:CsrfTest.php

示例6: getRequest

 /**
  * @return \Psr\Http\Message\RequestInterface
  */
 public function getRequest()
 {
     $request = $this->request->withMethod($this->method);
     $uri = $request->getUri()->withScheme($this->scheme)->withHost($this->host)->withPath($this->path)->withQuery($this->getQueryString());
     $request = $request->withUri($uri);
     $request = $request->withProtocolVersion($this->protocolVersion);
     $request = $request->withHeader("Accept", "application/vnd.api+json");
     $request = $request->withHeader("Content-Type", "application/vnd.api+json");
     foreach ($this->headers as $name => $value) {
         $request = $request->withHeader($name, $value);
     }
     $request->getBody()->write($this->body);
     return $request;
 }
开发者ID:woohoolabs,项目名称:yang,代码行数:17,代码来源:JsonApiRequestBuilder.php

示例7: withMethod

 /**
  * @param string $method
  * @return RequestInterface
  */
 public function withMethod($method)
 {
     $this->request = $this->request->withMethod($method);
     return $this;
 }
开发者ID:bweston92,项目名称:expressive-async,代码行数:9,代码来源:ServerRequest.php

示例8: withMethod

 public function withMethod($method)
 {
     $new = clone $this;
     $new->request = $this->request->withMethod($method);
     return $new;
 }
开发者ID:deepfreeze,项目名称:zend-diactoros,代码行数:6,代码来源:Request.php

示例9: put

 /**
  * {@inheritdoc}
  */
 public function put(RequestInterface $request)
 {
     return $this->request($request->withMethod('PUT'));
 }
开发者ID:softrog,项目名称:gloo-client,代码行数:7,代码来源:CurlHandler.php


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