Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for PSR18 #2122

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -13,7 +13,8 @@
}
],
"require": {
"php": ">=5.5",
"php": "^7.0",
"psr/http-client": "^0.1",
"guzzlehttp/psr7": "^1.4",
"guzzlehttp/promises": "^1.0"
},
Expand Down
14 changes: 12 additions & 2 deletions src/Client.php
Expand Up @@ -2,6 +2,7 @@
namespace GuzzleHttp;

use GuzzleHttp\Cookie\CookieJar;
use GuzzleHttp\Exception\InvalidRequestException;
use GuzzleHttp\Promise;
use GuzzleHttp\Psr7;
use Psr\Http\Message\UriInterface;
Expand Down Expand Up @@ -106,6 +107,15 @@ public function send(RequestInterface $request, array $options = [])
return $this->sendAsync($request, $options)->wait();
}

public function sendRequest(RequestInterface $request): ResponseInterface
{
$options[RequestOptions::SYNCHRONOUS] = true;
$options[RequestOptions::ALLOW_REDIRECTS] = false;
$options[RequestOptions::HTTP_ERRORS] = false;

return $this->sendAsync($request, $options)->wait();
}

public function requestAsync($method, $uri = '', array $options = [])
{
$options = $this->prepareDefaults($options);
Expand Down Expand Up @@ -371,7 +381,7 @@ private function applyOptions(RequestInterface $request, array &$options)
$value = http_build_query($value, null, '&', PHP_QUERY_RFC3986);
}
if (!is_string($value)) {
throw new \InvalidArgumentException('query must be a string or array');
throw new InvalidRequestException($request, 'query must be a string or array');
}
$modify['query'] = $value;
unset($options['query']);
Expand All @@ -381,7 +391,7 @@ private function applyOptions(RequestInterface $request, array &$options)
if (isset($options['sink'])) {
// TODO: Add more sink validation?
if (is_bool($options['sink'])) {
throw new \InvalidArgumentException('sink must not be a boolean');
throw new InvalidRequestException($request, 'sink must not be a boolean');
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/Exception/ConnectException.php
@@ -1,14 +1,15 @@
<?php
namespace GuzzleHttp\Exception;

use Psr\Http\Client\Exception\NetworkException;
use Psr\Http\Message\RequestInterface;

/**
* Exception thrown when a connection cannot be established.
*
* Note that no response is present for a ConnectException
*/
class ConnectException extends RequestException
class ConnectException extends RequestException implements NetworkException
{
public function __construct(
$message,
Expand Down
23 changes: 23 additions & 0 deletions src/Exception/InvalidRequestException.php
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace GuzzleHttp\Exception;

use Psr\Http\Message\RequestInterface;

class InvalidRequestException extends \InvalidArgumentException implements \Psr\Http\Client\Exception\RequestException, GuzzleException
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you could have a look on this #2163. If we could merge this PR you can have this exception extend that one.

{
private $request;
public function __construct(RequestInterface $request, $message)
{
$this->request = $request;
parent::__construct($message);
}


public function getRequest(): RequestInterface
{
return $this->request;
}
}
2 changes: 1 addition & 1 deletion src/Exception/RequestException.php
Expand Up @@ -175,7 +175,7 @@ private static function obfuscateUri($uri)
*
* @return RequestInterface
*/
public function getRequest()
public function getRequest(): RequestInterface
{
return $this->request;
}
Expand Down