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
|
|
|
* @copyright 2010-2018 Mike van Riel<[email protected]> |
11
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
12
|
|
|
* @link http://phpdoc.org |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace phpDocumentor\Reflection\Php; |
16
|
|
|
|
17
|
|
|
use phpDocumentor\Reflection\Fqsen; |
18
|
|
|
use phpDocumentor\Reflection\Project as ProjectInterface; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Represents the entire project with its files, namespaces and indexes. |
22
|
|
|
*/ |
23
|
|
|
final class Project implements ProjectInterface |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
private $name = ''; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var Namespace_|null |
32
|
|
|
*/ |
33
|
|
|
private $rootNamespace; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var File[] |
37
|
|
|
*/ |
38
|
|
|
private $files = []; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var Namespace_[] |
42
|
|
|
*/ |
43
|
|
|
private $namespaces = []; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Initializes this descriptor. |
47
|
|
|
* |
48
|
|
|
* @param string $name Name of the current project. |
49
|
|
|
* @param null|Namespace_ $namespace Root namespace of the project. |
50
|
|
|
*/ |
51
|
2 |
|
public function __construct(string $name, ?Namespace_ $namespace = null) |
52
|
|
|
{ |
53
|
2 |
|
$this->name = $name; |
54
|
2 |
|
$this->rootNamespace = $namespace; |
55
|
2 |
|
if ($this->rootNamespace === null) { |
56
|
2 |
|
$this->rootNamespace = new Namespace_(new Fqsen('\\')); |
57
|
|
|
} |
58
|
2 |
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Returns the name of this project. |
62
|
|
|
*/ |
63
|
1 |
|
public function getName(): string |
64
|
|
|
{ |
65
|
1 |
|
return $this->name; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Returns all files with their sub-elements. |
70
|
|
|
* |
71
|
|
|
* @return File[] |
72
|
|
|
*/ |
73
|
1 |
|
public function getFiles(): array |
74
|
|
|
{ |
75
|
1 |
|
return $this->files; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Add a file to this project. |
80
|
|
|
*/ |
81
|
1 |
|
public function addFile(File $file): void |
82
|
|
|
{ |
83
|
1 |
|
$this->files[$file->getPath()] = $file; |
84
|
1 |
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Returns all namespaces with their sub-elements. |
88
|
|
|
* |
89
|
|
|
* @return Namespace_[] |
90
|
|
|
*/ |
91
|
1 |
|
public function getNamespaces(): array |
92
|
|
|
{ |
93
|
1 |
|
return $this->namespaces; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Add a namespace to the project. |
98
|
|
|
*/ |
99
|
1 |
|
public function addNamespace(Namespace_ $namespace): void |
100
|
|
|
{ |
101
|
1 |
|
$this->namespaces[(string) $namespace->getFqsen()] = $namespace; |
102
|
1 |
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Returns the root (global) namespace. |
106
|
|
|
*/ |
107
|
1 |
|
public function getRootNamespace(): ?Namespace_ |
108
|
|
|
{ |
109
|
1 |
|
return $this->rootNamespace; |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|