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