MetaData.php
8.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
<?php
namespace Phalcon\Mvc\Model {
/**
* Phalcon\Mvc\Model\MetaData
*
* <p>Because Phalcon\Mvc\Model requires meta-data like field names, data types, primary keys, etc.
* this component collect them and store for further querying by Phalcon\Mvc\Model.
* Phalcon\Mvc\Model\MetaData can also use adapters to store temporarily or permanently the meta-data.</p>
*
* <p>A standard Phalcon\Mvc\Model\MetaData can be used to query model attributes:</p>
*
* <code>
* $metaData = new Phalcon\Mvc\Model\MetaData\Memory();
* $attributes = $metaData->getAttributes(new Robots());
* print_r($attributes);
* </code>
*
*/
abstract class MetaData implements \Phalcon\DI\InjectionAwareInterface {
const MODELS_ATTRIBUTES = 0;
const MODELS_PRIMARY_KEY = 1;
const MODELS_NON_PRIMARY_KEY = 2;
const MODELS_NOT_NULL = 3;
const MODELS_DATA_TYPES = 4;
const MODELS_DATA_TYPES_NUMERIC = 5;
const MODELS_DATE_AT = 6;
const MODELS_DATE_IN = 7;
const MODELS_IDENTITY_COLUMN = 8;
const MODELS_DATA_TYPES_BIND = 9;
const MODELS_AUTOMATIC_DEFAULT_INSERT = 10;
const MODELS_AUTOMATIC_DEFAULT_UPDATE = 11;
const MODELS_COLUMN_MAP = 0;
const MODELS_REVERSE_COLUMN_MAP = 1;
protected $_dependencyInjector;
protected $_strategy;
protected $_metaData;
protected $_columnMap;
/**
* Initialize the metadata for certain table
*
* @param \Phalcon\Mvc\ModelInterface $model
* @param string $key
* @param string $table
* @param string $schema
*/
protected function _initialize(){ }
/**
* Sets the DependencyInjector container
*
* @param \Phalcon\DiInterface $dependencyInjector
*/
public function setDI($dependencyInjector){ }
/**
* Returns the DependencyInjector container
*
* @return \Phalcon\DiInterface
*/
public function getDI(){ }
/**
* Set the meta-data extraction strategy
*
* @param \Phalcon\Mvc\Model\MetaData\Strategy\Introspection $strategy
*/
public function setStrategy($strategy){ }
/**
* Return the strategy to obtain the meta-data
*
* @return \Phalcon\Mvc\Model\MetaData\Strategy\Introspection
*/
public function getStrategy(){ }
/**
* Reads the complete meta-data for certain model
*
*<code>
* print_r($metaData->readMetaData(new Robots()));
*</code>
*
* @param \Phalcon\Mvc\ModelInterface $model
* @return array
*/
public function readMetaData($model){ }
/**
* Reads meta-data for certain model using a MODEL_* constant
*
*<code>
* print_r($metaData->writeColumnMapIndex(new Robots(), MetaData::MODELS_REVERSE_COLUMN_MAP, array('leName' => 'name')));
*</code>
*
* @param \Phalcon\Mvc\ModelInterface $model
* @param int $index
* @return array
*/
public function readMetaDataIndex($model, $index){ }
/**
* Writes meta-data for certain model using a MODEL_* constant
*
*<code>
* print_r($metaData->writeColumnMapIndex(new Robots(), MetaData::MODELS_REVERSE_COLUMN_MAP, array('leName' => 'name')));
*</code>
*
* @param \Phalcon\Mvc\ModelInterface $model
* @param int $index
* @param mixed $data
*/
public function writeMetaDataIndex($model, $index, $data, $replace){ }
/**
* Reads the ordered/reversed column map for certain model
*
*<code>
* print_r($metaData->readColumnMap(new Robots()));
*</code>
*
* @param \Phalcon\Mvc\ModelInterface $model
* @return array
*/
public function readColumnMap($model){ }
/**
* Reads column-map information for certain model using a MODEL_* constant
*
*<code>
* print_r($metaData->readColumnMapIndex(new Robots(), MetaData::MODELS_REVERSE_COLUMN_MAP));
*</code>
*
* @param \Phalcon\Mvc\ModelInterface $model
* @param int $index
*/
public function readColumnMapIndex($model, $index){ }
/**
* Returns table attributes names (fields)
*
*<code>
* print_r($metaData->getAttributes(new Robots()));
*</code>
*
* @param \Phalcon\Mvc\ModelInterface $model
* @return array
*/
public function getAttributes($model){ }
/**
* Returns an array of fields which are part of the primary key
*
*<code>
* print_r($metaData->getPrimaryKeyAttributes(new Robots()));
*</code>
*
* @param \Phalcon\Mvc\ModelInterface $model
* @return array
*/
public function getPrimaryKeyAttributes($model){ }
/**
* Returns an arrau of fields which are not part of the primary key
*
*<code>
* print_r($metaData->getNonPrimaryKeyAttributes(new Robots()));
*</code>
*
* @param \Phalcon\Mvc\ModelInterface $model
* @return array
*/
public function getNonPrimaryKeyAttributes($model){ }
/**
* Returns an array of not null attributes
*
*<code>
* print_r($metaData->getNotNullAttributes(new Robots()));
*</code>
*
* @param \Phalcon\Mvc\ModelInterface $model
* @return array
*/
public function getNotNullAttributes($model){ }
/**
* Returns attributes and their data types
*
*<code>
* print_r($metaData->getDataTypes(new Robots()));
*</code>
*
* @param \Phalcon\Mvc\ModelInterface $model
* @return array
*/
public function getDataTypes($model){ }
/**
* Returns attributes which types are numerical
*
*<code>
* print_r($metaData->getDataTypesNumeric(new Robots()));
*</code>
*
* @param \Phalcon\Mvc\ModelInterface $model
* @return array
*/
public function getDataTypesNumeric($model){ }
/**
* Returns the name of identity field (if one is present)
*
*<code>
* print_r($metaData->getIdentityField(new Robots()));
*</code>
*
* @param \Phalcon\Mvc\ModelInterface $model
* @return string
*/
public function getIdentityField($model){ }
/**
* Returns attributes and their bind data types
*
*<code>
* print_r($metaData->getBindTypes(new Robots()));
*</code>
*
* @param \Phalcon\Mvc\ModelInterface $model
* @return array
*/
public function getBindTypes($model){ }
/**
* Returns attributes that must be ignored from the INSERT SQL generation
*
*<code>
* print_r($metaData->getAutomaticCreateAttributes(new Robots()));
*</code>
*
* @param \Phalcon\Mvc\ModelInterface $model
* @return array
*/
public function getAutomaticCreateAttributes($model){ }
/**
* Returns attributes that must be ignored from the UPDATE SQL generation
*
*<code>
* print_r($metaData->getAutomaticUpdateAttributes(new Robots()));
*</code>
*
* @param \Phalcon\Mvc\ModelInterface $model
* @return array
*/
public function getAutomaticUpdateAttributes($model){ }
/**
* Set the attributes that must be ignored from the INSERT SQL generation
*
*<code>
* $metaData->setAutomaticCreateAttributes(new Robots(), array('created_at' => true));
*</code>
*
* @param \Phalcon\Mvc\ModelInterface $model
* @param array $attributes
*/
public function setAutomaticCreateAttributes($model, $attributes, $replace){ }
/**
* Set the attributes that must be ignored from the UPDATE SQL generation
*
*<code>
* $metaData->setAutomaticUpdateAttributes(new Robots(), array('modified_at' => true));
*</code>
*
* @param \Phalcon\Mvc\ModelInterface $model
* @param array $attributes
*/
public function setAutomaticUpdateAttributes($model, $attributes, $replace){ }
/**
* Returns the column map if any
*
*<code>
* print_r($metaData->getColumnMap(new Robots()));
*</code>
*
* @param \Phalcon\Mvc\ModelInterface $model
* @return array
*/
public function getColumnMap($model){ }
/**
* Returns the reverse column map if any
*
*<code>
* print_r($metaData->getReverseColumnMap(new Robots()));
*</code>
*
* @param \Phalcon\Mvc\ModelInterface $model
* @return array
*/
public function getReverseColumnMap($model){ }
/**
* Check if a model has certain attribute
*
*<code>
* var_dump($metaData->hasAttribute(new Robots(), 'name'));
*</code>
*
* @param \Phalcon\Mvc\ModelInterface $model
* @param string $attribute
* @return boolean
*/
public function hasAttribute($model, $attribute){ }
/**
* Checks if the internal meta-data container is empty
*
*<code>
* var_dump($metaData->isEmpty());
*</code>
*
* @return boolean
*/
public function isEmpty(){ }
/**
* Resets internal meta-data in order to regenerate it
*
*<code>
* $metaData->reset();
*</code>
*/
public function reset(){ }
}
}