1 | <?php |
||
25 | final class ProjectFactory implements ProjectFactoryInterface |
||
|
|||
26 | { |
||
27 | /** |
||
28 | * @var ProjectFactoryStrategies[] |
||
29 | */ |
||
30 | private $strategies; |
||
31 | |||
32 | /** |
||
33 | * Initializes the factory with a number of strategies. |
||
34 | * |
||
35 | * @param ProjectFactoryStrategy[] $strategies |
||
36 | */ |
||
37 | 1 | public function __construct($strategies) |
|
41 | |||
42 | /** |
||
43 | * Creates a new instance of this factory. With all default strategies. |
||
44 | * |
||
45 | * @return static; |
||
46 | */ |
||
47 | public static function createInstance() |
||
64 | |||
65 | /** |
||
66 | * Creates a project from the set of files. |
||
67 | * |
||
68 | * @param string $name |
||
69 | * @param string[] $files |
||
70 | * @return Project |
||
71 | * @throws Exception when no matching strategy was found. |
||
72 | */ |
||
73 | 9 | public function create($name, array $files) |
|
86 | |||
87 | /** |
||
88 | * Builds the namespace tree with all elements in the project. |
||
89 | * |
||
90 | * @param Project $project |
||
91 | */ |
||
92 | 8 | private function buildNamespaces(Project $project) |
|
93 | 1 | { |
|
94 | 8 | foreach ($project->getFiles() as $file) { |
|
95 | 8 | foreach ($file->getNamespaces() as $namespaceFqsen) { |
|
96 | 7 | $namespace = $this->getNamespaceByName($project, (string)$namespaceFqsen); |
|
97 | 7 | $this->buildNamespace($file, $namespace); |
|
98 | 8 | } |
|
99 | 8 | } |
|
100 | 8 | } |
|
101 | |||
102 | /** |
||
103 | * Gets Namespace from the project if it exists, otherwise returns a new namepace |
||
104 | * |
||
105 | * @param Project $project |
||
106 | * @param $name |
||
107 | * @return Namespace_ |
||
108 | */ |
||
109 | 7 | private function getNamespaceByName(Project $project, $name) |
|
121 | |||
122 | /** |
||
123 | * Adds all elements belonging to the namespace to the namespace. |
||
124 | * |
||
125 | * @param File $file |
||
126 | * @param Namespace_ $namespace |
||
127 | */ |
||
128 | 7 | private function buildNamespace(File $file, Namespace_ $namespace) |
|
160 | } |
||
161 |