Skip to content

Commit ab089f4

Browse files
committed
Support React v0.4 (while preserving BC)
Fixes #4
1 parent d26be0e commit ab089f4

File tree

5 files changed

+25
-16
lines changed

5 files changed

+25
-16
lines changed

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
},
1616
"require": {
1717
"php": ">=5.3",
18-
"react/socket-client": "0.3.*",
19-
"react/event-loop": "0.3.*",
20-
"react/promise": "~1.0"
18+
"react/socket-client": "0.3.*|0.4.*",
19+
"react/event-loop": "0.3.*|0.4.*",
20+
"react/promise": "~1.0|~2.0"
2121
}
2222
}

src/ConnectionManagerReject.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
namespace ConnectionManager\Extra;
44

55
use React\SocketClient\ConnectorInterface;
6-
use React\Promise\When;
6+
use React\Promise\Deferred;
77
use \Exception;
88

99
// a simple connection manager that rejects every single connection attempt
1010
class ConnectionManagerReject implements ConnectorInterface
1111
{
1212
public function create($host, $port)
1313
{
14-
return When::reject(new Exception('Connection rejected'));
14+
$deferred = new Deferred();
15+
$deferred->reject(new Exception('Connection rejected'));
16+
return $deferred->promise();
1517
}
1618
}

src/Multiple/ConnectionManagerConsecutive.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@
33
namespace ConnectionManager\Extra\Multiple;
44

55
use React\SocketClient\ConnectorInterface;
6-
use React\Promise\When;
6+
use React\Promise\Deferred;
77
use \UnderflowException;
88

99
class ConnectionManagerConsecutive implements ConnectorInterface
1010
{
1111
protected $managers = array();
12-
12+
1313
public function addConnectionManager(ConnectorInterface $connectionManager)
1414
{
1515
$this->managers []= $connectionManager;
1616
}
17-
17+
1818
public function create($host, $port)
1919
{
20-
return $this->tryConnection($this->managers, $host, $port);
20+
return $this->tryConnection($this->managers, $host, $port);
2121
}
22-
22+
2323
/**
24-
*
24+
*
2525
* @param ConnectorInterface[] $managers
2626
* @param string $host
2727
* @param int $port
@@ -31,7 +31,9 @@ public function create($host, $port)
3131
public function tryConnection(array $managers, $host, $port)
3232
{
3333
if (!$managers) {
34-
return When::reject(new UnderflowException('No more managers to try to connect through'));
34+
$deferred = new Deferred();
35+
$deferred->reject(new UnderflowException('No more managers to try to connect through'));
36+
return $deferred->promise();
3537
}
3638
$manager = array_shift($managers);
3739
$that = $this;

src/Multiple/ConnectionManagerSelective.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace ConnectionManager\Extra\Multiple;
44

55
use React\SocketClient\ConnectorInterface;
6-
use React\Promise\When;
6+
use React\Promise\Deferred;
77
use \UnderflowException;
88
use \InvalidArgumentException;
99

@@ -19,7 +19,9 @@ public function create($host, $port)
1919
$cm = $this->getConnectionManagerFor($host, $port);
2020
}
2121
catch (UnderflowException $e) {
22-
return When::reject($e);
22+
$deferred = new Deferred();
23+
$deferred->reject($e);
24+
return $deferred->promise();
2325
}
2426
return $cm->create($host, $port);
2527
}

tests/bootstrap.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
use React\Promise\When;
3+
use React\Promise\Deferred;
44

55
require __DIR__ . '/../vendor/autoload.php';
66

@@ -62,10 +62,13 @@ protected function createConnectionManagerMock($ret)
6262
->disableOriginalConstructor()
6363
->getMock();
6464

65+
$deferred = new Deferred();
66+
$deferred->resolve($ret);
67+
6568
$mock
6669
->expects($this->any())
6770
->method('create')
68-
->will($this->returnValue(When::resolve($ret)));
71+
->will($this->returnValue($deferred->promise()));
6972

7073
return $mock;
7174
}

0 commit comments

Comments
 (0)