Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: php

php:
# - 5.3 # requires old distro, see below
- 5.4
- 5.5
- 5.6
Expand All @@ -12,9 +11,6 @@ php:
dist: trusty

matrix:
include:
- php: 5.3
dist: precise
allow_failures:
- php: hhvm

Expand Down
12 changes: 1 addition & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,6 @@ $request = $request->withProtocolVersion(1.1);
$browser->send($request)->then(…);
```

> Legacy compatibility: Note that the custom HTTP protocol version will be
ignored for legacy versions (PHP 5.3) because the underlying `http-client`
v0.3 API does not support this parameter.

#### withOptions()

The `withOptions(array $options)` method can be used to change the [options](#options) to use:
Expand Down Expand Up @@ -481,12 +477,6 @@ connector settings (DNS resolution, SSL/TLS parameters, timeouts etc.), you can
explicitly pass a custom instance of the
[legacy `ConnectorInterface`](https://github.com/reactphp/socket-client#connectorinterface).

The below examples assume you've installed the latest legacy SocketClient version:

```bash
$ composer require react/socket-client:^0.5
```

You can optionally pass additional
[socket context options](http://php.net/manual/en/context.socket.php)
to the constructor like this:
Expand Down Expand Up @@ -583,7 +573,7 @@ $ composer require clue/buzz-react:^1.1.1
See also the [CHANGELOG](CHANGELOG.md) for details about version upgrades.

This project aims to run on any platform and thus does not require any PHP
extensions and supports running on legacy PHP 5.3 through current PHP 7+ and
extensions and supports running on legacy PHP 5.4 through current PHP 7+ and
HHVM.
It's *highly recommended to use PHP 7+* for this project.

Expand Down
11 changes: 5 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
"psr-4": { "Clue\\React\\Buzz\\": "src/" }
},
"require": {
"php": ">=5.3",
"php": ">=5.4",
"react/event-loop": "^0.4 || ^0.3",
"react/http-client": "^0.5 || ^0.4 || ^0.3",
"react/socket": "^0.8",
"react/socket-client": "^0.5 || ^0.4.5",
"react/dns": "^0.4.1 || ^0.3",
"react/http-client": "^0.5",
"react/promise": "^2 || ^1.1",
"react/stream": "^0.4 || ^0.3.1",
"react/socket": "^0.8",
"react/socket-client": "^0.7 || ^0.6",
"react/stream": "^0.6 || ^0.5 || ^0.4.6",
"psr/http-message": "^1.0",
"ringcentral/psr7": "^1.2"
},
Expand Down
10 changes: 3 additions & 7 deletions examples/21-stream-forwarding.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?php

use Clue\React\Buzz\Browser;
use React\Stream\ReadableStreamInterface;
use Psr\Http\Message\ResponseInterface;
use React\Stream\Stream;
use React\Stream\WritableResourceStream;
use RingCentral\Psr7;

$url = isset($argv[1]) ? $argv[1] : 'http://google.com/';
Expand All @@ -13,11 +12,8 @@
$loop = React\EventLoop\Factory::create();
$client = new Browser($loop);

$out = new Stream(STDOUT, $loop);
$out->pause();

$info = new Stream(STDERR, $loop);
$info->pause();
$out = new WritableResourceStream(STDOUT, $loop);
$info = new WritableResourceStream(STDERR, $loop);

$info->write('Requesting ' . $url . '…' . PHP_EOL);

Expand Down
5 changes: 2 additions & 3 deletions examples/22-stream-stdin.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?php

use Clue\React\Buzz\Browser;
use React\Stream\ReadableStreamInterface;
use Psr\Http\Message\ResponseInterface;
use React\Stream\Stream;
use React\Stream\ReadableResourceStream;
use RingCentral\Psr7;

$url = isset($argv[1]) ? $argv[1] : 'https://httpbin.org/post';
Expand All @@ -13,7 +12,7 @@
$loop = React\EventLoop\Factory::create();
$client = new Browser($loop);

$in = new Stream(STDIN, $loop);
$in = new ReadableResourceStream(STDIN, $loop);

echo 'Sending STDIN as POST to ' . $url . '…' . PHP_EOL;

Expand Down
2 changes: 1 addition & 1 deletion src/Io/ConnectionUpcaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use React\Stream\Util;

/**
* Adapter to upcast a legacy SocketClient:v0.5 Connector result to a new Socket:v0.8 ConnectionInterface
* Adapter to upcast a legacy SocketClient-Connector result to a new Socket-ConnectionInterface
*
* @internal
*/
Expand Down
13 changes: 4 additions & 9 deletions src/Io/ConnectorUpcaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,25 @@

use React\Socket\ConnectorInterface;
use React\SocketClient\ConnectorInterface as LegacyConnectorInterface;
use React\Stream\Stream;
use React\Stream\DuplexStreamInterface;

/**
* Adapter to upcast a legacy SocketClient:v0.5 Connector to a new Socket:v0.8 Connector
* Adapter to upcast a legacy SocketClient:v0.7/v0.6 Connector to a new Socket:v0.8 Connector
*
* @internal
*/
class ConnectorUpcaster implements ConnectorInterface
{
private $legacy;

public function __construct(LegacyConnectorInterface$connector)
public function __construct(LegacyConnectorInterface $connector)
{
$this->legacy = $connector;
}

public function connect($uri)
{
$parts = parse_url((strpos($uri, '://') === false ? 'tcp://' : '') . $uri);
if (!$parts || !isset($parts['host'], $parts['port'])) {
return \React\Promise\reject(new \InvalidArgumentException('Unable to parse URI'));
}

return $this->legacy->create($parts['host'], $parts['port'])->then(function (Stream $stream) {
return $this->legacy->connect($uri)->then(function (DuplexStreamInterface $stream) {
return new ConnectionUpcaster($stream);
});
}
Expand Down
23 changes: 23 additions & 0 deletions src/Io/FixedUriConnector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Clue\React\Buzz\Io;

use React\Socket\ConnectorInterface;

/** @internal */
class FixedUriConnector implements ConnectorInterface
{
private $uri;
private $connector;

public function __construct($uri, ConnectorInterface $connector)
{
$this->uri = $uri;
$this->connector = $connector;
}

public function connect($_)
{
return $this->connector->connect($this->uri);
}
}
75 changes: 26 additions & 49 deletions src/Io/Sender.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,20 @@

namespace Clue\React\Buzz\Io;

use React\HttpClient\Client as HttpClient;
use Clue\React\Buzz\Message\MessageFactory;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use React\EventLoop\LoopInterface;
use React\HttpClient\Client as HttpClient;
use React\HttpClient\Request as RequestStream;
use React\HttpClient\Response as ResponseStream;
use React\Promise;
use React\Promise\Deferred;
use React\EventLoop\LoopInterface;
use React\Dns\Resolver\Factory as ResolverFactory;
use React\Socket\Connector;
use React\SocketClient\Connector as LegacyConnector;
use React\SocketClient\SecureConnector;
use React\SocketClient\ConnectorInterface as LegacyConnectorInterface;
use React\Dns\Resolver\Resolver;
use React\Promise;
use Clue\React\Buzz\Message\MessageFactory;
use React\Stream\ReadableStreamInterface;
use React\Socket\UnixConnector;

class Sender
{
Expand All @@ -41,36 +39,23 @@ class Sender
*/
public static function createFromLoop(LoopInterface $loop)
{
$ref = new \ReflectionClass('React\HttpClient\Client');
$num = $ref->getConstructor()->getNumberOfRequiredParameters();
if ($num === 1) {
// react/http 0.5
return new self(new HttpClient($loop));
}

// react/http 0.4/0.3
return self::createFromLoopDns($loop, '8.8.8.8');
return new self(new HttpClient($loop));
}

/**
* [deprecated] create sender attached to the given event loop and DNS resolver
*
* @param LoopInterface $loop
* @param Resolver|string $dns DNS resolver instance or IP address
* @param \React\Dns\Resolver\Resolver|string $dns DNS resolver instance or IP address
* @return self
* @deprecated as of v1.2.0, see createFromLoop()
* @see self::createFromLoop()
*/
public static function createFromLoopDns(LoopInterface $loop, $dns)
{
if (!($dns instanceof Resolver)) {
$dnsResolverFactory = new ResolverFactory();
$dns = $dnsResolverFactory->createCached($dns, $loop);
}

$connector = new LegacyConnector($loop, $dns);

return self::createFromLoopConnectors($loop, $connector);
return new self(new HttpClient($loop, new Connector($loop, array(
'dns' => $dns
))));
}

/**
Expand All @@ -89,27 +74,13 @@ public static function createFromLoopConnectors(LoopInterface $loop, LegacyConne
$secureConnector = new SecureConnector($connector, $loop);
}

// create HttpClient for React 0.5/0.4/0.3 (code coverage will be achieved by testing versions with Travis)
// @codeCoverageIgnoreStart
$ref = new \ReflectionClass('React\HttpClient\Client');
$num = $ref->getConstructor()->getNumberOfRequiredParameters();
if ($num === 1) {
// react/http-client:0.5 only requires the loop, the connector is actually optional
// v0.5 requires the new Socket-Connector, so we upcast from the legacy SocketClient-Connectors here
$http = new HttpClient($loop, new Connector($loop, array(
'tcp' => new ConnectorUpcaster($connector),
'tls' => new ConnectorUpcaster($secureConnector),
'dns' => false
)));
} elseif ($num === 2) {
// react/http-client:0.4 removed the $loop parameter
$http = new HttpClient($connector, $secureConnector);
} else {
$http = new HttpClient($loop, $connector, $secureConnector);
}
// @codeCoverageIgnoreEnd

return new self($http);
// react/http v0.5 requires the new Socket-Connector, so we upcast from the legacy SocketClient-Connectors here
return new self(new HttpClient($loop, new Connector($loop, array(
'tcp' => new ConnectorUpcaster($connector),
'tls' => new ConnectorUpcaster($secureConnector),
'dns' => false,
'timeout' => false
))));
}

/**
Expand All @@ -121,9 +92,15 @@ public static function createFromLoopConnectors(LoopInterface $loop, LegacyConne
*/
public static function createFromLoopUnix(LoopInterface $loop, $path)
{
$connector = new UnixConnector($loop, $path);

return self::createFromLoopConnectors($loop, $connector);
return new self(
new HttpClient(
$loop,
new FixedUriConnector(
$path,
new UnixConnector($loop)
)
)
);
}

private $http;
Expand Down
51 changes: 0 additions & 51 deletions src/Io/UnixConnector.php

This file was deleted.

1 change: 1 addition & 0 deletions tests/FunctionalBrowserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ public function testPostStreamChunked()

$this->loop->addTimer(0.001, function () use ($stream) {
$stream->emit('data', array('hello world'));
$stream->emit('end');
$stream->close();
});

Expand Down
16 changes: 16 additions & 0 deletions tests/Io/FixedUriConnectorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

use Clue\React\Buzz\Io\FixedUriConnector;

class FixedUriConnectorTest extends PHPUnit_Framework_TestCase
{
public function testWillInvokeGivenConnector()
{
$base = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
$base->expects($this->once())->method('connect')->with('test')->willReturn('ret');

$connector = new FixedUriConnector('test', $base);

$this->assertEquals('ret', $connector->connect('ignored'));
}
}
Loading