From d547add0788f3bee489c54a8c2642a90343e4cc2 Mon Sep 17 00:00:00 2001 From: Robin van der Vleuten Date: Thu, 1 Mar 2012 17:13:11 +0100 Subject: [PATCH 1/8] CacheAdapterFactory created --- .../Factory/CacheAdapterFactory.php | 51 +++++++++++++++++++ Resources/config/adapter_factories.xml | 3 ++ Resources/config/gaufrette.xml | 1 + 3 files changed, 55 insertions(+) create mode 100644 DependencyInjection/Factory/CacheAdapterFactory.php diff --git a/DependencyInjection/Factory/CacheAdapterFactory.php b/DependencyInjection/Factory/CacheAdapterFactory.php new file mode 100644 index 0000000..a07654a --- /dev/null +++ b/DependencyInjection/Factory/CacheAdapterFactory.php @@ -0,0 +1,51 @@ + + */ +class CacheAdapterFactory implements AdapterFactoryInterface +{ + /** + * {@inheritDoc} + */ + public function create(ContainerBuilder $container, $id, array $config) + { + $container + ->setDefinition($id, new DefinitionDecorator('knp_gaufrette.adapter.cache')) + ->addArgument(new Reference('gaufrette.' . $config['source'] . '_adapter')) + ->addArgument(new Reference('gaufrette.' . $config['cache'] . '_adapter')) + ->addArgument($config['ttl']) + ; + } + + /** + * {@inheritDoc} + */ + public function getKey() + { + return 'cache'; + } + + /** + * {@inheritDoc} + */ + public function addConfiguration(NodeDefinition $node) + { + $node + ->children() + ->scalarNode('source')->isRequired()->cannotBeEmpty()->end() + ->scalarNode('cache')->isRequired()->cannotBeEmpty()->end() + ->scalarNode('ttl')->defaultValue(0)->end() + ->end() + ; + } +} diff --git a/Resources/config/adapter_factories.xml b/Resources/config/adapter_factories.xml index 6adc9b2..4d52403 100644 --- a/Resources/config/adapter_factories.xml +++ b/Resources/config/adapter_factories.xml @@ -35,6 +35,9 @@ + + + diff --git a/Resources/config/gaufrette.xml b/Resources/config/gaufrette.xml index c901c08..20f3313 100644 --- a/Resources/config/gaufrette.xml +++ b/Resources/config/gaufrette.xml @@ -31,6 +31,7 @@ + From 70d74ebe1160be2fb16c507d9615ed7537edf055 Mon Sep 17 00:00:00 2001 From: Robin van der Vleuten Date: Thu, 1 Mar 2012 17:35:36 +0100 Subject: [PATCH 2/8] You can now also set the serialize cache class --- DependencyInjection/Factory/CacheAdapterFactory.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/DependencyInjection/Factory/CacheAdapterFactory.php b/DependencyInjection/Factory/CacheAdapterFactory.php index a07654a..f606512 100644 --- a/DependencyInjection/Factory/CacheAdapterFactory.php +++ b/DependencyInjection/Factory/CacheAdapterFactory.php @@ -24,6 +24,7 @@ class CacheAdapterFactory implements AdapterFactoryInterface ->addArgument(new Reference('gaufrette.' . $config['source'] . '_adapter')) ->addArgument(new Reference('gaufrette.' . $config['cache'] . '_adapter')) ->addArgument($config['ttl']) + ->addArgument($config['serialize'] ? new Reference('gaufrette.' . $config['serialize'] . '_adapter') : null) ; } @@ -45,6 +46,7 @@ class CacheAdapterFactory implements AdapterFactoryInterface ->scalarNode('source')->isRequired()->cannotBeEmpty()->end() ->scalarNode('cache')->isRequired()->cannotBeEmpty()->end() ->scalarNode('ttl')->defaultValue(0)->end() + ->scalarNode('serialize')->defaultNull()->end() ->end() ; } From 3de89038d9c9d376be7dcf8d95f88be832e612b9 Mon Sep 17 00:00:00 2001 From: Robin van der Vleuten Date: Fri, 2 Mar 2012 10:12:56 +0100 Subject: [PATCH 3/8] Otherwise composer will check for the original package. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 263386b..1f5f3a4 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "knplabs/knp-gaufrette-bundle", + "name": "rvdv/knp-gaufrette-bundle", "type": "symfony-bundle", "description": "Allows to easily use the Gaufrette library in a Symfony project", "keywords": ["file", "filesystem", "media", "abstraction"], From 3a80615cac9428c7032a18aabfc708fc508ee9df Mon Sep 17 00:00:00 2001 From: Robin van der Vleuten Date: Wed, 13 Jun 2012 12:42:33 +0300 Subject: [PATCH 4/8] Changed the name to the correct one. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 1f5f3a4..263386b 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "rvdv/knp-gaufrette-bundle", + "name": "knplabs/knp-gaufrette-bundle", "type": "symfony-bundle", "description": "Allows to easily use the Gaufrette library in a Symfony project", "keywords": ["file", "filesystem", "media", "abstraction"], From 0f3c770a24f47c75068a268c52f345a28a4cdbfe Mon Sep 17 00:00:00 2001 From: l3l0 Date: Wed, 5 Sep 2012 20:29:39 +0200 Subject: [PATCH 5/8] Add info about cache adapter to README. Added tests for cache and ftp adapter. --- README.markdown | 39 +++++++++++++++++ Tests/Functional/ConfigurationTest.php | 46 +++++++++++++------- Tests/Functional/Resources/config/config.yml | 23 +++++++++- 3 files changed, 90 insertions(+), 18 deletions(-) diff --git a/README.markdown b/README.markdown index 99ce394..79a958d 100644 --- a/README.markdown +++ b/README.markdown @@ -338,3 +338,42 @@ knp_gaufrette: prefix: APC 'namespace' prefix ttl: 0 ``` + +## Cache + +Adapter which allow to cache other adapters + +### Parameters + + * `source` The source adapter that must be cached *(required)* + * `cache` The adapter used to cache the source *(required)* + * `ttl` Time to live *(default 0)* + * `serializer` The adapter used to cache serializations *(default null)* + +### Example + +``` yaml +# app/config/config.yml +knp_gaufrette: + adapters: + media_ftp: + ftp: + host: example.com + username: user + password: pass + directory: /example/ftp + create: true + mode: FTP_BINARY + media_apc: + apc: + prefix: APC 'namespace' prefix + ttl: 0 + media_cache: + cache: + source: media_ftp + cache: media_apc + ttl: 7200 + filesystems: + media: + adapter: media_cache +``` diff --git a/Tests/Functional/ConfigurationTest.php b/Tests/Functional/ConfigurationTest.php index cc63ce4..1b8126d 100644 --- a/Tests/Functional/ConfigurationTest.php +++ b/Tests/Functional/ConfigurationTest.php @@ -7,6 +7,7 @@ use Symfony\Component\HttpKernel\Util\Filesystem; class ConfigurationTest extends \PHPUnit_Framework_TestCase { private $cacheDir; + private $kernel; public function setUp() { @@ -17,6 +18,9 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase } mkdir($this->cacheDir, 0777, true); + + $this->kernel = new TestKernel('test', false); + $this->kernel->boot(); } public function tearDown() @@ -32,12 +36,7 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase */ public function shouldAllowForFilesystemAlias() { - $kernel = new TestKernel('test', false); - $kernel->boot(); - - $container = $kernel->getContainer(); - - $this->assertInstanceOf('Gaufrette\Filesystem', $container->get('foo_filesystem')); + $this->assertInstanceOf('Gaufrette\Filesystem', $this->kernel->getContainer()->get('foo_filesystem')); } /** @@ -57,12 +56,7 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase */ public function shouldAllowAccessToAllPublicServices() { - $kernel = new TestKernel('dev', false); - $kernel->boot(); - - $container = $kernel->getContainer(); - $this->assertInstanceOf('Gaufrette\Filesystem', $container->get('foo_filesystem')); - $this->assertInstanceOf('Knp\Bundle\GaufretteBundle\FilesystemMap', $container->get('knp_gaufrette.filesystem_map')); + $this->assertInstanceOf('Knp\Bundle\GaufretteBundle\FilesystemMap', $this->kernel->getContainer()->get('knp_gaufrette.filesystem_map')); } /** @@ -70,10 +64,30 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase */ public function shouldAllowAccessToFilesystemThoughFilesystemMap() { - $kernel = new TestKernel('test', false); - $kernel->boot(); + $this->assertInstanceOf('Gaufrette\Filesystem', $this->kernel->getContainer()->get('knp_gaufrette.filesystem_map')->get('foo')); + } - $container = $kernel->getContainer(); - $this->assertInstanceOf('Gaufrette\Filesystem', $container->get('knp_gaufrette.filesystem_map')->get('foo')); + /** + * @test + */ + public function shouldAllowAccessToLocalFilesystem() + { + $this->assertInstanceOf('Gaufrette\Adapter\Local', $this->kernel->getContainer()->get('foo_filesystem')->getAdapter()); + } + + /** + * @test + */ + public function shouldAllowAccessToCacheFilesystem() + { + $this->assertInstanceOf('Gaufrette\Adapter\Cache', $this->kernel->getContainer()->get('cache_filesystem')->getAdapter()); + } + + /** + * @test + */ + public function shouldAllowAccessToFtpFilesystem() + { + $this->assertInstanceOf('Gaufrette\Adapter\Ftp', $this->kernel->getContainer()->get('ftp_filesystem')->getAdapter()); } } diff --git a/Tests/Functional/Resources/config/config.yml b/Tests/Functional/Resources/config/config.yml index 229dedc..7fed85b 100644 --- a/Tests/Functional/Resources/config/config.yml +++ b/Tests/Functional/Resources/config/config.yml @@ -1,11 +1,30 @@ knp_gaufrette: adapters: - foo: + foo_local: local: directory: %kernel.root_dir% create: true + foo_ftp: + ftp: + host: example.com + username: user + password: pass + directory: /example/ftp + create: true + mode: FTP_BINARY + foo_cache: + cache: + source: foo_ftp + cache: foo_local + ttl: 7200 filesystems: foo: - adapter: foo + adapter: foo_local alias: foo_filesystem + cache: + adapter: foo_cache + alias: cache_filesystem + ftp: + adapter: foo_ftp + alias: ftp_filesystem From 3ed8b7db5c4e392b24e9127acd5ec780069ed4cc Mon Sep 17 00:00:00 2001 From: l3l0 Date: Wed, 5 Sep 2012 20:31:58 +0200 Subject: [PATCH 6/8] Added checking test coverage at tavisci --- .travis.yml | 2 +- composer.json | 3 ++- phpunit.xml.dist | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6bfadb9..517a42a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,4 +9,4 @@ before_script: - php composer.phar install --dev script: - - phpunit + - phpunit --coverage-text diff --git a/composer.json b/composer.json index 84bff0a..bdc12fc 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,8 @@ "knplabs/gaufrette": "*" }, "require-dev": { - "symfony/yaml": "2.*" + "symfony/yaml": "2.*", + "symfony/console": "2.*" }, "autoload": { "psr-0": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index c7be983..8ffb57f 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -23,6 +23,7 @@ ./Resources ./Tests + ./vendor From 1b5964daa17b104543fc141263bfe12d0e0f6679 Mon Sep 17 00:00:00 2001 From: l3l0 Date: Wed, 5 Sep 2012 21:10:42 +0200 Subject: [PATCH 7/8] Added part about composer to README file --- README.markdown | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index 79a958d..5df84ca 100644 --- a/README.markdown +++ b/README.markdown @@ -34,6 +34,10 @@ you must add the following lines to it: git=http://github.com/KnpLabs/KnpGaufretteBundle.git target=/bundles/Knp/Bundle/GaufretteBundle +### Composer Style + +Bundle can be installed using composer by add to require `composer.json` part `"knplabs/knp-gaufrette-bundle": "dev-master"` line. + ### Git Submodule Style If you are versioning your project with git, you had better to embed it @@ -41,9 +45,10 @@ as a submodule: $ git submodule add https://github.com/KnpLabs/KnpGaufretteBundle.git vendor/bundles/Knp/Bundle/GaufretteBundle -## Add the namespace in the autoloader +## Add the namespace in the autoloader You must register both Gaufrette and the KnpGaufretteBundle in your autoloader: +You do not have to do that if you are using composer autoload system. ``` php Date: Wed, 5 Sep 2012 21:13:18 +0200 Subject: [PATCH 8/8] Improved readme --- README.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index 5df84ca..e19202c 100644 --- a/README.markdown +++ b/README.markdown @@ -48,7 +48,7 @@ as a submodule: ## Add the namespace in the autoloader You must register both Gaufrette and the KnpGaufretteBundle in your autoloader: -You do not have to do that if you are using composer autoload system. +(You do not have to do that if you are using composer autoload system.) ``` php