1
|
|
|
<?php |
2
|
|
|
//[PHPCOMPRESSOR(remove,start)] |
3
|
|
|
/** |
4
|
|
|
* Created by Vitaly Iegorov <[email protected]>. |
5
|
|
|
* on 22.03.16 at 17:50 |
6
|
|
|
*/ |
7
|
|
|
namespace samsoncms\api\generator; |
8
|
|
|
|
9
|
|
|
use samsonphp\generator\Generator; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Generic object-oriented programming class generator. |
13
|
|
|
* |
14
|
|
|
* @package samsoncms\api\generator |
15
|
|
|
*/ |
16
|
|
|
abstract class Generic |
17
|
|
|
{ |
18
|
|
|
/** @var string Generated class name */ |
19
|
|
|
public $className; |
20
|
|
|
|
21
|
|
|
/** @var string Generated parent class */ |
22
|
|
|
protected $parentClass; |
23
|
|
|
|
24
|
|
|
/** @var Generator Code generation instance */ |
25
|
|
|
protected $generator; |
26
|
|
|
|
27
|
|
|
/** @var \samsoncms\api\generator\metadata\GenericMetadata Entity query Generic */ |
28
|
|
|
protected $metadata; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* OOP constructor. |
32
|
|
|
* |
33
|
|
|
* @param Generator $generator Code generation instance |
34
|
|
|
* @param \samsoncms\api\generator\metadata\GenericMetadata $Generic Entity query metadata |
|
|
|
|
35
|
|
|
*/ |
36
|
|
|
public function __construct(Generator $generator, $metadata) |
37
|
|
|
{ |
38
|
|
|
$this->metadata = $metadata; |
39
|
|
|
$this->generator = $generator; |
40
|
|
|
$this->className = $metadata->entity; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Generic class generation. |
45
|
|
|
* |
46
|
|
|
* @param Generic|metadata\GenericMetadata $metadata Entity metadata |
47
|
|
|
* |
48
|
|
|
* @return string Generated PHP class code |
49
|
|
|
*/ |
50
|
|
|
public function generate(Generic $metadata = null) |
51
|
|
|
{ |
52
|
|
|
$metadata = null === $metadata ? $this->metadata : $metadata; |
53
|
|
|
|
54
|
|
|
$this->createUses($metadata); |
|
|
|
|
55
|
|
|
$this->createDefinition($metadata); |
|
|
|
|
56
|
|
|
$this->createConstants($metadata); |
|
|
|
|
57
|
|
|
$this->createStaticFields($metadata); |
|
|
|
|
58
|
|
|
$this->createStaticMethods($metadata); |
|
|
|
|
59
|
|
|
$this->createFields($metadata); |
|
|
|
|
60
|
|
|
$this->createMethods($metadata); |
|
|
|
|
61
|
|
|
$this->createConstructor($metadata); |
|
|
|
|
62
|
|
|
|
63
|
|
|
return $this->generator->endClass()->flush(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Class uses generation part. |
68
|
|
|
* |
69
|
|
|
* @param \samsoncms\api\generator\metadata\GenericMetadata $metadata Entity metadata |
70
|
|
|
*/ |
71
|
|
|
protected function createUses($metadata) |
|
|
|
|
72
|
|
|
{ |
73
|
|
|
|
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Class definition generation part. |
78
|
|
|
* |
79
|
|
|
* @param \samsoncms\api\generator\metadata\GenericMetadata $metadata Entity metadata |
80
|
|
|
*/ |
81
|
|
|
abstract protected function createDefinition($metadata); |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Class constants generation part. |
85
|
|
|
* |
86
|
|
|
* @param \samsoncms\api\generator\metadata\GenericMetadata $metadata Entity metadata |
87
|
|
|
*/ |
88
|
|
|
protected function createConstants($metadata) |
89
|
|
|
{ |
90
|
|
|
|
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Class static fields generation part. |
95
|
|
|
* |
96
|
|
|
* @param \samsoncms\api\generator\metadata\GenericMetadata $metadata Entity metadata |
97
|
|
|
*/ |
98
|
|
|
protected function createStaticFields($metadata) |
99
|
|
|
{ |
100
|
|
|
|
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Class static methods generation part. |
105
|
|
|
* |
106
|
|
|
* @param \samsoncms\api\generator\metadata\GenericMetadata $metadata Entity metadata |
107
|
|
|
*/ |
108
|
|
|
protected function createStaticMethods($metadata) |
|
|
|
|
109
|
|
|
{ |
110
|
|
|
|
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Class fields generation part. |
115
|
|
|
* |
116
|
|
|
* @param \samsoncms\api\generator\metadata\GenericMetadata $metadata Entity metadata |
117
|
|
|
*/ |
118
|
|
|
protected function createFields($metadata) |
119
|
|
|
{ |
120
|
|
|
|
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Class methods generation part. |
125
|
|
|
* |
126
|
|
|
* @param \samsoncms\api\generator\metadata\GenericMetadata $metadata Entity metadata |
127
|
|
|
*/ |
128
|
|
|
protected function createMethods($metadata) |
129
|
|
|
{ |
130
|
|
|
|
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Class constructor generation part. |
135
|
|
|
* |
136
|
|
|
* @param \samsoncms\api\generator\metadata\GenericMetadata $metadata Entity metadata |
137
|
|
|
*/ |
138
|
|
|
protected function createConstructor($metadata) |
139
|
|
|
{ |
140
|
|
|
|
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
//[PHPCOMPRESSOR(remove,end)] |
144
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.