1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of phpDocumentor. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
* |
8
|
|
|
* @copyright 2010-2017 Mike van Riel<[email protected]> |
9
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
10
|
|
|
* @link http://phpdoc.org |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace phpDocumentor\Infrastructure\Parser; |
14
|
|
|
|
15
|
|
|
use phpDocumentor\DomainModel\Dsn; |
16
|
|
|
use phpDocumentor\DomainModel\Parser\FileCollector; |
17
|
|
|
use phpDocumentor\Infrastructure\FlySystemFactory; |
18
|
|
|
use phpDocumentor\Infrastructure\SpecificationFactory; |
|
|
|
|
19
|
|
|
use phpDocumentor\Reflection\File; |
20
|
|
|
|
21
|
|
|
final class FlySystemCollector implements FileCollector |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var SpecificationFactory |
25
|
|
|
*/ |
26
|
|
|
private $specificationFactory; |
27
|
|
|
/** |
28
|
|
|
* @var FlySystemFactory |
29
|
|
|
*/ |
30
|
|
|
private $flySystemFactory; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* FlySystemCollector constructor. |
34
|
|
|
* @param SpecificationFactory $specificationFactory |
35
|
|
|
* @param FlySystemFactory $flySystemFactory |
36
|
|
|
*/ |
37
|
|
|
public function __construct(SpecificationFactory $specificationFactory, FlySystemFactory $flySystemFactory) |
38
|
|
|
{ |
39
|
|
|
$this->specificationFactory = $specificationFactory; |
40
|
|
|
$this->flySystemFactory = $flySystemFactory; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function getFiles(Dsn $dsn, array $paths, array $ignore, array $extensions): array |
44
|
|
|
{ |
45
|
|
|
$specs = $this->specificationFactory->create($paths, $ignore, $extensions); |
46
|
|
|
|
47
|
|
|
$fileSystems = []; |
48
|
|
|
|
49
|
|
|
$fileSystems[] = $this->flySystemFactory->create($dsn); |
50
|
|
|
|
51
|
|
|
$files = []; |
52
|
|
|
foreach ($fileSystems as $fileSystem) { |
53
|
|
|
$result = $fileSystem->find($specs); |
54
|
|
|
foreach ($result as $file) { |
55
|
|
|
$files[] = new FlySystemFile($fileSystem, $file['path']); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return $files; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
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: