Skip to content

Commit

Permalink
Add preparations for implementing PSR-18
Browse files Browse the repository at this point in the history
  • Loading branch information
Art4 committed Dec 10, 2018
1 parent 32cd677 commit 8ffb5a7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Added

- make preparations for implementing PSR-17 and PSR-18
- new method `YoutubeDownloader\Http\CurlClient::createFullRequest()` to create a PSR-7 request instance with headers and body

### Fixed
Expand All @@ -19,6 +20,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Deprecated

- `YoutubeDownloader\Http\CurlClient::createRequest()` will be removed in 0.10, use `YoutubeDownloader\Http\CurlClient::createFullRequest()` instead
- `YoutubeDownloader\Http\Client::createRequest()` will be renamed to `YoutubeDownloader\Http\Client::createFullRequest()` in 0.10

## [0.8] - 2018-12-06

Expand Down
3 changes: 3 additions & 0 deletions src/Http/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ interface Client
/**
* Factory for a new Request
*
* @deprecated since version 0.9, to be renamed in 0.10.
*
* @param string $method HTTP method
* @param string $target The target url for this request
* @param array $headers Request headers
Expand All @@ -39,6 +41,7 @@ interface Client
*
* @return Psr\Http\Message\RequestInterface
*/
// public function createFullRequest($method, $target, array $headers = [], $body = null, $version = '1.1');
public function createRequest($method, $target, array $headers = [], $body = null, $version = '1.1');

/**
Expand Down
19 changes: 18 additions & 1 deletion src/Http/CurlClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

namespace YoutubeDownloader\Http;

// use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;
Expand All @@ -28,7 +29,7 @@
/**
* A curl http client instance
*/
class CurlClient implements Client /* , RequestFactoryInterface */
class CurlClient implements Client /* , ClientInterface, RequestFactoryInterface */
{
/**
* Factory for a new Request
Expand Down Expand Up @@ -103,6 +104,22 @@ private function createRequestPsr17(string $method, $uri) {
* @return Response
*/
public function send(RequestInterface $request, array $options = [])
{
$this->sendRequest($request, $options);
}

/**
* Sends a PSR-7 request and returns a PSR-7 response.
*
* @TODO make this public to implement PSR-18 HTTP Client
*
* @param RequestInterface $request
*
* @return ResponseInterface
*
* @throws \Psr\Http\Client\ClientExceptionInterface If an error happens while processing the request.
*/
private function sendRequest(RequestInterface $request)
{
$curl_options = $this->createCurlOptions($request, $options);

Expand Down

0 comments on commit 8ffb5a7

Please sign in to comment.