|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Micro framework package. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Stanislau Komar <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Micro\Library\DTO\Generator; |
|
15
|
|
|
|
|
16
|
|
|
use Micro\Library\DTO\ClassDef\ClassDefinition; |
|
17
|
|
|
use Micro\Library\DTO\Preparation\CollectionPreparationInterface; |
|
18
|
|
|
use Micro\Library\DTO\Reader\ReaderInterface; |
|
19
|
|
|
use Micro\Library\DTO\View\RendererInterface; |
|
20
|
|
|
use Micro\Library\DTO\Writer\WriterInterface; |
|
21
|
|
|
use Psr\Log\LoggerInterface; |
|
22
|
|
|
|
|
23
|
|
|
class Generator |
|
24
|
|
|
{ |
|
25
|
6 |
|
public function __construct( |
|
26
|
|
|
private ReaderInterface $reader, |
|
27
|
|
|
private WriterInterface $writer, |
|
28
|
|
|
private RendererInterface $renderer, |
|
29
|
|
|
private CollectionPreparationInterface $classCollectionPreparation, |
|
30
|
|
|
private LoggerInterface $logger |
|
31
|
|
|
) { |
|
32
|
6 |
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @return void |
|
36
|
|
|
*/ |
|
37
|
6 |
|
public function generate(): void |
|
38
|
|
|
{ |
|
39
|
|
|
/** @var ClassDefinition $classDef */ |
|
40
|
6 |
|
foreach ($this->classCollectionPreparation->process($this->reader) as $classDef) { |
|
41
|
1 |
|
$classRendered = $this->renderer->render($classDef); |
|
42
|
1 |
|
$classname = $classDef->getNamespace().'\\'.$classDef->getName(); |
|
43
|
|
|
|
|
44
|
1 |
|
$this->writer->write($classname, $classRendered); |
|
45
|
1 |
|
$this->logger->debug(sprintf('Generated class "%s"', $classname)); |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|