-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from Happyr/no-discovery
Make sure we do not have to use discovery
- Loading branch information
Showing
5 changed files
with
75 additions
and
10 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 |
---|---|---|
|
@@ -7,20 +7,31 @@ | |
use Http\Client\HttpClient; | ||
use Http\Discovery\HttpClientDiscovery; | ||
use Http\Discovery\MessageFactoryDiscovery; | ||
use Http\Message\MessageFactory; | ||
|
||
/** | ||
* A class to create HTTP requests and to send them. | ||
* | ||
* @author Tobias Nyholm <[email protected]> | ||
*/ | ||
class RequestManager implements RequestManagerInterface | ||
{ | ||
/** | ||
* @var \Http\Client\HttpClient | ||
*/ | ||
private $httpClient; | ||
|
||
/** | ||
* @var \Http\Message\MessageFactory | ||
*/ | ||
private $messageFactory; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function sendRequest($method, $uri, array $headers = [], $body = null, $protocolVersion = '1.1') | ||
{ | ||
$request = MessageFactoryDiscovery::find()->createRequest($method, $uri, $headers, $body, $protocolVersion); | ||
$request = $this->getMessageFactory()->createRequest($method, $uri, $headers, $body, $protocolVersion); | ||
|
||
try { | ||
return $this->getHttpClient()->sendRequest($request); | ||
|
@@ -50,4 +61,29 @@ protected function getHttpClient() | |
|
||
return $this->httpClient; | ||
} | ||
|
||
/** | ||
* @param MessageFactory $messageFactory | ||
* | ||
* @return RequestManager | ||
*/ | ||
public function setMessageFactory(MessageFactory $messageFactory) | ||
{ | ||
$this->messageFactory = $messageFactory; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* | ||
* @return \Http\Message\MessageFactory | ||
*/ | ||
private function getMessageFactory() | ||
{ | ||
if ($this->messageFactory === null) { | ||
$this->messageFactory = MessageFactoryDiscovery::find(); | ||
} | ||
|
||
return $this->messageFactory; | ||
} | ||
} |
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