Skip to content
This repository was archived by the owner on Jan 8, 2024. It is now read-only.

Update for CakePHP 4.x. #11

Merged
merged 5 commits into from
Mar 24, 2020
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: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Define the line ending behavior of the different file extensions
# Set default behavior, in case users don't have core.autocrlf set.
* text text=auto eol=lf

.editorconfig export-ignore
.gitattributes export-ignore
/.github/ export-ignore
Expand Down
14 changes: 8 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/behat.yml
/build/
/composer.lock
/phpspec.yml
/phpunit.xml
/vendor/
behat.yml
build/
composer.lock
phpspec.yml
phpunit.xml
.phpunit.result.cache
vendor/
.idea/
17 changes: 7 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
language: php

sudo: false

cache:
directories:
- $HOME/.composer/cache/files

php:
- 5.6
- 7.0
- 7.1
- 7.2
- 7.4

env:
global:
Expand All @@ -25,7 +18,7 @@ matrix:
dist: trusty
fast_finish: true
include:
- php: 5.6
- php: 7.2
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" COVERAGE=true TEST_COMMAND="composer test-ci"
- php: hhvm
dist: trusty
Expand All @@ -47,3 +40,7 @@ script:
after_success:
- if [[ $COVERAGE = true ]]; then wget https://scrutinizer-ci.com/ocular.phar; fi
- if [[ $COVERAGE = true ]]; then php ocular.phar code-coverage:upload --format=php-clover build/coverage.xml; fi

cache:
directories:
- $HOME/.composer/cache/files
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## 0.3.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## 0.3.0
## Unreleased


- CakePHP 4.x compatibility

## 0.2.0

### Changed
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
[![Quality Score](https://img.shields.io/scrutinizer/g/php-http/cakephp-adapter.svg?style=flat-square)](https://scrutinizer-ci.com/g/php-http/cakephp-adapter)
[![Total Downloads](https://img.shields.io/packagist/dt/php-http/cakephp-adapter.svg?style=flat-square)](https://packagist.org/packages/php-http/cakephp-adapter)

**Httplug adapter for the cakephp network library**
Httplug adapter for the **CakePHP** HTTP library.

This branch is for use with CakePHP 4.0+.

## Install

Expand Down
12 changes: 7 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
}
],
"require": {
"php": "^5.6 || ^7.0",
"php-http/httplug": "^1.0",
"php": "^7.2",
"php-http/httplug": "^2.0",
"php-http/discovery": "^1.0",
"cakephp/cakephp": "^3.4.12"
"cakephp/cakephp": "^4.0"
},
"require-dev": {
"php-http/client-integration-tests": "^0.6"
"php-http/client-integration-tests": "^0.6",
"phpunit/phpunit": "^8.5"
},
"autoload": {
"psr-4": {
Expand All @@ -36,9 +37,10 @@
"test": "vendor/bin/phpunit",
"test-ci": "vendor/bin/phpunit --coverage-clover build/coverage.xml"
},
"prefer-stable": true,
"extra": {
"branch-alias": {
"dev-master": "0.2-dev"
"dev-master": "0.3-dev"
}
}
}
26 changes: 16 additions & 10 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,27 @@
use Http\Discovery\MessageFactoryDiscovery;
use Http\Message\ResponseFactory;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Throwable;

/**
* Client compatible with PSR7 and Httplug interfaces, using a CakePHP client.
*/
class Client implements HttpClient
{
/** @var CakeClient */
/**
* @var \Cake\Http\Client
*/
private $client;

/** @var ResponseFactory */
/**
* @var \Http\Message\ResponseFactory
*/
private $responseFactory;

/**
* @param CakeClient $client
* @param ResponseFactory $responseFactory
* @param \Cake\Http\Client|null $client
* @param \Http\Message\ResponseFactory|null $responseFactory
*/
public function __construct(CakeClient $client = null, ResponseFactory $responseFactory = null)
{
Expand All @@ -33,9 +39,9 @@ public function __construct(CakeClient $client = null, ResponseFactory $response
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function sendRequest(RequestInterface $request)
public function sendRequest(RequestInterface $request): ResponseInterface
{
$cakeRequest = new Request(
(string) $request->getUri(),
Expand All @@ -47,13 +53,13 @@ public function sendRequest(RequestInterface $request)
->withProtocolVersion($request->getProtocolVersion())
->withBody($request->getBody());

if (null === $cakeRequest->header('Content-Type')) {
$cakeRequest->header('Content-Type', 'application/x-www-form-urlencoded');
if (null === $cakeRequest->getHeader('Content-Type')) {
$cakeRequest = $cakeRequest->withHeader('Content-Type', 'application/x-www-form-urlencoded');
}

try {
$response = $this->client->send($cakeRequest, $this->client->config());
} catch (Exception $exception) {
$response = $this->client->send($cakeRequest, $this->client->getConfig());
} catch (Throwable $exception) {
throw new NetworkException('Failed to send request', $request, $exception);
}

Expand Down
5 changes: 4 additions & 1 deletion tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@

class ClientTest extends HttpClientTest
{
protected function createHttpAdapter()
/**
* @return \Http\Adapter\Cake\Client
*/
protected function createHttpAdapter(): Client
{
return new Client();
}
Expand Down