Skip to content

Commit 81784c2

Browse files
committed
Merge pull request #16 from joelwurtz/feature/async
Add http async client discovery
2 parents 1812dd9 + 029fff4 commit 81784c2

File tree

4 files changed

+71
-4
lines changed

4 files changed

+71
-4
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/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: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,11 @@ 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

0 commit comments

Comments
 (0)