Skip to content

Commit

Permalink
Merge pull request #382 from formapro-forks/move-data-loaders
Browse files Browse the repository at this point in the history
Move data loaders to binary folder
  • Loading branch information
makasim committed Apr 4, 2014
2 parents 23bd992 + 6d3c7c9 commit bab39ad
Show file tree
Hide file tree
Showing 24 changed files with 59 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
composer.lock
composer.phar
vendor/
/Tests/Functional/app/web/media/cache
Tests/Functional/app/web/media/cache
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Liip\ImagineBundle\Imagine\Data\Loader;
namespace Liip\ImagineBundle\Binary\Loader;

use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Liip\ImagineBundle\Imagine\Data\Loader;
namespace Liip\ImagineBundle\Binary\Loader;

use Imagine\Image\ImagineInterface;
use Liip\ImagineBundle\Imagine\Data\Transformer\TransformerInterface;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Liip\ImagineBundle\Imagine\Data\Loader;
namespace Liip\ImagineBundle\Binary\Loader;

use Liip\ImagineBundle\Model\Binary;
use Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesser;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Liip\ImagineBundle\Imagine\Data\Loader;
namespace Liip\ImagineBundle\Binary\Loader;

use Doctrine\ODM\MongoDB\DocumentManager;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Liip\ImagineBundle\Imagine\Data\Loader;
namespace Liip\ImagineBundle\Binary\Loader;

interface LoaderInterface
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Liip\ImagineBundle\Imagine\Data\Loader;
namespace Liip\ImagineBundle\Binary\Loader;

use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/Compiler/LoadersCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function process(ContainerBuilder $container)
}
}

$tags = $container->findTaggedServiceIds('liip_imagine.data.loader');
$tags = $container->findTaggedServiceIds('liip_imagine.binary.loader');

if (count($tags) > 0 && $container->hasDefinition('liip_imagine.data.manager')) {
$manager = $container->getDefinition('liip_imagine.data.manager');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ class FileSystemLoaderFactory implements LoaderFactoryInterface
*/
public function create(ContainerBuilder $container, $loaderName, array $config)
{
$loaderDefinition = new DefinitionDecorator('liip_imagine.data.loader.prototype.filesystem');
$loaderDefinition = new DefinitionDecorator('liip_imagine.binary.loader.prototype.filesystem');
$loaderDefinition->replaceArgument(2, $config['data_root']);
$loaderDefinition->addTag('liip_imagine.data.loader', array(
$loaderDefinition->addTag('liip_imagine.binary.loader', array(
'loader' => $loaderName
));
$loaderId = 'liip_imagine.data.loader.'.$loaderName;
$loaderId = 'liip_imagine.binary.loader.'.$loaderName;

$container->setDefinition($loaderId, $loaderDefinition);

Expand Down
6 changes: 3 additions & 3 deletions DependencyInjection/Factory/Loader/StreamLoaderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ class StreamLoaderFactory implements LoaderFactoryInterface
*/
public function create(ContainerBuilder $container, $loaderName, array $config)
{
$loaderDefinition = new DefinitionDecorator('liip_imagine.data.loader.prototype.stream');
$loaderDefinition = new DefinitionDecorator('liip_imagine.binary.loader.prototype.stream');
$loaderDefinition->replaceArgument(0, $config['wrapper']);
$loaderDefinition->replaceArgument(1, $config['context']);
$loaderDefinition->addTag('liip_imagine.data.loader', array(
$loaderDefinition->addTag('liip_imagine.binary.loader', array(
'loader' => $loaderName
));
$loaderId = 'liip_imagine.data.loader.'.$loaderName;
$loaderId = 'liip_imagine.binary.loader.'.$loaderName;

$container->setDefinition($loaderId, $loaderDefinition);

Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/LiipImagineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function load(array $configs, ContainerBuilder $container)

$container->setParameter('liip_imagine.filter_sets', $config['filter_sets']);

$container->setParameter('liip_imagine.data.loader.default', $config['data_loader']);
$container->setParameter('liip_imagine.binary.loader.default', $config['data_loader']);

$container->setParameter('liip_imagine.controller_action', $config['controller_action']);

Expand Down
2 changes: 1 addition & 1 deletion Imagine/Data/DataManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Liip\ImagineBundle\Imagine\Data;

use Liip\ImagineBundle\Imagine\Data\Loader\LoaderInterface;
use Liip\ImagineBundle\Binary\Loader\LoaderInterface;
use Liip\ImagineBundle\Imagine\Filter\FilterConfiguration;
use Liip\ImagineBundle\Binary\MimeTypeGuesserInterface;
use Liip\ImagineBundle\Model\Binary;
Expand Down
10 changes: 5 additions & 5 deletions Resources/config/imagine.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@

<!-- Data loaders' classes -->

<parameter key="liip_imagine.data.loader.filesystem.class">Liip\ImagineBundle\Imagine\Data\Loader\FileSystemLoader</parameter>
<parameter key="liip_imagine.data.loader.stream.class">Liip\ImagineBundle\Imagine\Data\Loader\StreamLoader</parameter>
<parameter key="liip_imagine.binary.loader.filesystem.class">Liip\ImagineBundle\Binary\Loader\FileSystemLoader</parameter>
<parameter key="liip_imagine.binary.loader.stream.class">Liip\ImagineBundle\Binary\Loader\StreamLoader</parameter>

<!-- Cache resolvers' classes -->

Expand Down Expand Up @@ -76,7 +76,7 @@
<argument type="service" id="liip_imagine.binary.mime_type_guesser" />
<argument type="service" id="liip_imagine.extension_guesser" />
<argument type="service" id="liip_imagine.filter.configuration" />
<argument>%liip_imagine.data.loader.default%</argument>
<argument>%liip_imagine.binary.loader.default%</argument>
</service>

<service id="liip_imagine.cache.manager" class="%liip_imagine.cache.manager.class%">
Expand Down Expand Up @@ -179,13 +179,13 @@

<!-- Data loaders -->

<service id="liip_imagine.data.loader.prototype.filesystem" class="%liip_imagine.data.loader.filesystem.class%">
<service id="liip_imagine.binary.loader.prototype.filesystem" class="%liip_imagine.binary.loader.filesystem.class%">
<argument type="service" id="liip_imagine.mime_type_guesser" />
<argument type="service" id="liip_imagine.extension_guesser" />
<argument><!-- will be injected by FileSystemLoaderFactory --></argument>
</service>

<service id="liip_imagine.data.loader.prototype.stream" class="%liip_imagine.data.loader.stream.class%">
<service id="liip_imagine.binary.loader.prototype.stream" class="%liip_imagine.binary.loader.stream.class%">
<argument><!-- will be injected by StreamLoaderFactory --></argument>
<argument><!-- will be injected by StreamLoaderFactory --></argument>
</service>
Expand Down
4 changes: 2 additions & 2 deletions Resources/doc/data-loader/gridfs.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ liip_imagine:
Add loader to your services:
``` xml
<service id="liip_imagine.data.loader.grid_fs" class="Liip\ImagineBundle\Imagine\Data\Loader\GridFSLoader">
<tag name="liip_imagine.data.loader" loader="grid_fs" />
<service id="liip_imagine.binary.loader.grid_fs" class="Liip\ImagineBundle\Binary\Loader\GridFSLoader">
<tag name="liip_imagine.binary.loader" loader="grid_fs" />
<argument type="service" id="liip_imagine" />
<argument type="service" id="doctrine.odm.mongodb.document_manager" />
<argument>Application\ImageBundle\Document\Image</argument>
Expand Down
8 changes: 4 additions & 4 deletions Resources/doc/data-loader/stream.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ liip_imagine:
## Custom
The `Liip\ImagineBundle\Imagine\Data\Loader\StreamLoader` allows to read images from any stream registered
The `Liip\ImagineBundle\Binary\Loader\StreamLoader` allows to read images from any stream registered
thus allowing you to serve your images from literally anywhere.

The example service definition shows how to use a stream wrapped by the [Gaufrette](https://github.com/KnpLabs/Gaufrette) filesystem abstraction layer.
Expand All @@ -24,12 +24,12 @@ you can make use of the [StreamWrapper configuration](https://github.com/KnpLabs

``` yaml
services:
acme.liip_imagine.data.loader.stream.profile_photos:
class: "%liip_imagine.data.loader.stream.class%"
acme.liip_imagine.binary.loader.stream.profile_photos:
class: "%liip_imagine.binary.loader.stream.class%"
arguments:
- 'gaufrette://profile_photos/'
tags:
- { name: 'liip_imagine.data.loader', loader: 'stream.profile_photos' }
- { name: 'liip_imagine.binary.loader', loader: 'stream.profile_photos' }
```

## Usage
Expand Down
14 changes: 7 additions & 7 deletions Resources/doc/data-loaders.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
The ImagineBundle allows you to add your custom image loader classes. The only
requirement is that each data loader implement the following interface:

Liip\ImagineBundle\Imagine\Data\Loader\LoaderInterface
Liip\ImagineBundle\Binary\Loader\LoaderInterface

To tell the bundle about your new data loader, register it in the service
container and apply the `liip_imagine.data.loader` tag to it (example here in XML):
container and apply the `liip_imagine.binary.loader` tag to it (example here in XML):

``` xml
<service id="acme_imagine.data.loader.my_custom" class="Acme\ImagineBundle\Imagine\Data\Loader\MyCustomDataLoader">
<tag name="liip_imagine.data.loader" loader="my_custom_data" />
<service id="acme_imagine.data.loader.my_custom" class="Acme\ImagineBundle\Binary\Loader\MyCustomDataLoader">
<tag name="liip_imagine.binary.loader" loader="my_custom_data" />
<argument type="service" id="liip_imagine" />
</service>
```
Expand Down Expand Up @@ -51,13 +51,13 @@ liip_imagine:
For an example of a data loader implementation, refer to
`Liip\ImagineBundle\Imagine\Data\Loader\FileSystemLoader`.
`Liip\ImagineBundle\Binary\Loader\FileSystemLoader`.

## Extending the image loader with data transformers

You can extend a custom data loader to support virtually any file type using transformers.
A data tranformer is intended to transform a file before actually rendering it. You
can refer to `Liip\ImagineBundle\Imagine\Data\Loader\ExtendedFileSystemLoader` and
can refer to `Liip\ImagineBundle\Binary\Loader\ExtendedFileSystemLoader` and
to `Liip\ImagineBundle\Imagine\Data\Transformer\PdfTransformer` as an example.

ExtendedFileSystemLoader extends FileSystemLoader and takes, as argument, an array of transformers.
Expand All @@ -79,7 +79,7 @@ services:
custom_loader:
class: Acme\ImagineBundle\Imagine\Data\Loader\MyCustomDataLoader
tags:
- { name: liip_imagine.data.loader, loader: custom_data_loader }
- { name: liip_imagine.binary.loader, loader: custom_data_loader }
arguments:
- '@liip_imagine'
- %kernel.root_dir%/../web
Expand Down
4 changes: 2 additions & 2 deletions Resources/doc/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ There are several components involved to get this done.

The first step is to retrieve the original image, the one you address.

In order to retrieve such an image, there are so-called `DataLoader` those implement the `Liip\ImagineBundle\Imagine\Data\Loader\LoaderInterface`.
In order to retrieve such an image, there are so-called `DataLoader` those implement the `Liip\ImagineBundle\Binary\Loader\LoaderInterface`.
Those loaders are typically managed by the `DataManager` and automatically wired with it, using dependency injection.

How a specific `DataLoader` retrieves the image, is up to the loader. The most simple way is to read a file from the local filesystem. This is implemented by the `Liip\ImagineBundle\Imagine\Data\Loader\FileSystemLoader`, which is set by default.
How a specific `DataLoader` retrieves the image, is up to the loader. The most simple way is to read a file from the local filesystem. This is implemented by the `Liip\ImagineBundle\Binary\Loader\FileSystemLoader`, which is set by default.
You could also create a random image on the fly using drawing utilities, or read a binary stream from any stream registered.

The most important parts about those `DataLoader`:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace Liip\ImagineBundle\Tests\Imagine\Data\Loader;
namespace Liip\ImagineBundle\Tests\Binary\Loader;

use Liip\ImagineBundle\Imagine\Data\Loader\FileSystemLoader;
use Liip\ImagineBundle\Binary\Loader\FileSystemLoader;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesser;
use Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesserInterface;
Expand All @@ -20,16 +20,16 @@ public static function provideLoadCases()
array(__DIR__.'/', $fileName),
array(__DIR__, '/'.$fileName),
array(__DIR__.'/', '/'.$fileName),
array(realpath(__DIR__.'/../..'), 'Data/Loader/'.$fileName),
array(realpath(__DIR__.'/../../'), '/Data/Loader/'.$fileName),
array(realpath(__DIR__.'/..'), 'Loader/'.$fileName),
array(realpath(__DIR__.'/../'), '/Loader/'.$fileName),
);
}

public function testShouldImplementLoaderInterface()
{
$rc = new \ReflectionClass('Liip\ImagineBundle\Imagine\Data\Loader\FileSystemLoader');
$rc = new \ReflectionClass('Liip\ImagineBundle\Binary\Loader\FileSystemLoader');

$this->assertTrue($rc->implementsInterface('Liip\ImagineBundle\Imagine\Data\Loader\LoaderInterface'));
$this->assertTrue($rc->implementsInterface('Liip\ImagineBundle\Binary\Loader\LoaderInterface'));
}

public function testCouldBeConstructedWithExpectedArguments()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

namespace Liip\ImagineBundle\Tests\Imagine\Data\Loader;
namespace Liip\ImagineBundle\Tests\Binary\Loader;

use Liip\ImagineBundle\Imagine\Data\Loader\StreamLoader;
use Liip\ImagineBundle\Binary\Loader\StreamLoader;
use Liip\ImagineBundle\Tests\AbstractTest;

/**
* @covers Liip\ImagineBundle\Imagine\Data\Loader\StreamLoader
* @covers Liip\ImagineBundle\Binary\Loader\StreamLoader
*/
class StreamLoaderTest extends AbstractTest
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ public function testCreateLoaderDefinitionOnCreate()
'data_root' => 'theDataRoot',
));

$this->assertTrue($container->hasDefinition('liip_imagine.data.loader.theloadername'));
$this->assertTrue($container->hasDefinition('liip_imagine.binary.loader.theloadername'));

$loaderDefinition = $container->getDefinition('liip_imagine.data.loader.theloadername');
$loaderDefinition = $container->getDefinition('liip_imagine.binary.loader.theloadername');
$this->assertInstanceOf('Symfony\Component\DependencyInjection\DefinitionDecorator', $loaderDefinition);
$this->assertEquals('liip_imagine.data.loader.prototype.filesystem', $loaderDefinition->getParent());
$this->assertEquals('liip_imagine.binary.loader.prototype.filesystem', $loaderDefinition->getParent());

$this->assertEquals('theDataRoot', $loaderDefinition->getArgument(2));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ public function testCreateLoaderDefinitionOnCreate()
'context' => 'theContext',
));

$this->assertTrue($container->hasDefinition('liip_imagine.data.loader.theloadername'));
$this->assertTrue($container->hasDefinition('liip_imagine.binary.loader.theloadername'));

$loaderDefinition = $container->getDefinition('liip_imagine.data.loader.theloadername');
$loaderDefinition = $container->getDefinition('liip_imagine.binary.loader.theloadername');
$this->assertInstanceOf('Symfony\Component\DependencyInjection\DefinitionDecorator', $loaderDefinition);
$this->assertEquals('liip_imagine.data.loader.prototype.stream', $loaderDefinition->getParent());
$this->assertEquals('liip_imagine.binary.loader.prototype.stream', $loaderDefinition->getParent());

$this->assertEquals('theWrapper', $loaderDefinition->getArgument(0));
$this->assertEquals('theContext', $loaderDefinition->getArgument(1));
Expand Down
Binary file not shown.
4 changes: 2 additions & 2 deletions Tests/Imagine/Data/DataManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Liip\ImagineBundle\Tests\Imagine\Data;

use Liip\ImagineBundle\Imagine\Data\DataManager;
use Liip\ImagineBundle\Imagine\Data\Loader\LoaderInterface;
use Liip\ImagineBundle\Binary\Loader\LoaderInterface;
use Liip\ImagineBundle\Model\Binary;
use Liip\ImagineBundle\Tests\AbstractTest;

Expand Down Expand Up @@ -340,7 +340,7 @@ public function testShouldReturnBinaryWithLoaderContentAndGuessedFormatOnFind()
*/
protected function getMockLoader()
{
return $this->getMock('Liip\ImagineBundle\Imagine\Data\Loader\LoaderInterface');
return $this->getMock('Liip\ImagineBundle\Binary\Loader\LoaderInterface');
}

/**
Expand Down
6 changes: 6 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ Upgrade
* [Cache] `AbstractFilesystemResolver` was removed.
* [Data] `LoaderInterface::find` now can return string or `BinaryInterface` instance.
* [Data] `DataManager::find` now can return `BinaryInterface` instance only.
* [Data] All data loaders moved to `Binary/Loader` folder.
* [Data] Tag name `liip_imagine.data.loader` changed to `liip_imagine.binary.loader`
* [Data] Parameter key `liip_imagine.data.loader.filesystem.class` changed to `liip_imagine.binary.loader.filesystem.class`
* [Data] Parameter key `liip_imagine.data.loader.stream.class` changed to `liip_imagine.binary.loader.stream.class`
* [Data] Service id `liip_imagine.data.loader.prototype.filesystem` changed to `liip_imagine.binary.loader.prototype.filesystem`
* [Data] Service id `liip_imagine.data.loader.prototype.stream` changed to `liip_imagine.binary.loader.prototype.stream`
* [Filter] `FilterManager::applyFilter` now return instance of `BinaryInterface`.
* [Filter] `FilterManager::applyFilter` first argument was changed from Image instance to BinaryInterface one.
* [Filter] `FilterManager::get` was removed.
Expand Down

0 comments on commit bab39ad

Please sign in to comment.