Skip to content

Upgrade to PSR18 + Httplug 2.0 #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Mar 23, 2019
Merged
Show file tree
Hide file tree
Changes from 9 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: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ vendor/
composer.lock
phpspec.yml
phpunit.xml
/.php_cs.cache
/tests/server/ssl/*.pem
/tests/server/ssl/*.key
/tests/server/ssl/*.req
27 changes: 18 additions & 9 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
<?php

/*
* In order to make it work, fabpot/php-cs-fixer and sllh/php-cs-fixer-styleci-bridge must be installed globally
* with composer.
*
* @link https://github.com/Soullivaneuh/php-cs-fixer-styleci-bridge
* @link https://github.com/FriendsOfPHP/PHP-CS-Fixer
*/
$config = PhpCsFixer\Config::create();
$config->setRules([
'@PSR2' => true,
'@Symfony' => true,
'array_syntax' => [
'syntax' => 'short',
],
'no_empty_phpdoc' => true,
'no_superfluous_phpdoc_tags' => true,
]);

use SLLH\StyleCIBridge\ConfigBridge;
$finder = PhpCsFixer\Finder::create();
$finder->in([
'src',
'tests'
]);

return ConfigBridge::create();
$config->setFinder($finder);

return $config;
10 changes: 0 additions & 10 deletions .styleci.yml

This file was deleted.

14 changes: 5 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ cache:
- $HOME/.composer/cache

php:
- 5.5
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3

env:
global:
Expand All @@ -21,15 +20,12 @@ branches:
- /^analysis-.*$/

matrix:
allow_failures:
- php: hhvm
dist: trusty
fast_finish: true
include:
- php: 5.5
- php: 7.1
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" COVERAGE=true TEST_COMMAND="composer test-ci"
- php: hhvm
dist: trusty
- php: 7.2
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest"

before_install:
- travis_retry composer self-update
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## 2.0.0 (unreleased)

* PSR18 and HTTPlug 2 support
* Remove support for php 5.5, 5.6 and 7.0
* SSL Method now defaults to `STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT`

## 1.4.0

* Support for Symfony 4
Expand Down
15 changes: 9 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@
}
],
"require": {
"php": "^5.5 || ^7.0",
"php": "^7.1",
"symfony/options-resolver": "^2.6 || ^3.0 || ^4.0",
"php-http/httplug": "^1.0",
"php-http/message-factory": "^1.0.2",
"php-http/httplug": "^1.0 || ^2.0",
"php-http/message-factory": "^1.0.2 || ^2.0",
"php-http/discovery": "^1.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.2",
"guzzlehttp/psr7": "^1.2",
"php-http/client-integration-tests": "^0.6",
"php-http/client-integration-tests": "^1.0 || ^2.0",
"php-http/message": "^1.0",
"php-http/client-common": "^1.0"
"php-http/client-common": "^1.0 || ^2.0"
},
"provide": {
"php-http/client-implementation": "1.0"
Expand All @@ -35,12 +36,14 @@
}
},
"scripts": {
"cs-check": "vendor/bin/php-cs-fixer fix --dry-run",
"cs-fix": "vendor/bin/php-cs-fixer fix",
"test": "vendor/bin/phpunit",
"test-ci": "vendor/bin/phpunit --coverage-clover build/coverage.xml"
},
"extra": {
"branch-alias": {
"dev-master": "1.1-dev"
"dev-master": "2.0-dev"
}
},
"prefer-stable": true,
Expand Down
10 changes: 5 additions & 5 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Http\Discovery\MessageFactoryDiscovery;
use Http\Message\ResponseFactory;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;

Expand All @@ -31,7 +32,7 @@ class Client implements HttpClient
'stream_context_param' => [],
'ssl' => null,
'write_buffer_size' => 8192,
'ssl_method' => STREAM_CRYPTO_METHOD_TLS_CLIENT,
'ssl_method' => STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT,
];

/**
Expand All @@ -46,7 +47,7 @@ class Client implements HttpClient
* @var array $stream_context_param Context params as defined in the PHP documentation
* @var bool $ssl Use ssl, default to scheme from request, false if not present
* @var int $write_buffer_size Buffer when writing the request body, defaults to 8192
* @var int $ssl_method Crypto method for ssl/tls, see PHP doc, defaults to STREAM_CRYPTO_METHOD_TLS_CLIENT
* @var int $ssl_method Crypto method for ssl/tls, see PHP doc, defaults to STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT
* }
*/
public function __construct(ResponseFactory $responseFactory = null, array $config = [])
Expand All @@ -62,7 +63,7 @@ public function __construct(ResponseFactory $responseFactory = null, array $conf
/**
* {@inheritdoc}
*/
public function sendRequest(RequestInterface $request)
public function sendRequest(RequestInterface $request): ResponseInterface
{
$remote = $this->config['remote_socket'];
$useSsl = $this->config['ssl'];
Expand Down Expand Up @@ -104,7 +105,7 @@ public function sendRequest(RequestInterface $request)
*
* @return resource Socket resource
*/
protected function createSocket(RequestInterface $request, $remote, $useSsl)
protected function createSocket(RequestInterface $request, string $remote, bool $useSsl)
{
$errNo = null;
$errMsg = null;
Expand Down Expand Up @@ -161,7 +162,6 @@ protected function configure(array $config = [])
/**
* Return remote socket from the request.
*
* @param RequestInterface $request
*
* @throws InvalidRequestException When no remote can be determined from the request
*
Expand Down
21 changes: 6 additions & 15 deletions src/RequestWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ trait RequestWriter
/**
* Write a request to a socket.
*
* @param resource $socket
* @param RequestInterface $request
* @param int $bufferSize
* @param resource $socket
*
* @throws BrokenPipeException
*/
protected function writeRequest($socket, RequestInterface $request, $bufferSize = 8192)
protected function writeRequest($socket, RequestInterface $request, int $bufferSize = 8192)
{
if (false === $this->fwrite($socket, $this->transformRequestHeadersToString($request))) {
throw new BrokenPipeException('Failed to send request, underlying socket not accessible, (BROKEN EPIPE)', $request);
Expand All @@ -37,13 +35,11 @@ protected function writeRequest($socket, RequestInterface $request, $bufferSize
/**
* Write Body of the request.
*
* @param resource $socket
* @param RequestInterface $request
* @param int $bufferSize
* @param resource $socket
*
* @throws BrokenPipeException
*/
protected function writeBody($socket, RequestInterface $request, $bufferSize = 8192)
protected function writeBody($socket, RequestInterface $request, int $bufferSize = 8192)
{
$body = $request->getBody();

Expand All @@ -62,12 +58,8 @@ protected function writeBody($socket, RequestInterface $request, $bufferSize = 8

/**
* Produce the header of request as a string based on a PSR Request.
*
* @param RequestInterface $request
*
* @return string
*/
protected function transformRequestHeadersToString(RequestInterface $request)
protected function transformRequestHeadersToString(RequestInterface $request): string
{
$message = vsprintf('%s %s HTTP/%s', [
strtoupper($request->getMethod()),
Expand All @@ -90,11 +82,10 @@ protected function transformRequestHeadersToString(RequestInterface $request)
* @see https://secure.phabricator.com/rPHU69490c53c9c2ef2002bc2dd4cecfe9a4b080b497
*
* @param resource $stream The stream resource
* @param string $bytes Bytes written in the stream
*
* @return bool|int false if pipe is broken, number of bytes written otherwise
*/
private function fwrite($stream, $bytes)
private function fwrite($stream, string $bytes)
{
if (!strlen($bytes)) {
return 0;
Expand Down
14 changes: 4 additions & 10 deletions src/ResponseReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,12 @@ trait ResponseReader
/**
* Read a response from a socket.
*
* @param RequestInterface $request
* @param resource $socket
* @param resource $socket
*
* @throws TimeoutException When the socket timed out
* @throws BrokenPipeException When the response cannot be read
*
* @return ResponseInterface
*/
protected function readResponse(RequestInterface $request, $socket)
protected function readResponse(RequestInterface $request, $socket): ResponseInterface
{
$headers = [];
$reason = null;
Expand Down Expand Up @@ -88,12 +85,9 @@ protected function readResponse(RequestInterface $request, $socket)
/**
* Create the stream.
*
* @param $socket
* @param ResponseInterface $response
*
* @return Stream
* @param resource $socket
*/
protected function createStream($socket, ResponseInterface $response)
protected function createStream($socket, ResponseInterface $response): Stream
{
$size = null;

Expand Down
2 changes: 1 addition & 1 deletion src/Stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Stream implements StreamInterface
* @param resource $socket
* @param int $size
*/
public function __construct($socket, $size = null)
public function __construct($socket, ?int $size = null)
{
$this->socket = $socket;
$this->size = $size;
Expand Down
6 changes: 3 additions & 3 deletions tests/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ class BaseTestCase extends TestCase

public function startServer($name)
{
$filename = __DIR__ . '/server/' . $name . '.php';
$pipes = [];
$filename = __DIR__.'/server/'.$name.'.php';
$pipes = [];

if (!Semaphore::acquire()) {
$this->fail('Could not connect to server');
}

$this->servers[$name] = proc_open('php '. $filename, [], $pipes);
$this->servers[$name] = proc_open('php '.$filename, [], $pipes);
sleep(1);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Semaphore.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static function acquire()
return false;
}
}
self::$openConnections++;
++self::$openConnections;

return true;
}
Expand All @@ -35,6 +35,6 @@ public static function release()
{
// Do no be too quick
usleep(500000);
self::$openConnections--;
--self::$openConnections;
}
}
1 change: 0 additions & 1 deletion tests/SocketClientFeatureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Http\Client\Socket\Tests;

use Http\Client\Tests\HttpFeatureTest;
use Http\Message\MessageFactory\GuzzleMessageFactory;
use Http\Client\Socket\Client as SocketHttpClient;

class SocketClientFeatureTest extends HttpFeatureTest
Expand Down
1 change: 0 additions & 1 deletion tests/SocketHttpAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Http\Client\Socket\Tests;

use Http\Client\Tests\HttpClientTest;
use Http\Message\MessageFactory\GuzzleMessageFactory;
use Http\Client\Socket\Client as SocketHttpClient;

class SocketHttpAdapterTest extends HttpClientTest
Expand Down
Loading