Skip to content

Commit f3a843b

Browse files
committed
Deprecate plugins
1 parent 7585d59 commit f3a843b

24 files changed

+70
-847
lines changed

spec/AddHostPluginSpec.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@ function let(UriInterface $uri)
2222
function it_is_initializable(UriInterface $uri)
2323
{
2424
$uri->getHost()->shouldBeCalled()->willReturn('example.com');
25-
$this->beConstructedWith($uri);
25+
2626
$this->shouldHaveType('Http\Client\Plugin\AddHostPlugin');
2727
}
2828

2929
function it_is_a_plugin(UriInterface $uri)
3030
{
3131
$uri->getHost()->shouldBeCalled()->willReturn('example.com');
32-
$this->beConstructedWith($uri);
3332

3433
$this->shouldImplement('Http\Client\Plugin\Plugin');
3534
}

spec/ContentLengthPluginSpec.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,20 @@
33
namespace spec\Http\Client\Plugin;
44

55
use PhpSpec\Exception\Example\SkippingException;
6-
use PhpSpec\ObjectBehavior;
7-
use Prophecy\Argument;
86
use Psr\Http\Message\RequestInterface;
97
use Psr\Http\Message\StreamInterface;
8+
use PhpSpec\ObjectBehavior;
9+
use Prophecy\Argument;
1010

1111
class ContentLengthPluginSpec extends ObjectBehavior
1212
{
1313
function it_is_initializable()
1414
{
1515
$this->shouldHaveType('Http\Client\Plugin\ContentLengthPlugin');
16+
}
17+
18+
function it_is_a_plugin()
19+
{
1620
$this->shouldImplement('Http\Client\Plugin\Plugin');
1721
}
1822

spec/HeaderAppendPluginSpec.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
namespace spec\Http\Client\Plugin;
44

55
use PhpSpec\Exception\Example\SkippingException;
6-
use PhpSpec\ObjectBehavior;
7-
use Prophecy\Argument;
86
use Psr\Http\Message\RequestInterface;
97
use Psr\Http\Message\StreamInterface;
8+
use PhpSpec\ObjectBehavior;
9+
use Prophecy\Argument;
1010

1111
class HeaderAppendPluginSpec extends ObjectBehavior
1212
{

spec/HeaderDefaultsPluginSpec.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
namespace spec\Http\Client\Plugin;
44

55
use PhpSpec\Exception\Example\SkippingException;
6-
use PhpSpec\ObjectBehavior;
7-
use Prophecy\Argument;
86
use Psr\Http\Message\RequestInterface;
97
use Psr\Http\Message\StreamInterface;
8+
use PhpSpec\ObjectBehavior;
9+
use Prophecy\Argument;
1010

1111
class HeaderDefaultsPluginSpec extends ObjectBehavior
1212
{

spec/HeaderRemovePluginSpec.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
namespace spec\Http\Client\Plugin;
44

55
use PhpSpec\Exception\Example\SkippingException;
6-
use PhpSpec\ObjectBehavior;
7-
use Prophecy\Argument;
86
use Psr\Http\Message\RequestInterface;
97
use Psr\Http\Message\StreamInterface;
8+
use PhpSpec\ObjectBehavior;
9+
use Prophecy\Argument;
1010

1111
class HeaderRemovePluginSpec extends ObjectBehavior
1212
{

spec/HeaderSetPluginSpec.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
namespace spec\Http\Client\Plugin;
44

55
use PhpSpec\Exception\Example\SkippingException;
6-
use PhpSpec\ObjectBehavior;
7-
use Prophecy\Argument;
86
use Psr\Http\Message\RequestInterface;
97
use Psr\Http\Message\StreamInterface;
8+
use PhpSpec\ObjectBehavior;
9+
use Prophecy\Argument;
1010

1111
class HeaderSetPluginSpec extends ObjectBehavior
1212
{

src/AddHostPlugin.php

Lines changed: 3 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2,72 +2,11 @@
22

33
namespace Http\Client\Plugin;
44

5-
use Psr\Http\Message\RequestInterface;
6-
use Psr\Http\Message\UriInterface;
7-
use Symfony\Component\OptionsResolver\OptionsResolver;
8-
95
/**
10-
* Add schema and host to a request. Can be set to overwrite the schema and host if desired.
11-
*
126
* @author Tobias Nyholm <[email protected]>
7+
*
8+
* @deprecated since version 1.1, to be removed in 2.0. Use {@link \Http\Client\Common\Plugin\AddHostPlugin} instead.
139
*/
14-
class AddHostPlugin implements Plugin
10+
class AddHostPlugin extends \Http\Client\Common\Plugin\AddHostPlugin implements Plugin
1511
{
16-
/**
17-
* @var UriInterface
18-
*/
19-
private $host;
20-
21-
/**
22-
* @var bool
23-
*/
24-
private $replace;
25-
26-
/**
27-
* @param UriInterface $host
28-
* @param array $config {
29-
*
30-
* @var bool $replace True will replace all hosts, false will only add host when none is specified.
31-
* }
32-
*/
33-
public function __construct(UriInterface $host, array $config = [])
34-
{
35-
if ($host->getHost() === '') {
36-
throw new \LogicException('Host can not be empty');
37-
}
38-
39-
$this->host = $host;
40-
41-
$resolver = new OptionsResolver();
42-
$this->configureOptions($resolver);
43-
$options = $resolver->resolve($config);
44-
45-
$this->replace = $options['replace'];
46-
}
47-
48-
/**
49-
* {@inheritdoc}
50-
*/
51-
public function handleRequest(RequestInterface $request, callable $next, callable $first)
52-
{
53-
if ($this->replace || $request->getUri()->getHost() === '') {
54-
$uri = $request->getUri()->withHost($this->host->getHost());
55-
$uri = $uri->withScheme($this->host->getScheme());
56-
57-
$request = $request->withUri($uri);
58-
}
59-
60-
return $next($request);
61-
}
62-
63-
/**
64-
* @param OptionsResolver $resolver
65-
*/
66-
private function configureOptions(OptionsResolver $resolver)
67-
{
68-
$resolver->setDefaults([
69-
'replace' => false,
70-
]);
71-
$resolver->setAllowedTypes('replace', 'bool');
72-
}
7312
}

src/AuthenticationPlugin.php

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,12 @@
33
namespace Http\Client\Plugin;
44

55
use Http\Message\Authentication;
6-
use Psr\Http\Message\RequestInterface;
76

87
/**
9-
* Send an authenticated request.
10-
*
118
* @author Joel Wurtz <[email protected]>
9+
*
10+
* @deprecated since version 1.1, to be removed in 2.0. Use {@link \Http\Client\Common\Plugin\AuthenticationPlugin} instead.
1211
*/
13-
class AuthenticationPlugin implements Plugin
12+
class AuthenticationPlugin extends \Http\Client\Common\Plugin\AuthenticationPlugin implements Plugin
1413
{
15-
/**
16-
* @var Authentication An authentication system
17-
*/
18-
private $authentication;
19-
20-
/**
21-
* @param Authentication $authentication
22-
*/
23-
public function __construct(Authentication $authentication)
24-
{
25-
$this->authentication = $authentication;
26-
}
27-
28-
/**
29-
* {@inheritdoc}
30-
*/
31-
public function handleRequest(RequestInterface $request, callable $next, callable $first)
32-
{
33-
$request = $this->authentication->authenticate($request);
34-
35-
return $next($request);
36-
}
3714
}

src/ContentLengthPlugin.php

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,11 @@
22

33
namespace Http\Client\Plugin;
44

5-
use Http\Message\Encoding\ChunkStream;
6-
use Psr\Http\Message\RequestInterface;
7-
85
/**
9-
* Allow to set the correct content length header on the request or to transfer it as a chunk if not possible.
10-
*
116
* @author Joel Wurtz <[email protected]>
7+
*
8+
* @deprecated since version 1.1, to be removed in 2.0. Use {@link \Http\Client\Common\Plugin\ContentLengthPlugin} instead.
129
*/
13-
class ContentLengthPlugin implements Plugin
10+
class ContentLengthPlugin extends \Http\Client\Common\Plugin\ContentLengthPlugin implements Plugin
1411
{
15-
/**
16-
* {@inheritdoc}
17-
*/
18-
public function handleRequest(RequestInterface $request, callable $next, callable $first)
19-
{
20-
if (!$request->hasHeader('Content-Length')) {
21-
$stream = $request->getBody();
22-
23-
// Cannot determine the size so we use a chunk stream
24-
if (null === $stream->getSize()) {
25-
$stream = new ChunkStream($stream);
26-
$request = $request->withBody($stream);
27-
$request = $request->withAddedHeader('Transfer-Encoding', 'chunked');
28-
} else {
29-
$request = $request->withHeader('Content-Length', $stream->getSize());
30-
}
31-
}
32-
33-
return $next($request);
34-
}
3512
}

0 commit comments

Comments
 (0)