1 | <?php |
||
12 | class ScalarBeanPropertyDescriptor extends AbstractBeanPropertyDescriptor |
||
13 | { |
||
14 | /** |
||
15 | * @var Column |
||
16 | */ |
||
17 | private $column; |
||
18 | |||
19 | public function __construct(Table $table, Column $column) |
||
25 | |||
26 | /** |
||
27 | * Returns the foreign-key the column is part of, if any. null otherwise. |
||
28 | * |
||
29 | * @return ForeignKeyConstraint|null |
||
30 | */ |
||
31 | public function getForeignKey() |
||
35 | |||
36 | /** |
||
37 | * Returns the param annotation for this property (useful for constructor). |
||
38 | * |
||
39 | * @return string |
||
40 | */ |
||
41 | public function getParamAnnotation() |
||
50 | |||
51 | public function getUpperCamelCaseName() |
||
55 | |||
56 | /** |
||
57 | * Returns the name of the class linked to this property or null if this is not a foreign key. |
||
58 | * |
||
59 | * @return null|string |
||
60 | */ |
||
61 | public function getClassName() |
||
65 | |||
66 | /** |
||
67 | * Returns true if the property is compulsory (and therefore should be fetched in the constructor). |
||
68 | * |
||
69 | * @return bool |
||
70 | */ |
||
71 | public function isCompulsory() |
||
75 | |||
76 | /** |
||
77 | * Returns true if the property has a default value. |
||
78 | * |
||
79 | * @return bool |
||
80 | */ |
||
81 | public function hasDefault() |
||
85 | |||
86 | /** |
||
87 | * Returns the code that assigns a value to its default value. |
||
88 | * |
||
89 | * @return string |
||
90 | */ |
||
91 | public function assignToDefaultCode() |
||
105 | |||
106 | /** |
||
107 | * Returns true if the property is the primary key. |
||
108 | * |
||
109 | * @return bool |
||
110 | */ |
||
111 | public function isPrimaryKey() |
||
115 | |||
116 | /** |
||
117 | * Returns the PHP code for getters and setters. |
||
118 | * |
||
119 | * @return string |
||
120 | */ |
||
121 | public function getGetterSetterCode() |
||
122 | { |
||
123 | $type = $this->column->getType(); |
||
124 | $normalizedType = TDBMDaoGenerator::dbalTypeToPhpType($type); |
||
125 | |||
126 | $columnGetterName = $this->getGetterName(); |
||
127 | $columnSetterName = $this->getSetterName(); |
||
128 | |||
129 | if ($normalizedType == '\\DateTimeInterface') { |
||
130 | $castTo = '\\DateTimeInterface '; |
||
131 | } else { |
||
132 | $castTo = ''; |
||
133 | } |
||
134 | |||
135 | $getterAndSetterCode = ' /** |
||
136 | * The getter for the "%s" column. |
||
137 | * |
||
138 | * @return %s |
||
139 | */ |
||
140 | public function %s() { |
||
141 | return $this->get(%s, %s); |
||
142 | } |
||
143 | |||
144 | /** |
||
145 | * The setter for the "%s" column. |
||
146 | * |
||
147 | * @param %s $%s |
||
148 | */ |
||
149 | public function %s(%s$%s) { |
||
150 | $this->set(%s, $%s, %s); |
||
151 | } |
||
152 | |||
153 | '; |
||
154 | |||
155 | return sprintf($getterAndSetterCode, |
||
156 | // Getter |
||
157 | $this->column->getName(), |
||
158 | $normalizedType, |
||
159 | $columnGetterName, |
||
160 | var_export($this->column->getName(), true), |
||
161 | var_export($this->table->getName(), true), |
||
162 | // Setter |
||
163 | $this->column->getName(), |
||
164 | $normalizedType, |
||
165 | $this->column->getName(), |
||
166 | $columnSetterName, |
||
167 | $castTo, |
||
168 | $this->column->getName().($castTo ? ($this->column->getNotnull() ? '' : ' = null') : ''), |
||
169 | var_export($this->column->getName(), true), |
||
170 | $this->column->getName(), |
||
171 | var_export($this->table->getName(), true) |
||
172 | ); |
||
173 | } |
||
174 | |||
175 | /** |
||
176 | * Returns the part of code useful when doing json serialization. |
||
177 | * |
||
178 | * @return string |
||
179 | */ |
||
180 | public function getJsonSerializeCode() |
||
191 | |||
192 | /** |
||
193 | * Returns the column name. |
||
194 | * |
||
195 | * @return string |
||
196 | */ |
||
197 | public function getColumnName() |
||
201 | } |
||
202 |