Skip to content

Commit 81daf7f

Browse files
authored
Merge pull request #73 from CakeDC/issue/72
72 - Remove CakePHP Adapter in favor of official Cake Client
2 parents 098dcd2 + 55fbebf commit 81daf7f

File tree

9 files changed

+34
-29
lines changed

9 files changed

+34
-29
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ jobs:
1111
strategy:
1212
fail-fast: false
1313
matrix:
14-
php-version: ['7.4', '8.2']
14+
php-version: ['8.1', '8.3']
1515
db-type: [sqlite, mysql, pgsql]
1616
prefer-lowest: ['']
1717
include:
18-
- php-version: '7.4'
18+
- php-version: '8.1'
1919
db-type: 'sqlite'
2020
prefer-lowest: 'prefer-lowest'
2121

@@ -67,7 +67,7 @@ jobs:
6767
if [[ ${{ matrix.db-type }} == 'sqlite' ]]; then export DB_URL='sqlite:///:memory:'; fi
6868
if [[ ${{ matrix.db-type }} == 'mysql' ]]; then export DB_URL='mysql://root:[email protected]/cakephp'; fi
6969
if [[ ${{ matrix.db-type }} == 'pgsql' ]]; then export DB_URL='postgres://postgres:[email protected]/postgres'; fi
70-
if [[ ${{ matrix.php-version }} == '7.4' && ${{ matrix.db-type }} == 'sqlite' ]]; then
70+
if [[ ${{ matrix.php-version }} == '8.1' && ${{ matrix.db-type }} == 'sqlite' ]]; then
7171
vendor/bin/phpunit --coverage-clover=coverage.xml
7272
else
7373
vendor/bin/phpunit
@@ -76,7 +76,7 @@ jobs:
7676
run: if ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then vendor/bin/validate-prefer-lowest -m; fi
7777

7878
- name: Code Coverage Report
79-
if: success() && matrix.php-version == '7.4' && matrix.db-type == 'sqlite'
79+
if: success() && matrix.php-version == '8.1' && matrix.db-type == 'sqlite'
8080
uses: codecov/codecov-action@v3
8181

8282
validation:
@@ -89,7 +89,7 @@ jobs:
8989
- name: Setup PHP
9090
uses: shivammathur/setup-php@v2
9191
with:
92-
php-version: '7.4'
92+
php-version: '8.1'
9393
extensions: mbstring, intl
9494
coverage: none
9595

composer.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@
1919
}
2020
],
2121
"require": {
22-
"php": ">=7.4",
22+
"php": ">=8.1",
2323
"cakephp/cakephp": "^4.2.0"
2424
},
2525
"require-dev": {
2626
"ext-intl": "*",
2727
"ext-json": "*",
2828
"geocoder-php/provider-implementation": "^1.0",
29-
"php-http/cakephp-adapter": "^0.3.0",
30-
"php-http/message": "^1.8.0",
29+
"php-http/message": "^1.16.0",
3130
"geocoder-php/google-maps-provider": "^4.4.0",
3231
"geocoder-php/nominatim-provider": "^5.1",
3332
"dereuromark/cakephp-tools": "^2.0.0",
3433
"fig-r/psr2r-sniffer": "dev-master",
35-
"phpunit/phpunit": "^9.5"
34+
"phpunit/phpunit": "^9.5",
35+
"symfony/http-client": "^6.0 || ^7.0"
3636
},
3737
"support": {
3838
"source": "https://github.com/dereuromark/cakephp-geo"
@@ -49,6 +49,9 @@
4949
"TestApp\\": "tests/TestApp/src/"
5050
}
5151
},
52+
"conflict": {
53+
"php-http/cakephp-adapter": "*"
54+
},
5255
"scripts": {
5356
"test": "phpunit",
5457
"test-coverage": "phpunit --log-junit webroot/coverage/unitreport.xml --coverage-html webroot/coverage --coverage-clover webroot/coverage/coverage.xml",

docs/Install.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@ Plugin::loadAll([
3939
## Optional packages
4040

4141
Depending on what tools you use (e.g. geocoding), you might need additional packages.
42-
So depending on the type of engine/adapter, you might need for example the following for geocoding:
43-
44-
"php-http/cakephp-adapter": "^0.3.0",
45-
"php-http/message": "^1.8.0",
46-
47-
Add this to your composer.json require section then.
4842

4943
For using GoogleMaps as concrete adapter, you might also need for example:
5044

src/Geocoder/Geocoder.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use Cake\Core\Configure;
66
use Cake\Core\InstanceConfigTrait;
7-
use Cake\Http\Client as HttpCakeClient;
7+
use Cake\Http\Client;
88
use Cake\I18n\I18n;
99
use Geo\Exception\InconclusiveException;
1010
use Geo\Exception\NotAccurateEnoughException;
@@ -15,7 +15,6 @@
1515
use Geocoder\Query\GeocodeQuery;
1616
use Geocoder\Query\ReverseQuery;
1717
use Geocoder\StatefulGeocoder;
18-
use Http\Adapter\Cake\Client;
1918
use Locale;
2019

2120
/**
@@ -129,7 +128,7 @@ class Geocoder {
129128
protected $geocoder;
130129

131130
/**
132-
* @var \Http\Client\HttpClient
131+
* @var \Cake\Http\Client
133132
*/
134133
protected $adapter;
135134

@@ -354,9 +353,9 @@ protected function _buildGeocoder() {
354353
return;
355354
}
356355

357-
/** @var \Http\Client\HttpClient $adapterClass */
356+
/** @var \Cake\Http\Client $adapterClass */
358357
$adapterClass = $this->getConfig('adapter');
359-
$this->adapter = new $adapterClass(new HttpCakeClient(), new ResponseFactory());
358+
$this->adapter = new $adapterClass();
360359

361360
$provider = new GoogleMaps($this->adapter, $this->getConfig('region'), $this->getConfig('apiKey'));
362361
$geocoder = new StatefulGeocoder($provider, $this->getConfig('locale') ?: 'en');

src/Geocoder/Provider/GeoIpLookup.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace Geo\Geocoder\Provider;
88

9+
use Cake\Http\Client;
910
use Cake\Utility\Xml;
1011
use Geocoder\Collection;
1112
use Geocoder\Exception\InvalidServerResponse;
@@ -16,7 +17,6 @@
1617
use Geocoder\Model\AdminLevel;
1718
use Geocoder\Query\GeocodeQuery;
1819
use Geocoder\Query\ReverseQuery;
19-
use Http\Client\HttpClient;
2020

2121
/**
2222
* @author Mark Scherer
@@ -39,11 +39,11 @@ class GeoIpLookup extends AbstractHttpProvider {
3939
protected $referer;
4040

4141
/**
42-
* @param \Http\Client\HttpClient $client an HTTP client
42+
* @param \Cake\Http\Client $client an HTTP client
4343
* @param string $userAgent Value of the User-Agent header
4444
* @param string $referer Value of the Referer header
4545
*/
46-
public function __construct(HttpClient $client, string $userAgent, string $referer = '') {
46+
public function __construct(Client $client, string $userAgent, string $referer = '') {
4747
parent::__construct($client);
4848

4949
$this->userAgent = $userAgent;

src/Geocoder/ResponseFactory.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,23 @@
33
namespace Geo\Geocoder;
44

55
use Cake\Http\Client\Response;
6-
use Http\Message\ResponseFactory as ResponseFactoryInterface;
6+
use Psr\Http\Message\ResponseFactoryInterface;
7+
use Psr\Http\Message\ResponseInterface;
78

9+
/**
10+
* @deprecated Not in use anymore - directly use {@link \Cake\Http\Client} instead.
11+
*/
812
class ResponseFactory implements ResponseFactoryInterface {
913

1014
/**
11-
* @inheritDoc
15+
* @param int $code
16+
* @param string $reasonPhrase
17+
* @param array<string> $headers
18+
* @param string|null $body
19+
*
20+
* @return \Psr\Http\Message\ResponseInterface
1221
*/
13-
public function createResponse($statusCode = 200, $reasonPhrase = null, array $headers = [], $body = null, $protocolVersion = '1.1') {
22+
public function createResponse(int $code = 200, string $reasonPhrase = '', array $headers = [], ?string $body = null): ResponseInterface {
1423
return new Response($headers, (string)$body);
1524
}
1625

tests/TestCase/Geocoder/GeocoderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
namespace Geo\Test\Geocoder;
44

5+
use Cake\Http\Client;
56
use Cake\I18n\I18n;
67
use Cake\TestSuite\TestCase;
78
use Geo\Geocoder\Provider\GeoIpLookup;
89
use Geocoder\Provider\Nominatim\Nominatim;
9-
use Http\Adapter\Cake\Client;
1010
use TestApp\Geocoder\Geocoder;
1111

1212
class GeocoderTest extends TestCase {

tests/TestCase/Geocoder/Provider/GeoIpLookupTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
namespace Geo\Test\Geocoder;
44

5+
use Cake\Http\Client;
56
use Cake\TestSuite\TestCase;
67
use Geo\Geocoder\Provider\GeoIpAddress;
78
use Geo\Geocoder\Provider\GeoIpLookup;
8-
use Http\Adapter\Cake\Client;
99

1010
class GeoIpLookupTest extends TestCase {
1111

tests/TestCase/View/Helper/GoogleMapHelperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public function testStatic() {
235235
'title' => '<b>Yeah!</b>',
236236
];
237237
$is = $this->GoogleMap->staticMap($options, $attr);
238-
$expected = '<img src="//maps.google.com/maps/api/staticmap?size=200x100&amp;format=png&amp;mobile=false&amp;center=1&amp;maptype=roadmap" title="&lt;b&gt;Yeah!&lt;/b&gt;" alt="Map"/>';
238+
$expected = '<img src="//maps.google.com/maps/api/staticmap?size=200x100&amp;format=png&amp;mobile=false&amp;center=1&amp;maptype=roadmap" title="&lt;b&gt;Yeah!&lt;/b&gt;" alt="Map">';
239239
$this->assertSame($expected, $is);
240240

241241
$pos = [

0 commit comments

Comments
 (0)