Skip to content

Commit

Permalink
Merge pull request #134 from Burgov/master
Browse files Browse the repository at this point in the history
Added a data loader for PHPCR
  • Loading branch information
lsmith77 committed Feb 5, 2013
2 parents c35ba16 + 335c3f6 commit 7a29c08
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
56 changes: 56 additions & 0 deletions Imagine/Data/Loader/PHPCRLoader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace Liip\ImagineBundle\Imagine\Data\Loader;

use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

use Imagine\Image\ImagineInterface;
use Doctrine\ODM\PHPCR\DocumentManager;

class PHPCRLoader implements LoaderInterface
{
/**
* @var Imagine\Image\ImagineInterface
*/
protected $imagine;

/**
* @var Doctrine\ODM\PHPCR\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->find($this->class, $id);

if (!$image) {
throw new NotFoundHttpException(sprintf('Source image not found with id "%s"', $id));
}

return $this->imagine->load(stream_get_contents($image->getContent()));
}
}
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,21 @@ Reference the image by its id
<img src="{{ image.id | imagine_filter('my_thumb') }}" />
```

### PHPCRLoader
Load images from PHPCR

This loader works the same as the GridFS loader with some minor changes in the
service definition:

``` xml
<service id="liip_imagine.data.loader.phpcr" class="Liip\ImagineBundle\Imagine\Data\Loader\PHPCRLoader">
<tag name="liip_imagine.data.loader" loader="phpcr" />
<argument type="service" id="liip_imagine" />
<argument type="service" id="doctrine_phpcr.odm.document_manager" />
<argument>%symfony_cmf_create.image.model_class%</argument>
</service>
```

## Extending the image loader with data transformers

You can extend a custom data loader to support virtually any file type using transformers.
Expand Down

0 comments on commit 7a29c08

Please sign in to comment.