| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* This file is part of the league/oauth2-client library |
| 5 |
* |
| 6 |
* For the full copyright and license information, please view the LICENSE |
| 7 |
* file that was distributed with this source code. |
| 8 |
* |
| 9 |
* @copyright Copyright (c) Alex Bilbie <hello@alexbilbie.com> |
| 10 |
* @license http://opensource.org/licenses/MIT MIT |
| 11 |
* @link http://thephpleague.com/oauth2-client/ Documentation |
| 12 |
* @link https://packagist.org/packages/league/oauth2-client Packagist |
| 13 |
* @link https://github.com/thephpleague/oauth2-client GitHub |
| 14 |
*/ |
| 15 |
namespace YoastSEO_Vendor\League\OAuth2\Client\Tool; |
| 16 |
|
| 17 |
use YoastSEO_Vendor\GuzzleHttp\Psr7\Request; |
| 18 |
/** |
| 19 |
* Used to produce PSR-7 Request instances. |
| 20 |
* |
| 21 |
* @link https://github.com/guzzle/guzzle/pull/1101 |
| 22 |
*/ |
| 23 |
class RequestFactory |
| 24 |
{ |
| 25 |
/** |
| 26 |
* Creates a PSR-7 Request instance. |
| 27 |
* |
| 28 |
* @param null|string $method HTTP method for the request. |
| 29 |
* @param null|string $uri URI for the request. |
| 30 |
* @param array $headers Headers for the message. |
| 31 |
* @param string|resource|StreamInterface $body Message body. |
| 32 |
* @param string $version HTTP protocol version. |
| 33 |
* |
| 34 |
* @return Request |
| 35 |
*/ |
| 36 |
public function getRequest($method, $uri, array $headers = [], $body = null, $version = '1.1') |
| 37 |
{ |
| 38 |
return new \YoastSEO_Vendor\GuzzleHttp\Psr7\Request($method, $uri, $headers, $body, $version); |
| 39 |
} |
| 40 |
/** |
| 41 |
* Parses simplified options. |
| 42 |
* |
| 43 |
* @param array $options Simplified options. |
| 44 |
* |
| 45 |
* @return array Extended options for use with getRequest. |
| 46 |
*/ |
| 47 |
protected function parseOptions(array $options) |
| 48 |
{ |
| 49 |
// Should match default values for getRequest |
| 50 |
$defaults = ['headers' => [], 'body' => null, 'version' => '1.1']; |
| 51 |
return \array_merge($defaults, $options); |
| 52 |
} |
| 53 |
/** |
| 54 |
* Creates a request using a simplified array of options. |
| 55 |
* |
| 56 |
* @param null|string $method |
| 57 |
* @param null|string $uri |
| 58 |
* @param array $options |
| 59 |
* |
| 60 |
* @return Request |
| 61 |
*/ |
| 62 |
public function getRequestWithOptions($method, $uri, array $options = []) |
| 63 |
{ |
| 64 |
$options = $this->parseOptions($options); |
| 65 |
return $this->getRequest($method, $uri, $options['headers'], $options['body'], $options['version']); |
| 66 |
} |
| 67 |
} |
| 68 |
|