Skip to content
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

[Review Required] Drop cache adapter support with Laravel 5.8+ #73

Merged
merged 7 commits into from
Oct 10, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ phpunit.xml
vendor
bin/
.php_cs.cache
.phpunit.*
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ Swap allows you to retrieve currency exchange rates from various services such a
$ composer require php-http/curl-client nyholm/psr7 php-http/message florianv/laravel-swap
```

### Laravel 5.7 or lesser

If you use cache, add also PSR-6 adapter and PSR-16 bridge cache dependencies :

```bash
$ composer require cache/illuminate-adapter cache/simple-cache-bridge
```

These dependencies are not required with Laravel 5.8 or greater which [implements PSR-16](https://github.com/laravel/framework/pull/27217).

Copy link
Owner

Choose a reason for hiding this comment

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

Can you please add the same to /doc/readme.md ?

### Laravel 5.5+

If you don't use auto-discovery, add the `ServiceProvider` to the providers array in `config/app.php`:
Expand Down
6 changes: 2 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,10 @@
},
"require": {
"php": "^7.1.3",
"florianv/swap": "^4.0",
"cache/illuminate-adapter": "^0.2.0",
"cache/simple-cache-bridge": "^1.0"
"florianv/swap": "^4.0"
},
"require-dev": {
"graham-campbell/testbench": "~5.2",
"graham-campbell/testbench": "^5.3",
"php-http/guzzle6-adapter": "^1.0",
"nyholm/psr7": "^1.0"
},
Expand Down
10 changes: 10 additions & 0 deletions doc/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ Copy the package config to your local config with the publish command:
$ php artisan vendor:publish --provider="Swap\Laravel\SwapServiceProvider"
```

__Laravel 5.7 or lesser :__

If you use cache, add also PSR-6 adapter and PSR-16 bridge cache dependencies :

```bash
$ composer require cache/illuminate-adapter cache/simple-cache-bridge
```

These dependencies are not required with Laravel 5.8 or greater which [implements PSR-16](https://github.com/laravel/framework/pull/27217).

### Lumen

Configure the Service Provider and alias:
Expand Down
21 changes: 19 additions & 2 deletions src/SwapServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,26 @@ private function getConfigPath($path = '')
private function getSimpleCache()
{
if ($cache = $this->app->config->get('swap.cache')) {
$store = $this->app['cache']->store($cache)->getStore();
$store = $this->app['cache']->store($cache);

return new SimpleCacheBridge(new IlluminateCachePool($store));
// Check simple cache PSR-16 compatibility
if ($store instanceof \Psr\SimpleCache\CacheInterface) {
return $store;
}

// Ensure PSR-6 adapter class exists
if (! class_exists(IlluminateCachePool::class)) {
throw new \Exception("cache/illuminate-adapter dependency is missing");
}

// Ensure PSR-16 bridge class exists
if (! class_exists(SimpleCacheBridge::class)) {
throw new \Exception("cache/simple-cache-bridge dependency is missing");
}

return new SimpleCacheBridge(
new IlluminateCachePool($store->getStore())
);
}

return null;
Expand Down
16 changes: 7 additions & 9 deletions tests/SwapServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,23 @@ class SwapServiceProviderTest extends AbstractTestCase
{
use ServiceProviderTrait;

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage The "access_key" option must be provided.
*/
public function testMissingServiceConfig()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('The "access_key" option must be provided.');

$this->app->config->set('swap.services', [
'currency_layer' => true,
]);

$this->app['swap'];
}

/**
* @expectedException \LogicException
* @expectedExceptionMessage The service "unknown" is not registered.
*/
public function testUnknownService()
{
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('The service "unknown" is not registered.');

$this->app->config->set('swap.services', [
'unknown' => true,
]);
Expand All @@ -49,7 +47,7 @@ public function testUnknownService()

public function testEmptyServices()
{
$this->app['swap'];
Assert::assertInstanceOf(Swap::class, $this->app['swap']);
}

public function testSwapIsInjectable()
Expand Down