|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Mouf\Database\TDBM\Utils; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Schema\Table; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* This class represent a property in a bean (a property has a getter, a setter, etc...). |
|
9
|
|
|
*/ |
|
10
|
|
|
abstract class AbstractBeanPropertyDescriptor |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var Table |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $table; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Whether to use the more complex name in case of conflict. |
|
19
|
|
|
* |
|
20
|
|
|
* @var bool |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $alternativeName = false; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @param Table $table |
|
26
|
|
|
*/ |
|
27
|
|
|
public function __construct(Table $table) |
|
28
|
|
|
{ |
|
29
|
|
|
$this->table = $table; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Use the more complex name in case of conflict. |
|
34
|
|
|
*/ |
|
35
|
|
|
public function useAlternativeName() |
|
36
|
|
|
{ |
|
37
|
|
|
$this->alternativeName = true; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Returns the name of the class linked to this property or null if this is not a foreign key. |
|
42
|
|
|
* |
|
43
|
|
|
* @return null|string |
|
44
|
|
|
*/ |
|
45
|
|
|
abstract public function getClassName(); |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Returns the param annotation for this property (useful for constructor). |
|
49
|
|
|
* |
|
50
|
|
|
* @return string |
|
51
|
|
|
*/ |
|
52
|
|
|
abstract public function getParamAnnotation(); |
|
53
|
|
|
|
|
54
|
|
|
public function getVariableName() |
|
55
|
|
|
{ |
|
56
|
|
|
return '$'.$this->getLowerCamelCaseName(); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function getLowerCamelCaseName() |
|
60
|
|
|
{ |
|
61
|
|
|
return TDBMDaoGenerator::toVariableName($this->getUpperCamelCaseName()); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
abstract public function getUpperCamelCaseName(); |
|
65
|
|
|
|
|
66
|
|
|
public function getSetterName() |
|
67
|
|
|
{ |
|
68
|
|
|
return 'set'.$this->getUpperCamelCaseName(); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function getGetterName() |
|
72
|
|
|
{ |
|
73
|
|
|
return 'get'.$this->getUpperCamelCaseName(); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Returns the PHP code used in the ben constructor for this property. |
|
78
|
|
|
* |
|
79
|
|
|
* @return string |
|
80
|
|
|
*/ |
|
81
|
|
|
public function getConstructorAssignCode() |
|
82
|
|
|
{ |
|
83
|
|
|
$str = ' $this->%s(%s);'; |
|
84
|
|
|
|
|
85
|
|
|
return sprintf($str, $this->getSetterName(), $this->getVariableName()); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Returns true if the property is compulsory (and therefore should be fetched in the constructor). |
|
90
|
|
|
* |
|
91
|
|
|
* @return bool |
|
92
|
|
|
*/ |
|
93
|
|
|
abstract public function isCompulsory(); |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Returns true if the property is the primary key. |
|
97
|
|
|
* |
|
98
|
|
|
* @return bool |
|
99
|
|
|
*/ |
|
100
|
|
|
abstract public function isPrimaryKey(); |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @return Table |
|
104
|
|
|
*/ |
|
105
|
|
|
public function getTable() |
|
106
|
|
|
{ |
|
107
|
|
|
return $this->table; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Returns the PHP code for getters and setters. |
|
112
|
|
|
* |
|
113
|
|
|
* @return string |
|
114
|
|
|
*/ |
|
115
|
|
|
abstract public function getGetterSetterCode(); |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Returns the part of code useful when doing json serialization. |
|
119
|
|
|
* |
|
120
|
|
|
* @return string |
|
121
|
|
|
*/ |
|
122
|
|
|
abstract public function getJsonSerializeCode(); |
|
123
|
|
|
} |
|
124
|
|
|
|