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[] $locatorOrDataRoots |
42
|
|
|
* @param LocatorInterface $locator |
|
|
|
|
43
|
|
|
*/ |
44
|
|
|
public function __construct( |
45
|
|
|
MimeTypeGuesserInterface $mimeGuesser, |
46
|
|
|
ExtensionGuesserInterface $extensionGuesser, |
47
|
|
|
$locatorOrDataRoots |
48
|
|
|
/* LocatorInterface $locator */ |
49
|
|
|
) { |
50
|
|
|
$this->mimeTypeGuesser = $mimeGuesser; |
51
|
|
|
$this->extensionGuesser = $extensionGuesser; |
52
|
|
|
|
53
|
|
|
if (is_array($locatorOrDataRoots) || is_string($locatorOrDataRoots)) { // pre-1.9.0 behaviour |
54
|
|
|
if (count((array) $locatorOrDataRoots) === 0) { |
55
|
|
|
throw new InvalidArgumentException('One or more data root paths must be specified.'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
if (func_num_args() >= 4) { |
59
|
|
|
if (func_get_arg(3) instanceof LocatorInterface) { |
60
|
|
|
@trigger_error( |
|
|
|
|
61
|
|
|
sprintf( |
62
|
|
|
'Passing a LocatorInterface as fourth parameter to %s() is deprecated. It needs to be the third parameter. ' . |
63
|
|
|
'The previous third parameter (data roots) is removed and the data roots must now be passed as a constructor argument ' . |
64
|
|
|
'to the LocatorInterface passed to this method.', |
65
|
|
|
__METHOD__ |
66
|
|
|
), |
67
|
|
|
E_USER_DEPRECATED |
68
|
|
|
); |
69
|
|
|
|
70
|
|
|
$this->locator = func_get_arg(3); |
71
|
|
|
$this->locator->setOptions(array('roots' => (array) $locatorOrDataRoots)); |
72
|
|
|
} else { |
73
|
|
|
throw new \InvalidArgumentException(sprintf('Unknown call to %s(). Please check the method signature.', __METHOD__)); |
74
|
|
|
} |
75
|
|
|
} else { |
76
|
|
|
@trigger_error( |
|
|
|
|
77
|
|
|
sprintf( |
78
|
|
|
'Method %s() will expect the third parameter to be a LocatorInterface in version 2.0. Defining dataroots instead is deprecated since version 1.9.0', |
79
|
|
|
__METHOD__ |
80
|
|
|
), |
81
|
|
|
E_USER_DEPRECATED |
82
|
|
|
); |
83
|
|
|
|
84
|
|
|
$this->locator = new FileSystemLocator((array) $locatorOrDataRoots); |
85
|
|
|
} |
86
|
|
|
} elseif ($locatorOrDataRoots instanceof LocatorInterface) { |
87
|
|
|
$this->locator = $locatorOrDataRoots; |
88
|
|
|
} else { |
89
|
|
|
throw new \InvalidArgumentException(sprintf('Method %s() expects a LocatorInterface for the third argument.', __METHOD__)); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* {@inheritdoc} |
95
|
|
|
*/ |
96
|
|
|
public function find($path) |
97
|
|
|
{ |
98
|
|
|
$path = $this->locator->locate($path); |
99
|
|
|
$mime = $this->mimeTypeGuesser->guess($path); |
100
|
|
|
|
101
|
|
|
return new FileBinary($path, $mime, $this->extensionGuesser->guess($mime)); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$ireland
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was changed, but the annotation was not.