|
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 string[] $dataRoots |
|
42
|
|
|
* @param LocatorInterface $locator |
|
|
|
|
|
|
43
|
|
|
*/ |
|
44
|
|
|
public function __construct( |
|
45
|
|
|
MimeTypeGuesserInterface $mimeGuesser, |
|
46
|
|
|
ExtensionGuesserInterface $extensionGuesser, |
|
47
|
|
|
$dataRoots |
|
48
|
|
|
/* LocatorInterface $locator */ |
|
49
|
|
|
) { |
|
50
|
|
|
$this->mimeTypeGuesser = $mimeGuesser; |
|
51
|
|
|
$this->extensionGuesser = $extensionGuesser; |
|
52
|
|
|
|
|
53
|
|
|
if (count($dataRoots) === 0) { |
|
54
|
|
|
throw new InvalidArgumentException('One or more data root paths must be specified.'); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
if (func_num_args() >= 4 && false === ($this->locator = func_get_arg(3)) instanceof LocatorInterface) { |
|
58
|
|
|
throw new \InvalidArgumentException(sprintf('Method %s() expects a LocatorInterface for the forth argument.', __METHOD__)); |
|
59
|
|
|
} elseif (func_num_args() < 4) { |
|
60
|
|
|
@trigger_error(sprintf('Method %s() will have a forth `LocatorInterface $locator` argument in version 2.0. Not defining it is deprecated since version 1.7.2', __METHOD__), E_USER_DEPRECATED); |
|
|
|
|
|
|
61
|
|
|
$this->locator = new FileSystemLocator(); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
$this->locator->setOptions(array('roots' => (array) $dataRoots)); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* {@inheritdoc} |
|
69
|
|
|
*/ |
|
70
|
|
|
public function find($path) |
|
71
|
|
|
{ |
|
72
|
|
|
$path = $this->locator->locate($path); |
|
73
|
|
|
$mime = $this->mimeTypeGuesser->guess($path); |
|
74
|
|
|
|
|
75
|
|
|
return new FileBinary($path, $mime, $this->extensionGuesser->guess($mime)); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.