Completed
Push — 2.0 ( 6cd6ae...d9081a )
by Rob
11s
created

FileSystemLoader::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 4
1
<?php
2
3
/*
4
 * This file is part of the `liip/LiipImagineBundle` project.
5
 *
6
 * (c) https://github.com/liip/LiipImagineBundle/graphs/contributors
7
 *
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Liip\ImagineBundle\Binary\Loader;
13
14
use Liip\ImagineBundle\Binary\Locator\FileSystemLocator;
15
use Liip\ImagineBundle\Binary\Locator\LocatorInterface;
16
use Liip\ImagineBundle\Exception\InvalidArgumentException;
17
use Liip\ImagineBundle\Model\FileBinary;
18
use Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesserInterface;
19
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface;
20
21
class FileSystemLoader implements LoaderInterface
22
{
23
    /**
24
     * @var MimeTypeGuesserInterface
25
     */
26
    protected $mimeTypeGuesser;
27
28
    /**
29
     * @var ExtensionGuesserInterface
30
     */
31
    protected $extensionGuesser;
32
33
    /**
34
     * @var LocatorInterface
35
     */
36
    protected $locator;
37
38
    /**
39
     * @param MimeTypeGuesserInterface  $mimeGuesser
40
     * @param ExtensionGuesserInterface $extensionGuesser
41
     * @param LocatorInterface          $locator
42
     * @param string[]                  $rootPaths
43
     */
44
    public function __construct(
45
        MimeTypeGuesserInterface $mimeGuesser,
46
        ExtensionGuesserInterface $extensionGuesser,
47
        LocatorInterface $locator,
48
        array $rootPaths = []
49
    ) {
50
        $this->mimeTypeGuesser = $mimeGuesser;
51
        $this->extensionGuesser = $extensionGuesser;
52
        $this->locator = $locator;
53
        $this->locator->setOptions(['roots' => $rootPaths]);
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function find($path)
60
    {
61
        $path = $this->locator->locate($path);
62
        $mime = $this->mimeTypeGuesser->guess($path);
63
64
        return new FileBinary($path, $mime, $this->extensionGuesser->guess($mime));
65
    }
66
}
67