1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Jellyfish\Transfer; |
6
|
|
|
|
7
|
|
|
use Jellyfish\Transfer\Definition\ClassDefinitionMapLoaderInterface; |
8
|
|
|
use Jellyfish\Transfer\Generator\FactoryRegistryGeneratorInterface; |
9
|
|
|
|
10
|
|
|
class TransferGenerator implements TransferGeneratorInterface |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var \Jellyfish\Transfer\Definition\ClassDefinitionMapLoaderInterface |
14
|
|
|
*/ |
15
|
|
|
protected $classDefinitionMapLoader; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var array |
19
|
|
|
*/ |
20
|
|
|
protected $classGenerators; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var \Jellyfish\Transfer\Generator\FactoryRegistryGeneratorInterface |
24
|
|
|
*/ |
25
|
|
|
protected $factoryRegistryGenerator; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param \Jellyfish\Transfer\Definition\ClassDefinitionMapLoaderInterface $classDefinitionMapLoader |
29
|
|
|
* @param \Jellyfish\Transfer\Generator\FactoryRegistryGeneratorInterface $factoryRegistryGenerator |
30
|
|
|
* @param \Jellyfish\Transfer\Generator\ClassGeneratorInterface[] $classGenerators |
31
|
|
|
*/ |
32
|
|
|
public function __construct( |
33
|
|
|
ClassDefinitionMapLoaderInterface $classDefinitionMapLoader, |
34
|
|
|
FactoryRegistryGeneratorInterface $factoryRegistryGenerator, |
35
|
|
|
array $classGenerators |
36
|
|
|
) { |
37
|
|
|
$this->classDefinitionMapLoader = $classDefinitionMapLoader; |
38
|
|
|
$this->factoryRegistryGenerator = $factoryRegistryGenerator; |
39
|
|
|
$this->classGenerators = $classGenerators; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return \Jellyfish\Transfer\TransferGeneratorInterface |
44
|
|
|
*/ |
45
|
|
|
public function generate(): TransferGeneratorInterface |
46
|
|
|
{ |
47
|
|
|
$classDefinitionMap = $this->classDefinitionMapLoader->load(); |
48
|
|
|
|
49
|
|
|
foreach ($classDefinitionMap as $classDefinitionMapEntry) { |
50
|
|
|
foreach ($this->classGenerators as $classGenerator) { |
51
|
|
|
$classGenerator->generate($classDefinitionMapEntry); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
$this->factoryRegistryGenerator->generate($classDefinitionMap); |
56
|
|
|
|
57
|
|
|
return $this; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|