|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the puli/symfony-bridge package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Bernhard Schussek <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Puli\SymfonyBridge\Config; |
|
13
|
|
|
|
|
14
|
|
|
use InvalidArgumentException; |
|
15
|
|
|
use Symfony\Component\Config\FileLocatorInterface; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @since 1.0 |
|
19
|
|
|
* |
|
20
|
|
|
* @author Bernhard Schussek <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
class FileLocatorChain implements FileLocatorInterface |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @var ChainableFileLocator[] |
|
26
|
|
|
*/ |
|
27
|
|
|
private $locators = array(); |
|
28
|
|
|
|
|
29
|
3 |
|
public function __construct(array $locators = array()) |
|
30
|
|
|
{ |
|
31
|
3 |
|
foreach ($locators as $locator) { |
|
32
|
3 |
|
$this->addLocator($locator); |
|
33
|
|
|
} |
|
34
|
3 |
|
} |
|
35
|
|
|
|
|
36
|
3 |
|
public function addLocator(ChainableFileLocator $locator) |
|
37
|
|
|
{ |
|
38
|
3 |
|
$this->locators[] = $locator; |
|
39
|
3 |
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Returns a full path for a given file name. |
|
43
|
|
|
* |
|
44
|
|
|
* @param mixed $name The file name to locate |
|
45
|
|
|
* @param string $currentPath The current path |
|
|
|
|
|
|
46
|
|
|
* @param bool $first Whether to return the first occurrence or an array of filenames |
|
47
|
|
|
* |
|
48
|
|
|
* @return string|array The full path to the file|An array of file paths |
|
49
|
|
|
* |
|
50
|
|
|
* @throws InvalidArgumentException When file is not found |
|
51
|
|
|
*/ |
|
52
|
3 |
|
public function locate($name, $currentPath = null, $first = true) |
|
53
|
|
|
{ |
|
54
|
3 |
|
foreach ($this->locators as $locator) { |
|
55
|
3 |
|
if ($locator->supports($name)) { |
|
56
|
3 |
|
return $locator->locate($name, $currentPath, $first); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
1 |
|
throw new InvalidArgumentException(sprintf( |
|
61
|
1 |
|
'The file "%s" could not be found.', |
|
62
|
|
|
$name |
|
63
|
|
|
)); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.