1 | <?php |
||
10 | final class FileLocator implements FileLocatorInterface |
||
11 | { |
||
12 | /** |
||
13 | * Directories to search in. |
||
14 | * |
||
15 | * @var array |
||
16 | */ |
||
17 | private $directories = [ |
||
18 | 'model' => [], |
||
19 | 'mixin' => [], |
||
20 | 'embed' => [], |
||
21 | ]; |
||
22 | |||
23 | /** |
||
24 | * Constructor. |
||
25 | * |
||
26 | * @param string|array $modelDirs |
||
27 | * @param string|array $mixinDirs |
||
28 | * @param string|array $embedDirs |
||
29 | */ |
||
30 | public function __construct($modelDirs, $mixinDirs = [], $embedDirs = []) |
||
31 | { |
||
32 | $this->directories['model'] = (Array) $modelDirs; |
||
33 | $this->directories['mixin'] = (Array) $mixinDirs; |
||
34 | $this->directories['embed'] = (Array) $embedDirs; |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * Gets the directories to search in. |
||
39 | * |
||
40 | * @param string $type The directory type, either model or mixin. |
||
41 | * @return array |
||
42 | */ |
||
43 | protected function getDirectories($type) |
||
47 | |||
48 | /** |
||
49 | * {@inheritDoc} |
||
50 | */ |
||
51 | public function findFileForEmbed($embedName, $extension) |
||
52 | { |
||
53 | return $this->findFile('embed', $embedName, $extension); |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * {@inheritDoc} |
||
58 | */ |
||
59 | public function findFileForMixin($mixinName, $extension) |
||
63 | |||
64 | /** |
||
65 | * {@inheritDoc} |
||
66 | */ |
||
67 | public function findFileForType($modelType, $extension) |
||
71 | |||
72 | /** |
||
73 | * Finds a file based on a directory type (model or mixin) and a key. |
||
74 | * |
||
75 | * @param string $dirType |
||
76 | * @param string $key |
||
77 | * @param string $extension |
||
78 | * @return string|null |
||
79 | */ |
||
80 | protected function findFile($dirType, $key, $extension) |
||
90 | |||
91 | /** |
||
92 | * {@inheritDoc} |
||
93 | */ |
||
94 | public function findAllTypes($extension) |
||
113 | |||
114 | /** |
||
115 | * Gets the filename for a metadata entity or mixin. |
||
116 | * |
||
117 | * @param string $key |
||
118 | * @param string $extension |
||
119 | * @return string |
||
120 | */ |
||
121 | protected function getFilename($key, $extension) |
||
125 | } |
||
126 |