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