Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added GridFS loader

  • Loading branch information...
commit 86c166ac88f5e714436533e6eeee06bc4036b3ff 1 parent 455fe60
@jdewit jdewit authored
View
1  DependencyInjection/Configuration.php
@@ -34,6 +34,7 @@ public function getConfigTreeBuilder()
->scalarNode('cache_base_path')->defaultValue('')->end()
->scalarNode('data_loader')->defaultValue('filesystem')->end()
->scalarNode('controller_action')->defaultValue('liip_imagine.controller:filterAction')->end()
+ ->scalarNode('image_class')->defaultNull()->end()
->arrayNode('formats')
->defaultValue(array())
->prototype('scalar')->end()
View
2  DependencyInjection/LiipImagineExtension.php
@@ -45,6 +45,8 @@ public function load(array $configs, ContainerBuilder $container)
$container->setParameter('liip_imagine.controller_action', $config['controller_action']);
+ $container->setParameter('liip_imagine.image_class', $config['image_class']);
+
if ('2' == Kernel::MAJOR_VERSION && '0' == Kernel::MINOR_VERSION) {
$container->removeDefinition('liip_imagine.cache.clearer');
}
View
60 Imagine/Data/Loader/GridFSLoader.php
@@ -0,0 +1,60 @@
+<?php
+
+namespace Liip\ImagineBundle\Imagine\Data\Loader;
+
+use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
+
+use Imagine\Image\ImagineInterface;
+use Doctrine\ODM\MongoDB\DocumentManager;
+
+class GridFSLoader implements LoaderInterface
+{
+ /**
+ * @var Imagine\Image\ImagineInterface
+ */
+ protected $imagine;
+
+ /**
+ * @var Doctrine\ODM\MongoDB\DocumentManager
+ */
+ protected $dm;
+
+ /**
+ * @var Image Class
+ */
+ protected $class;
+
+ /**
+ * Constructs
+ *
+ * @param ImagineInterface $imagine
+ * @param DocumentManager $dm
+ * @param string Image class
+ */
+ public function __construct(ImagineInterface $imagine, DocumentManager $dm, $class)
+ {
+ $this->imagine = $imagine;
+ $this->dm = $dm;
+ $this->class = $class;
+ }
+
+ /**
+ * @param string $id
+ *
+ * @return Imagine\Image\ImageInterface
+ */
+ public function find($id)
+ {
+ $image = $this->dm
+ ->getRepository($this->class)
+ ->findAll()
+ ->getCollection()
+ ->findOne(array("_id" => new \MongoId($id)));
+
+ if (!$image) {
+ throw new NotFoundHttpException(sprintf('Source image not found with id "%s"', $id));
+ }
+
+ return $this->imagine->load($image['file']->getBytes());
+ }
+}
View
17 README.md
@@ -443,6 +443,23 @@ services:
- { name: 'liip_imagine.data.loader', loader: 'stream.profile_photos' }
```
+### GridFSLoader
+Load your images from mongodb
+``` yaml
+liip_imagine:
+ image_class: Application\ImageBundle\Document\Image
+ filter_sets:
+ my_special_style:
+ data_loader: grid_fs
+ filters:
+ my_custom_filter: { }
+```
+
+Reference the image by its id
+``` jinja
+<img src="{{ image.id | imagine_filter('my_thumb') }}" />
+```
+
## Extending the image loader with data transformers
You can extend a custom data loader to support virtually any file type using transformers.
View
11 Resources/config/imagine.xml
@@ -144,6 +144,13 @@
<argument>%liip_imagine.data_root%</argument>
</service>
+ <service id="liip_imagine.data.loader.grid_fs" class="Liip\ImagineBundle\Imagine\Data\Loader\GridFSLoader">
+ <tag name="liip_imagine.data.loader" loader="grid_fs" />
+ <argument type="service" id="liip_imagine" />
+ <argument type="service" id="doctrine.odm.mongodb.document_manager" />
+ <argument>%liip_imagine.image_class%</argument>
+ </service>
+
<!-- Cache resolver -->
<service id="liip_imagine.cache.resolver.web_path" class="%liip_imagine.cache.resolver.web_path.class%">
@@ -160,12 +167,12 @@
</service>
<!-- Cache Clearer -->
-
+
<service id="liip_imagine.cache.clearer" class="%liip_imagine.cache.clearer.class%">
<tag name="kernel.cache_clearer" />
<argument type="service" id="liip_imagine.cache.manager" />
<argument>%liip_imagine.cache_prefix%</argument>
</service>
-
+
</services>
</container>
Please sign in to comment.
Something went wrong with that request. Please try again.