Skip to content

Commit 029fff4

Browse files
committed
Add http async client discovery
1 parent 9b16b3e commit 029fff4

File tree

5 files changed

+73
-6
lines changed

5 files changed

+73
-6
lines changed

spec/HttpAsyncClientDiscoverySpec.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace spec\Http\Discovery;
4+
5+
use PhpSpec\ObjectBehavior;
6+
7+
class HttpAsyncClientDiscoverySpec extends ObjectBehavior
8+
{
9+
function it_is_initializable()
10+
{
11+
$this->shouldHaveType('Http\Discovery\HttpAsyncClientDiscovery');
12+
}
13+
14+
function it_is_a_class_discovery()
15+
{
16+
$this->shouldHaveType('Http\Discovery\ClassDiscovery');
17+
}
18+
19+
function it_finds_an_http_client()
20+
{
21+
$this->find()->shouldImplement('Http\Client\HttpAsyncClient');
22+
}
23+
}

spec/HttpClientDiscoverySpec.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function it_is_a_class_discovery()
1616
$this->shouldHaveType('Http\Discovery\ClassDiscovery');
1717
}
1818

19-
function it_finds_an_http_adapter()
19+
function it_finds_an_http_client()
2020
{
2121
$this->find()->shouldImplement('Http\Client\HttpClient');
2222
}

spec/bootstrap.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
eval('namespace Http\Client; interface HttpClient {}');
77
}
88

9+
if (!interface_exists('Http\Client\HttpAsyncClient')) {
10+
eval('namespace Http\Client; interface HttpAsyncClient {}');
11+
}
12+
913
if (!class_exists('Http\Adapter\Guzzle6HttpAdapter')) {
10-
eval('namespace Http\Adapter; class Guzzle6HttpAdapter implements \Http\Client\HttpClient {}');
14+
eval('namespace Http\Adapter; class Guzzle6HttpAdapter implements \Http\Client\HttpClient, \Http\Client\HttpAsyncClient {}');
1115
}
1216

src/HttpAsyncClientDiscovery.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace Http\Discovery;
4+
5+
use Http\Client\HttpAsyncClient;
6+
7+
/**
8+
* Finds an HTTP Asynchronous Client
9+
*
10+
* @author Joel Wurtz <[email protected]>
11+
*/
12+
class HttpAsyncClientDiscovery extends ClassDiscovery
13+
{
14+
/**
15+
* @var HttpAsyncClient
16+
*/
17+
protected static $cache;
18+
19+
/**
20+
* @var array
21+
*/
22+
protected static $classes = [
23+
'guzzle6' => [
24+
'class' => 'Http\Adapter\Guzzle6HttpAdapter',
25+
'condition' => 'Http\Adapter\Guzzle6HttpAdapter',
26+
],
27+
];
28+
29+
/**
30+
* Finds an HTTP Async Client
31+
*
32+
* @return HttpAsyncClient
33+
*
34+
* @throws NotFoundException
35+
*/
36+
public static function find()
37+
{
38+
// Override only used for return type declaration
39+
return parent::find();
40+
}
41+
}

src/HttpClientDiscovery.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,16 @@ class HttpClientDiscovery extends ClassDiscovery
3131
protected static $classes = [
3232
'guzzle6' => [
3333
'class' => 'Http\Adapter\Guzzle6HttpAdapter',
34-
'condition' => 'Http\Adapter\Guzzle6HttpAdapter'
35-
34+
'condition' => 'Http\Adapter\Guzzle6HttpAdapter',
3635
],
3736
'guzzle5' => [
3837
'class' => 'Http\Adapter\Guzzle5HttpAdapter',
39-
'condition' => 'Http\Adapter\Guzzle5HttpAdapter'
38+
'condition' => 'Http\Adapter\Guzzle5HttpAdapter',
4039
],
4140
];
4241

4342
/**
44-
* Finds an HTTP Adapter
43+
* Finds an HTTP Client
4544
*
4645
* @return HttpClient
4746
*

0 commit comments

Comments
 (0)