1 | <?php |
||
43 | final class File implements ProjectFactoryStrategy |
||
|
|||
44 | { |
||
45 | /** |
||
46 | * @var NodesFactory |
||
47 | */ |
||
48 | private $nodesFactory; |
||
49 | |||
50 | /** |
||
51 | * @var Adapter |
||
52 | */ |
||
53 | private $adapter; |
||
54 | |||
55 | /** |
||
56 | * Initializes the object. |
||
57 | * |
||
58 | * @param NodesFactory $nodesFactory |
||
59 | * @param Adapter $adapter |
||
60 | * @param Middleware[] $middleware |
||
61 | */ |
||
62 | 9 | public function __construct(NodesFactory $nodesFactory, Adapter $adapter = null, $middleware = array()) |
|
63 | { |
||
64 | 9 | if ($adapter === null) { |
|
65 | 9 | $adapter = new LocalAdapter(); |
|
66 | } |
||
67 | |||
68 | 9 | $this->nodesFactory = $nodesFactory; |
|
69 | 9 | $this->adapter = $adapter; |
|
70 | |||
71 | 9 | $lastCallable = function ($command) { |
|
72 | 5 | return $this->createFile($command); |
|
73 | 9 | }; |
|
74 | |||
75 | 9 | $this->middlewareChain = ChainFactory::createExecutionChain($middleware, $lastCallable); |
|
76 | 9 | } |
|
77 | |||
78 | /** |
||
79 | * Returns true when the strategy is able to handle the object. |
||
80 | * |
||
81 | * @param string $filePath path to check. |
||
82 | * @return boolean |
||
83 | */ |
||
84 | 1 | public function matches($filePath) |
|
88 | |||
89 | /** |
||
90 | * Creates an File out of the given object. |
||
91 | * Since an object might contain other objects that need to be converted the $factory is passed so it can be |
||
92 | * used to create nested Elements. |
||
93 | * |
||
94 | * @param string $object path to the file to convert to an File object. |
||
95 | * @param StrategyContainer $strategies used to convert nested objects. |
||
96 | * @param Context $context |
||
97 | * @return File |
||
98 | */ |
||
99 | 7 | public function create($object, StrategyContainer $strategies, Context $context = null) |
|
115 | |||
116 | /** |
||
117 | * @param $object |
||
118 | * @param StrategyContainer $strategies |
||
119 | * @return FileElement |
||
120 | */ |
||
121 | 5 | private function createFile(CreateCommand $command) |
|
138 | |||
139 | /** |
||
140 | * @param Fqsen $namespace |
||
141 | * @param Node[] $nodes |
||
142 | * @param FileElement $file |
||
143 | * @param StrategyContainer $strategies |
||
144 | */ |
||
145 | 5 | private function createElements(Fqsen $namespace, $nodes, FileElement $file, StrategyContainer $strategies) |
|
178 | /** |
||
179 | * @param StrategyContainer $strategies |
||
180 | * @param $code |
||
181 | * @param $nodes |
||
182 | * @return null|\phpDocumentor\Reflection\Element |
||
183 | * @internal param Context $context |
||
184 | */ |
||
185 | 5 | private function createDocBlock(StrategyContainer $strategies, $code, $nodes) |
|
208 | } |
||
209 |