1 | <?php declare(strict_types=1); |
||
9 | class ResourceGenerator |
||
10 | { |
||
11 | /** |
||
12 | * @var callable |
||
13 | */ |
||
14 | protected $out = 'ApiClients\Tools\ResourceGenerator\outln'; |
||
15 | |||
16 | /** |
||
17 | * @var array |
||
18 | */ |
||
19 | protected $configuration; |
||
20 | |||
21 | /** |
||
22 | * @var FileGeneratorInterface[] |
||
23 | */ |
||
24 | protected $generators = []; |
||
25 | |||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $pathSrc; |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | protected $pathTests; |
||
35 | |||
36 | /** |
||
37 | * @var Fixer |
||
38 | */ |
||
39 | protected $fixer; |
||
40 | |||
41 | /** |
||
42 | * @var array |
||
43 | */ |
||
44 | protected $fixers; |
||
45 | |||
46 | 1 | public function __construct(array $configuration, callable $out = null) |
|
55 | |||
56 | 1 | public function run() |
|
66 | |||
67 | 1 | protected function applyAnnotationsToDefinition(array $definition): array |
|
102 | |||
103 | /** |
||
104 | * @param array $file |
||
105 | * @throws Exception |
||
106 | */ |
||
107 | 1 | protected function generateFromDefinition(array $file) |
|
134 | |||
135 | /** |
||
136 | * @param Node $node |
||
137 | * @return string |
||
138 | */ |
||
139 | 1 | protected function printCode(Node $node): string |
|
147 | |||
148 | /** |
||
149 | * @param string $fileName |
||
150 | * @param string $fileContents |
||
151 | * @throws Exception |
||
152 | * @return bool |
||
153 | */ |
||
154 | 1 | protected function save(string $fileName, string $fileContents) |
|
155 | { |
||
156 | 1 | $fileName = $this->configuration['root'] . $fileName; |
|
157 | |||
158 | 1 | if (file_exists($fileName)) { |
|
159 | $this->out('-- Exists'); |
||
160 | |||
161 | return false; |
||
162 | } |
||
163 | |||
164 | 1 | $directory = dirname($fileName); |
|
165 | 1 | if (!file_exists($directory)) { |
|
166 | 1 | mkdir($directory, 0755, true); |
|
167 | } |
||
168 | |||
169 | 1 | if (!file_exists($directory)) { |
|
170 | throw new Exception('Unable to create: ' . $directory); |
||
171 | } |
||
172 | |||
173 | 1 | file_put_contents($fileName, $fileContents); |
|
174 | |||
175 | do { |
||
176 | 1 | usleep(500); |
|
177 | 1 | } while (!file_exists($fileName)); |
|
178 | |||
179 | 1 | return true; |
|
180 | } |
||
181 | |||
182 | /** |
||
183 | * @param string $fileName |
||
184 | */ |
||
185 | 1 | protected function applyPsr2($fileName) |
|
199 | |||
200 | 1 | private function out(string $message) |
|
205 | } |
||
206 |