1 | <?php |
||
42 | final class File extends AbstractFactory implements ProjectFactoryStrategy |
||
|
|||
43 | { |
||
44 | /** |
||
45 | * @var NodesFactory |
||
46 | */ |
||
47 | private $nodesFactory; |
||
48 | |||
49 | /** |
||
50 | * Initializes the object. |
||
51 | * |
||
52 | * @param NodesFactory $nodesFactory |
||
53 | * @param Middleware[] $middleware |
||
54 | */ |
||
55 | 12 | public function __construct(NodesFactory $nodesFactory, $middleware = array()) |
|
56 | { |
||
57 | 12 | $this->nodesFactory = $nodesFactory; |
|
58 | |||
59 | 12 | $lastCallable = function ($command) { |
|
60 | 8 | return $this->createFile($command); |
|
61 | 12 | }; |
|
62 | |||
63 | 12 | $this->middlewareChain = ChainFactory::createExecutionChain($middleware, $lastCallable); |
|
64 | 12 | } |
|
65 | |||
66 | /** |
||
67 | * Returns true when the strategy is able to handle the object. |
||
68 | * |
||
69 | * @param string $file path to check. |
||
70 | * @return boolean |
||
71 | */ |
||
72 | 1 | public function matches($file) |
|
73 | { |
||
74 | 1 | return $file instanceof FileSystemFile; |
|
75 | } |
||
76 | |||
77 | /** |
||
78 | * Creates an File out of the given object. |
||
79 | * Since an object might contain other objects that need to be converted the $factory is passed so it can be |
||
80 | * used to create nested Elements. |
||
81 | * |
||
82 | * @param FileSystemFile $object path to the file to convert to an File object. |
||
83 | * @param StrategyContainer $strategies used to convert nested objects. |
||
84 | * @param Context $context |
||
85 | * @return File |
||
86 | */ |
||
87 | 9 | protected function doCreate($object, StrategyContainer $strategies, Context $context = null) |
|
88 | { |
||
89 | 9 | $command = new CreateCommand($object, $strategies); |
|
90 | 9 | $middlewareChain = $this->middlewareChain; |
|
91 | |||
92 | 9 | return $middlewareChain($command); |
|
93 | } |
||
94 | |||
95 | /** |
||
96 | * @param CreateCommand $command |
||
97 | * @return FileElement |
||
98 | */ |
||
99 | 8 | private function createFile(CreateCommand $command) |
|
121 | |||
122 | /** |
||
123 | * @param Fqsen $namespace |
||
124 | * @param Node[] $nodes |
||
125 | * @param FileElement $file |
||
126 | * @param StrategyContainer $strategies |
||
127 | */ |
||
128 | 8 | private function createElements(Fqsen $namespace, $nodes, FileElement $file, StrategyContainer $strategies) |
|
161 | |||
162 | /** |
||
163 | * @param Doc $docBlock |
||
164 | * @param StrategyContainer $strategies |
||
165 | * @param Context $context |
||
166 | * @param Node[] $nodes |
||
167 | * @return null|\phpDocumentor\Reflection\Element |
||
168 | */ |
||
169 | 8 | protected function createFileDocBlock( |
|
210 | } |
||
211 |