1 | <?php namespace Nord\Lumen\FileManager; |
||
16 | class FileManager implements FileManagerContract |
||
17 | { |
||
18 | |||
19 | /** |
||
20 | * @var FilesystemFactory |
||
21 | */ |
||
22 | private $filesystem; |
||
23 | |||
24 | /** |
||
25 | * @var FileFactory |
||
26 | */ |
||
27 | private $factory; |
||
28 | |||
29 | /** |
||
30 | * @var FileStorage |
||
31 | */ |
||
32 | private $storage; |
||
33 | |||
34 | /** |
||
35 | * @var IdGenerator |
||
36 | */ |
||
37 | private $idGenerator; |
||
38 | |||
39 | /** |
||
40 | * @var DiskAdapter[] |
||
41 | */ |
||
42 | private $adapters = []; |
||
43 | |||
44 | |||
45 | /** |
||
46 | * FileManager constructor. |
||
47 | * |
||
48 | * @param FilesystemFactory $filesystem |
||
49 | * @param FileFactory $factory |
||
50 | * @param FileStorage $storage |
||
51 | */ |
||
52 | public function __construct(FilesystemFactory $filesystem, FileFactory $factory, FileStorage $storage) |
||
58 | |||
59 | |||
60 | /** |
||
61 | * @inheritdoc |
||
62 | */ |
||
63 | public function saveFile(FileInfo $info, array $options = []) |
||
100 | |||
101 | |||
102 | /** |
||
103 | * @inheritdoc |
||
104 | */ |
||
105 | public function getFile($id) |
||
109 | |||
110 | |||
111 | /** |
||
112 | * @inheritdoc |
||
113 | */ |
||
114 | public function getFilePath(FileContract $file, array $options = []) |
||
118 | |||
119 | |||
120 | /** |
||
121 | * @inheritdoc |
||
122 | */ |
||
123 | public function getFileUrl(FileContract $file, array $options = []) |
||
127 | |||
128 | |||
129 | /** |
||
130 | * @inheritdoc |
||
131 | */ |
||
132 | public function deleteFile(FileContract $file, array $options = []) |
||
142 | |||
143 | |||
144 | /** |
||
145 | * @param DiskAdapter $adapter |
||
146 | */ |
||
147 | public function addAdapter(DiskAdapter $adapter) |
||
155 | |||
156 | |||
157 | /** |
||
158 | * @param IdGenerator $idGenerator |
||
159 | */ |
||
160 | public function setIdGenerator(IdGenerator $idGenerator) |
||
164 | |||
165 | |||
166 | /** |
||
167 | * @param string $name |
||
168 | * |
||
169 | * @return DiskAdapter |
||
170 | * @throws AdapterException |
||
171 | */ |
||
172 | protected function getAdapter($name) |
||
180 | |||
181 | |||
182 | /** |
||
183 | * @return mixed |
||
184 | */ |
||
185 | protected function generateId() |
||
193 | |||
194 | |||
195 | /** |
||
196 | * @param string $name |
||
197 | * |
||
198 | * @return string |
||
199 | */ |
||
200 | protected function normalizeName($name) |
||
204 | |||
205 | |||
206 | /** |
||
207 | * @param FileInfo $info |
||
208 | * |
||
209 | * @return null|string |
||
210 | */ |
||
211 | protected function getFilenameFromFileInfo(FileInfo $info) |
||
215 | |||
216 | |||
217 | /** |
||
218 | * @param FileInfo $info |
||
219 | * |
||
220 | * @return string |
||
221 | */ |
||
222 | protected function getExtensionFromFileInfo(FileInfo $info) |
||
226 | |||
227 | |||
228 | /** |
||
229 | * @param FileInfo $info |
||
230 | * |
||
231 | * @return array |
||
232 | */ |
||
233 | protected function extractDataFromFileInfo(FileInfo $info) |
||
244 | } |
||
245 |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: