Completed
Push — master ( 0a7932...aee286 )
by Maksim
13s
created

GridFSLoader::find()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 12
rs 9.4285
cc 2
eloc 7
nc 2
nop 1
1
<?php
2
3
namespace Liip\ImagineBundle\Binary\Loader;
4
5
use Doctrine\ODM\MongoDB\DocumentManager;
6
use Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException;
7
8
class GridFSLoader implements LoaderInterface
9
{
10
    /**
11
     * @var DocumentManager
12
     */
13
    protected $dm;
14
15
    /**
16
     * @var string
17
     */
18
    protected $class;
19
20
    /**
21
     * @param DocumentManager $dm
22
     * @param string          $class
23
     */
24
    public function __construct(DocumentManager $dm, $class)
25
    {
26
        $this->dm = $dm;
27
        $this->class = $class;
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function find($id)
34
    {
35
        $image = $this->dm
36
            ->getRepository($this->class)
37
            ->find(new \MongoId($id));
38
39
        if (!$image) {
40
            throw new NotLoadableException(sprintf('Source image was not found with id "%s"', $id));
41
        }
42
43
        return $image->getFile()->getBytes();
44
    }
45
}
46