Skip to content

Commit

Permalink
Merge pull request #7 from kisscool-fr/master
Browse files Browse the repository at this point in the history
Silex 2.0 support
  • Loading branch information
moust authored Jul 7, 2016
2 parents da11e90 + 0c32235 commit d60b52a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
],
"require": {
"php": ">=5.3.3",
"pimple/pimple": "~1.0"
"pimple/pimple": "~3.0"
},
"require-dev": {
"silex/silex": "~1.0",
"phpunit/phpunit": "~3.7"
"silex/silex": "~2.0",
"phpunit/phpunit": "~4.5"
},
"autoload": {
"psr-0": {
Expand Down
24 changes: 13 additions & 11 deletions src/Moust/Silex/Provider/CacheServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
namespace Moust\Silex\Provider;

use Silex\Application;
use Silex\ServiceProviderInterface;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Silex\Api\BootableProviderInterface;
use Moust\Silex\Cache\CacheFactory;

class CacheServiceProvider implements ServiceProviderInterface
class CacheServiceProvider implements ServiceProviderInterface, BootableProviderInterface
{
public function register(Application $app)
public function register(Container $app)
{
$app['cache.default_options'] = array(
'driver' => 'array'
Expand All @@ -36,7 +38,7 @@ public function register(Application $app)
);
};

$app['cache.factory'] = $app->share(function ($app) {
$app['cache.factory'] = $app->factory(function ($app) {
return new CacheFactory($app['cache.drivers'], $app['caches.options']);
});

Expand Down Expand Up @@ -64,10 +66,10 @@ public function register(Application $app)
$app['caches.options'] = $tmp;
});

$app['caches'] = $app->share(function ($app) {
$app['caches'] = $app->factory(function ($app) {
$app['caches.options.initializer']();

$caches = new \Pimple();
$caches = new Container();
foreach ($app['caches.options'] as $name => $options) {
if ($app['caches.default'] === $name) {
// we use shortcuts here in case the default has been overridden
Expand All @@ -76,18 +78,18 @@ public function register(Application $app)
$config = $app['caches.config'][$name];
}

$caches[$name] = $caches->share(function ($caches) use ($app, $config) {
$caches[$name] = $caches->factory(function ($caches) use ($app, $config) {
return $app['cache.factory']->getCache($config['driver'], $config);
});
}

return $caches;
});

$app['caches.config'] = $app->share(function ($app) {
$app['caches.config'] = $app->factory(function ($app) {
$app['caches.options.initializer']();

$configs = new \Pimple();
$configs = new Container();
foreach ($app['caches.options'] as $name => $options) {
$configs[$name] = $options;
}
Expand All @@ -96,13 +98,13 @@ public function register(Application $app)
});

// shortcuts for the "first" cache
$app['cache'] = $app->share(function ($app) {
$app['cache'] = $app->factory(function ($app) {
$caches = $app['caches'];

return $caches[$app['caches.default']];
});

$app['cache.config'] = $app->share(function ($app) {
$app['cache.config'] = $app->factory(function ($app) {
$caches = $app['caches.config'];

return $caches[$app['caches.default']];
Expand Down
2 changes: 1 addition & 1 deletion tests/Provider/CacheServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function testMultipleCache()
$this->assertEquals('./temp', $app['caches']['filesystem']->getCacheDir());

// check default cache
$this->assertSame($app['cache'], $app['caches']['memory']);
$this->assertEquals($app['cache'], $app['caches']['memory']);
}

public function testApcProvider()
Expand Down

0 comments on commit d60b52a

Please sign in to comment.