forked from gentlero/bitbucket-api
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
137 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,10 +14,11 @@ | |
use Bitbucket\API\Http\Plugin\HistoryPlugin; | ||
use Http\Client\Common\HttpMethodsClient; | ||
use Http\Client\Common\Plugin; | ||
use Http\Discovery\UriFactoryDiscovery; | ||
use Http\Message\MessageFactory; | ||
use Http\Discovery\Psr17FactoryDiscovery; | ||
use Psr\Http\Message\RequestFactoryInterface; | ||
use Psr\Http\Message\RequestInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\StreamFactoryInterface; | ||
|
||
/** | ||
* @author Alexandru G. <[email protected]> | ||
|
@@ -40,8 +41,10 @@ class Client implements ClientInterface | |
|
||
/** @var HttpPluginClientBuilder */ | ||
private $httpClientBuilder; | ||
/** @var MessageFactory */ | ||
private $messageFactory; | ||
/** @var RequestFactoryInterface */ | ||
private $requestFactory; | ||
/** @var StreamFactoryInterface */ | ||
private $streamFactory; | ||
/** @var HistoryPlugin */ | ||
private $responseHistory; | ||
|
||
|
@@ -55,7 +58,7 @@ public function __construct(array $options = array(), HttpPluginClientBuilder $h | |
$this->httpClientBuilder = $httpClientBuilder ?: new HttpPluginClientBuilder(); | ||
|
||
$this->httpClientBuilder->addPlugin( | ||
new Plugin\AddHostPlugin(UriFactoryDiscovery::find()->createUri($this->options['base_url'])) | ||
new Plugin\AddHostPlugin(Psr17FactoryDiscovery::findUriFactory()->createUri($this->options['base_url'])) | ||
); | ||
$this->httpClientBuilder->addPlugin(new Plugin\RedirectPlugin()); | ||
$this->httpClientBuilder->addPlugin(new Plugin\HeaderDefaultsPlugin([ | ||
|
@@ -65,7 +68,8 @@ public function __construct(array $options = array(), HttpPluginClientBuilder $h | |
|
||
$this->setApiVersion($this->options['api_version']); | ||
|
||
$this->messageFactory = $this->httpClientBuilder->getMessageFactory(); | ||
$this->requestFactory = $this->httpClientBuilder->getRequestFactory(); | ||
$this->streamFactory = Psr17FactoryDiscovery::findStreamFactory(); | ||
} | ||
|
||
/** | ||
|
@@ -124,7 +128,7 @@ public function request($endpoint, $params = array(), $method = 'GET', array $he | |
} | ||
} | ||
|
||
$body = null; | ||
$body = ''; | ||
if (is_string($paramsString) && $paramsString !== null) { | ||
$body = $paramsString; | ||
} | ||
|
@@ -140,7 +144,13 @@ public function request($endpoint, $params = array(), $method = 'GET', array $he | |
$endpoint .= (strpos($endpoint, '?') === false ? '?' : '&').'format='.$this->getResponseFormat(); | ||
} | ||
|
||
$request = $this->messageFactory->createRequest($method, $endpoint, $headers, $body); | ||
$request = $this->requestFactory | ||
->createRequest($method, $endpoint) | ||
->withBody($this->streamFactory->createStream($body)); | ||
|
||
foreach ($headers as $name => $value) { | ||
$request = $request->withHeader($name, $value); | ||
} | ||
|
||
return $this->getClient()->sendRequest($request); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,9 +10,9 @@ | |
namespace Bitbucket\API\Http\Response; | ||
|
||
use Bitbucket\API\Http\HttpPluginClientBuilder; | ||
use Http\Discovery\MessageFactoryDiscovery; | ||
use Http\Message\MessageFactory; | ||
use Http\Discovery\Psr17FactoryDiscovery; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\StreamFactoryInterface; | ||
|
||
/** | ||
* @author Alexandru Guzinschi <[email protected]> | ||
|
@@ -21,22 +21,24 @@ class Pager implements PagerInterface | |
{ | ||
/** @var HttpPluginClientBuilder */ | ||
private $httpPluginClientBuilder; | ||
/** @var MessageFactory */ | ||
private $messageFactory; | ||
/** @var StreamFactoryInterface */ | ||
private $streamFactory; | ||
/** @var ResponseInterface */ | ||
private $response; | ||
|
||
/** | ||
* @param HttpPluginClientBuilder $httpPluginClientBuilder | ||
* @param ResponseInterface $response | ||
* @param MessageFactory $messageFactory | ||
* @param object|null $messageFactory This argument is deprecated and will be removed in 3.0.0 | ||
* @param StreamFactoryInterface|null $streamFactory | ||
* | ||
* @throws \UnexpectedValueException | ||
*/ | ||
public function __construct( | ||
HttpPluginClientBuilder $httpPluginClientBuilder, | ||
ResponseInterface $response, | ||
MessageFactory $messageFactory = null | ||
$messageFactory = null, | ||
StreamFactoryInterface $streamFactory = null | ||
) { | ||
/** @var ResponseInterface $response */ | ||
if ($response->getStatusCode() >= 400) { | ||
|
@@ -45,7 +47,9 @@ public function __construct( | |
|
||
$this->httpPluginClientBuilder = $httpPluginClientBuilder; | ||
$this->response = $response; | ||
$this->messageFactory = $messageFactory ? : MessageFactoryDiscovery::find(); | ||
$this->streamFactory = $streamFactory ?: Psr17FactoryDiscovery::findStreamFactory(); | ||
|
||
unset($messageFactory); | ||
} | ||
|
||
/** | ||
|
@@ -117,13 +121,9 @@ public function fetchAll() | |
} | ||
|
||
$content['values'] = $values; | ||
$this->response = $this->messageFactory->createResponse( | ||
$this->response->getStatusCode(), | ||
$this->response->getReasonPhrase(), | ||
$this->response->getHeaders(), | ||
json_encode($content), | ||
$this->response->getProtocolVersion() | ||
); | ||
|
||
$this->response = $this->response | ||
->withBody($this->streamFactory->createStream(json_encode($content))); | ||
|
||
return $this->response; | ||
} | ||
|
Oops, something went wrong.