|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of Pomm's ModelManager package. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) 2014 - 2015 Grégoire HUBERT <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
namespace PommProject\ModelManager\Generator; |
|
11
|
|
|
|
|
12
|
|
|
use PommProject\Foundation\Inflector; |
|
13
|
|
|
use PommProject\Foundation\ParameterHolder; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* EntityGenerator |
|
17
|
|
|
* |
|
18
|
|
|
* Entity generator. |
|
19
|
|
|
* |
|
20
|
|
|
* @package ModelManager |
|
21
|
|
|
* @copyright 2014 - 2015 Grégoire HUBERT |
|
22
|
|
|
* @author Grégoire HUBERT |
|
23
|
|
|
* @license X11 {@link http://opensource.org/licenses/mit-license.php} |
|
24
|
|
|
* @see BaseGenerator |
|
25
|
|
|
*/ |
|
26
|
|
|
class EntityGenerator extends BaseGenerator |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* generate |
|
30
|
|
|
* |
|
31
|
|
|
* Generate Entity file. |
|
32
|
|
|
* |
|
33
|
|
|
* @see BaseGenerator |
|
34
|
|
|
*/ |
|
35
|
|
|
public function generate(ParameterHolder $input, array $output = []) |
|
36
|
|
|
{ |
|
37
|
|
|
$this |
|
38
|
|
|
->checkOverwrite($input) |
|
39
|
|
|
->outputFileCreation($output) |
|
40
|
|
|
->saveFile( |
|
41
|
|
|
$this->filename, |
|
42
|
|
|
$this->mergeTemplate( |
|
43
|
|
|
[ |
|
44
|
|
|
'namespace' => $this->namespace, |
|
45
|
|
|
'entity' => Inflector::studlyCaps($this->relation), |
|
46
|
|
|
'relation' => $this->relation, |
|
47
|
|
|
'schema' => $this->schema, |
|
48
|
|
|
'flexible_container' => $this->flexible_container, |
|
49
|
|
|
'flexible_container_class' => array_reverse(explode('\\', $this->flexible_container))[0] |
|
50
|
|
|
] |
|
51
|
|
|
) |
|
52
|
|
|
); |
|
53
|
|
|
|
|
54
|
|
|
return $output; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* getCodeTemplate |
|
59
|
|
|
* |
|
60
|
|
|
* @see BaseGenerator |
|
61
|
|
|
*/ |
|
62
|
|
|
protected function getCodeTemplate() |
|
63
|
|
|
{ |
|
64
|
|
|
return <<<'_' |
|
65
|
|
|
<?php |
|
66
|
|
|
|
|
67
|
|
|
namespace {:namespace:}; |
|
68
|
|
|
|
|
69
|
|
|
use {:flexible_container:}; |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* {:entity:} |
|
73
|
|
|
* |
|
74
|
|
|
* Flexible entity for relation |
|
75
|
|
|
* {:schema:}.{:relation:} |
|
76
|
|
|
* |
|
77
|
|
|
* @see FlexibleEntity |
|
78
|
|
|
*/ |
|
79
|
|
|
class {:entity:} extends {:flexible_container_class:} |
|
80
|
|
|
{ |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
_; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|