/
Model.zep
6028 lines (5288 loc) · 178 KB
/
Model.zep
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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view the
* LICENSE.txt file that was distributed with this source code.
*/
namespace Phalcon\Mvc;
use JsonSerializable;
use Phalcon\Db\Adapter\AdapterInterface;
use Phalcon\Db\Column;
use Phalcon\Db\DialectInterface;
use Phalcon\Db\Enum;
use Phalcon\Db\RawValue;
use Phalcon\Di\AbstractInjectionAware;
use Phalcon\Di\Di;
use Phalcon\Di\DiInterface;
use Phalcon\Events\ManagerInterface as EventsManagerInterface;
use Phalcon\Messages\Message;
use Phalcon\Messages\MessageInterface;
use Phalcon\Mvc\Model\BehaviorInterface;
use Phalcon\Mvc\Model\Criteria;
use Phalcon\Mvc\Model\CriteriaInterface;
use Phalcon\Mvc\Model\Exception;
use Phalcon\Mvc\Model\ManagerInterface;
use Phalcon\Mvc\Model\MetaDataInterface;
use Phalcon\Mvc\Model\Query;
use Phalcon\Mvc\Model\Query\Builder;
use Phalcon\Mvc\Model\Query\BuilderInterface;
use Phalcon\Mvc\Model\QueryInterface;
use Phalcon\Mvc\Model\ResultInterface;
use Phalcon\Mvc\Model\Resultset;
use Phalcon\Mvc\Model\ResultsetInterface;
use Phalcon\Mvc\Model\Relation;
use Phalcon\Mvc\Model\RelationInterface;
use Phalcon\Mvc\Model\TransactionInterface;
use Phalcon\Mvc\Model\ValidationFailed;
use Phalcon\Mvc\ModelInterface;
use Phalcon\Filter\Validation\ValidationInterface;
use Phalcon\Support\Collection;
use Phalcon\Support\Collection\CollectionInterface;
use Serializable;
/**
* Phalcon\Mvc\Model
*
* Phalcon\Mvc\Model connects business objects and database tables to create a
* persistable domain model where logic and data are presented in one wrapping.
* It‘s an implementation of the object-relational mapping (ORM).
*
* A model represents the information (data) of the application and the rules to
* manipulate that data. Models are primarily used for managing the rules of
* interaction with a corresponding database table. In most cases, each table in
* your database will correspond to one model in your application. The bulk of
* your application's business logic will be concentrated in the models.
*
* Phalcon\Mvc\Model is the first ORM written in Zephir/C languages for PHP,
* giving to developers high performance when interacting with databases while
* is also easy to use.
*
* ```php
* $robot = new Robots();
*
* $robot->type = "mechanical";
* $robot->name = "Astro Boy";
* $robot->year = 1952;
*
* if ($robot->save() === false) {
* echo "Umh, We can store robots: ";
*
* $messages = $robot->getMessages();
*
* foreach ($messages as $message) {
* echo $message;
* }
* } else {
* echo "Great, a new robot was saved successfully!";
* }
* ```
*/
abstract class Model extends AbstractInjectionAware implements EntityInterface, ModelInterface, ResultInterface, Serializable, JsonSerializable
{
const DIRTY_STATE_DETACHED = 2;
const DIRTY_STATE_PERSISTENT = 0;
const DIRTY_STATE_TRANSIENT = 1;
const OP_CREATE = 1;
const OP_DELETE = 3;
const OP_NONE = 0;
const OP_UPDATE = 2;
const TRANSACTION_INDEX = "transaction";
/**
* @var int
*/
protected dirtyState = 1;
/**
* @var array
*/
protected dirtyRelated = [];
/**
* @var array
*/
protected errorMessages = [];
/**
* @var ManagerInterface|null
*/
protected modelsManager = null;
/**
* @var MetaDataInterface|null
*/
protected modelsMetaData = null;
/**
* @var array
*/
protected related = [];
/**
* @var int
*/
protected operationMade = 0;
/**
* @var array
*/
protected oldSnapshot = [];
/**
* @var bool
*/
protected skipped = false;
/**
* @var array
*/
protected snapshot = [];
/**
* @var TransactionInterface|null
*/
protected transaction = null;
/**
* @var string|null
*/
protected uniqueKey = null;
/**
* @var array
*/
protected uniqueParams = [];
/**
* @var array
*/
protected uniqueTypes = [];
/**
* Phalcon\Mvc\Model constructor
*/
final public function __construct(
var data = null,
<DiInterface> container = null,
<ManagerInterface> modelsManager = null
) {
/**
* We use a default DI if the user doesn't define one
*/
if container === null {
let container = Di::getDefault();
}
if container === null {
throw new Exception(
"A dependency injection container is required to access the services related to the ODM in '" . get_class(this) . "'"
);
}
let this->container = container;
/**
* Inject the manager service from the DI
*/
if modelsManager === null {
let modelsManager = <ManagerInterface> container->getShared("modelsManager");
if modelsManager === null {
throw new Exception(
"The injected service 'modelsManager' is not valid in '" . get_class(this) . "'"
);
}
}
/**
* Update the models-manager
*/
let this->modelsManager = modelsManager;
/**
* The manager always initializes the object
*/
modelsManager->initialize(this);
/**
* This allows the developer to execute initialization stuff every time
* an instance is created
*/
if method_exists(this, "onConstruct") {
this->{"onConstruct"}(data);
}
if typeof data == "array" {
this->assign(data);
}
}
/**
* Handles method calls when a method is not implemented
*
* @return mixed
* @throws \Phalcon\Mvc\Model\Exception If the method doesn't exist
*/
public function __call(string method, array arguments)
{
var modelName, status, records;
let records = self::invokeFinder(method, arguments);
if records !== false {
return records;
}
let modelName = get_class(this);
/**
* Check if there is a default action using the magic getter
*/
let records = this->getRelatedRecords(modelName, method, arguments);
if records !== false {
return records;
}
/**
* Try to find a replacement for the missing method in a
* behavior/listener
*/
let status = (<ManagerInterface> this->modelsManager)->missingMethod(this, method, arguments);
if status !== null {
return status;
}
/**
* The method doesn't exist throw an exception
*/
throw new Exception(
"The method '" . method . "' doesn't exist on model '" . modelName . "'"
);
}
/**
* Handles method calls when a static method is not implemented
*
* @return mixed
* @throws \Phalcon\Mvc\Model\Exception If the method doesn't exist
*/
public static function __callStatic(string method, array arguments)
{
var modelName, records;
let records = self::invokeFinder(method, arguments);
if records !== false {
return records;
}
let modelName = get_called_class();
/**
* The method doesn't exist throw an exception
*/
throw new Exception(
"The method '" . method . "' doesn't exist on model '" . modelName . "'"
);
}
/**
* Magic method to get related records using the relation alias as a
* property
*
* @return mixed
*/
public function __get(string! property)
{
var modelName, manager, lowerProperty, relation;
string method;
let modelName = get_class(this),
manager = this->getModelsManager(),
lowerProperty = strtolower(property);
/**
* Check if the property is a relationship
*/
let relation = <RelationInterface> manager->getRelationByAlias(
modelName,
lowerProperty
);
if typeof relation == "object" {
/**
* There might be unsaved related records that can be returned
*/
if isset this->dirtyRelated[lowerProperty] {
return this->dirtyRelated[lowerProperty];
}
/**
* Get the related records
*/
return this->getRelated(lowerProperty);
}
/**
* Check if the property has getters
*/
let method = "get" . camelize(property);
if method_exists(this, method) {
return this->{method}();
}
/**
* A notice is shown if the property is not defined and it isn't a
* relationship
*/
trigger_error(
"Access to undefined property " . modelName . "::" . property
);
return null;
}
/**
* Magic method to check if a property is a valid relation
*/
public function __isset(string! property) -> bool
{
var manager, method, modelName, relation, result;
let modelName = get_class(this),
manager = <ManagerInterface> this->getModelsManager();
/**
* Check if the property is a relationship
*/
let relation = <RelationInterface> manager->getRelationByAlias(
modelName,
property
);
if typeof relation === "object" {
let result = true;
} else {
// If this is a property
let method = "get" . camelize(property);
let result = method_exists(this, method);
}
return result;
}
/**
* Serializes a model
*/
public function __serialize() -> array
{
/**
* Use the standard serialize function to serialize the array data
*/
var attributes, manager, dirtyState, snapshot = null;
let attributes = this->toArray(null, false),
dirtyState = this->dirtyState,
manager = <ManagerInterface> this->getModelsManager();
if manager->isKeepingSnapshots(this) && this->snapshot !== null && attributes != this->snapshot {
let snapshot = this->snapshot;
}
return [
"attributes": attributes,
"snapshot": snapshot,
"dirtyState": dirtyState
];
}
/**
* Magic method to assign values to the the model
*
* @param mixed value
*/
public function __set(string property, value)
{
var lowerProperty, modelName, manager, relation, referencedModel, item,
dirtyState;
array related;
/**
* Values are probably relationships if they are objects
*/
if typeof value === "object" && value instanceof ModelInterface {
let lowerProperty = strtolower(property),
modelName = get_class(this),
manager = this->getModelsManager(),
relation = <RelationInterface> manager->getRelationByAlias(
modelName,
lowerProperty
);
if typeof relation === "object" {
let dirtyState = this->dirtyState;
if (value->getDirtyState() != dirtyState) {
let dirtyState = self::DIRTY_STATE_TRANSIENT;
}
unset this->related[lowerProperty];
let this->dirtyRelated[lowerProperty] = value,
this->dirtyState = dirtyState;
return value;
}
}
/**
* Check if the value is an array
*/
elseif typeof value === "array" {
let lowerProperty = strtolower(property),
modelName = get_class(this),
manager = this->getModelsManager(),
relation = <RelationInterface> manager->getRelationByAlias(
modelName,
lowerProperty
);
if typeof relation === "object" {
switch relation->getType() {
case Relation::BELONGS_TO:
case Relation::HAS_ONE:
/**
* Load referenced model from local cache if its possible
*/
let referencedModel = manager->load(
relation->getReferencedModel()
);
if typeof referencedModel === "object" {
referencedModel->assign(value);
unset this->related[lowerProperty];
let this->dirtyRelated[lowerProperty] = referencedModel,
this->dirtyState = self::DIRTY_STATE_TRANSIENT;
return value;
}
break;
case Relation::HAS_MANY:
case Relation::HAS_MANY_THROUGH:
let related = [];
for item in value {
if typeof item === "object" {
if item instanceof ModelInterface {
let related[] = item;
}
}
}
unset this->related[lowerProperty];
if count(related) > 0 {
let this->dirtyRelated[lowerProperty] = related,
this->dirtyState = self::DIRTY_STATE_TRANSIENT;
} else {
unset this->dirtyRelated[lowerProperty];
}
return value;
}
}
}
// Use possible setter.
if this->possibleSetter(property, value) {
return value;
}
/**
* Throw an exception if there is an attempt to set a non-public
* property.
*/
if property_exists(this, property) {
let manager = this->getModelsManager();
if unlikely !manager->isVisibleModelProperty(this, property) {
throw new Exception(
"Cannot access property '" . property . "' (not public) in '" . get_class(this) . "'"
);
}
}
let this->{property} = value;
return value;
}
/**
* Unserializes an array to the model
*/
public function __unserialize(array data) -> void
{
var container, manager, key, value, snapshot, properties, dirtyState;
if !isset data["attributes"] {
let data = [
"attributes": data
];
}
/**
* Obtain the default DI
*/
let container = Di::getDefault();
if container === null {
throw new Exception(
"A dependency injection container is required to access the services related to the ODM in '" . get_class(this) . "'"
);
}
/**
* Update the dependency injector
*/
let this->container = container;
/**
* Gets the default modelsManager service
*/
let manager = <ManagerInterface> container->getShared("modelsManager");
if manager === null {
throw new Exception(
"The injected service 'modelsManager' is not valid in '" . get_class(this) . "'"
);
}
/**
* Update the models manager
*/
let this->modelsManager = manager;
/**
* Try to initialize the model
*/
manager->initialize(this);
/**
* Fetch serialized props
*/
if fetch properties, data["attributes"] {
/**
* Update the objects properties
*/
for key, value in properties {
let this->{key} = value;
}
} else {
let properties = [];
}
/**
* Fetch serialized dirtyState
*/
if fetch dirtyState, data["dirtyState"] {
let this->dirtyState = dirtyState;
}
/**
* Fetch serialized snapshot when option is active
*/
if manager->isKeepingSnapshots(this) {
if fetch snapshot, data["snapshot"] {
let this->snapshot = snapshot;
} else {
let this->snapshot = properties;
}
}
}
/**
* Setups a behavior in a model
*
*```php
* use Phalcon\Mvc\Model;
* use Phalcon\Mvc\Model\Behavior\Timestampable;
*
* class Robots extends Model
* {
* public function initialize()
* {
* $this->addBehavior(
* new Timestampable(
* [
* "beforeCreate" => [
* "field" => "created_at",
* "format" => "Y-m-d",
* ],
* ]
* )
* );
*
* $this->addBehavior(
* new Timestampable(
* [
* "beforeUpdate" => [
* "field" => "updated_at",
* "format" => "Y-m-d",
* ],
* ]
* )
* );
* }
* }
*```
*/
public function addBehavior(<BehaviorInterface> behavior) -> void
{
(<ManagerInterface> this->modelsManager)->addBehavior(this, behavior);
}
/**
* Appends a customized message on the validation process
*
* ```php
* use Phalcon\Mvc\Model;
* use Phalcon\Messages\Message as Message;
*
* class Robots extends Model
* {
* public function beforeSave()
* {
* if ($this->name === "Peter") {
* $message = new Message(
* "Sorry, but a robot cannot be named Peter"
* );
*
* $this->appendMessage($message);
* }
* }
* }
* ```
*/
public function appendMessage(<MessageInterface> message) -> <ModelInterface>
{
let this->errorMessages[] = message;
return this;
}
/**
* Assigns values to a model from an array
*
* ```php
* $robot->assign(
* [
* "type" => "mechanical",
* "name" => "Astro Boy",
* "year" => 1952,
* ]
* );
*
* // Assign by db row, column map needed
* $robot->assign(
* $dbRow,
* [
* "db_type" => "type",
* "db_name" => "name",
* "db_year" => "year",
* ]
* );
*
* // Allow assign only name and year
* $robot->assign(
* $_POST,
* [
* "name",
* "year",
* ]
* );
*
* // By default assign method will use setters if exist, you can disable it by using ini_set to directly use properties
*
* ini_set("phalcon.orm.disable_assign_setters", true);
*
* $robot->assign(
* $_POST,
* [
* "name",
* "year",
* ]
* );
* ```
*
* @param array data
* @param mixed whiteList
* @param mixed dataColumnMap Array to transform keys of data to another
*
* @return ModelInterface
*/
public function assign(array! data, var whiteList = null, var dataColumnMap = null) -> <ModelInterface>
{
var key, keyMapped, value, attribute, attributeField, metaData,
columnMap, disableAssignSetters;
array dataMapped;
let disableAssignSetters = globals_get("orm.disable_assign_setters");
// apply column map for data, if exist
if typeof dataColumnMap === "array" {
let dataMapped = [];
for key, value in data {
if fetch keyMapped, dataColumnMap[key] {
let dataMapped[keyMapped] = value;
}
}
} else {
let dataMapped = data;
}
if count(dataMapped) === 0 {
return this;
}
let metaData = this->getModelsMetaData();
if globals_get("orm.column_renaming") {
let columnMap = metaData->getColumnMap(this);
} else {
let columnMap = null;
}
for attribute in metaData->getAttributes(this) {
// Try to find case-insensitive key variant
if !isset columnMap[attribute] && globals_get("orm.case_insensitive_column_map") {
let attribute = self::caseInsensitiveColumnMap(
columnMap,
attribute
);
}
// Check if we need to rename the field
if typeof columnMap === "array" {
if !fetch attributeField, columnMap[attribute] {
if unlikely !globals_get("orm.ignore_unknown_columns") {
throw new Exception(
"Column '" . attribute. "' doesn't make part of the column map in '" . get_class(this) . "'"
);
}
continue;
}
} else {
let attributeField = attribute;
}
// The value in the array passed
// Check if we there is data for the field
if fetch value, dataMapped[attributeField] {
// If white-list exists check if the attribute is on that list
if typeof whiteList == "array" {
if !in_array(attributeField, whiteList) {
continue;
}
}
// Try to find a possible getter
if disableAssignSetters || !this->possibleSetter(attributeField, value) {
let this->{attributeField} = value;
}
}
}
return this;
}
/**
* Returns the average value on a column for a result-set of rows matching
* the specified conditions.
*
* Returned value will be a float for simple queries or a ResultsetInterface
* instance for when the GROUP condition is used. The results will
* contain the average of each group.
*
* ```php
* // What's the average price of robots?
* $average = Robots::average(
* [
* "column" => "price",
* ]
* );
*
* echo "The average price is ", $average, "\n";
*
* // What's the average price of mechanical robots?
* $average = Robots::average(
* [
* "type = 'mechanical'",
* "column" => "price",
* ]
* );
*
* echo "The average price of mechanical robots is ", $average, "\n";
* ```
*
* @param array parameters
* @return float | ResultsetInterface
*/
public static function average(array parameters = []) -> float | <ResultsetInterface>
{
var result;
let result = self::groupResult("AVG", "average", parameters);
if typeof result === "string" {
return (float) result;
}
return result;
}
/**
* Assigns values to a model from an array returning a new model
*
*```php
* $robot = Phalcon\Mvc\Model::cloneResult(
* new Robots(),
* [
* "type" => "mechanical",
* "name" => "Astro Boy",
* "year" => 1952,
* ]
* );
*```
*/
public static function cloneResult(<ModelInterface> base, array! data, int dirtyState = 0) -> <ModelInterface>
{
var instance, key, value;
/**
* Clone the base record
*/
let instance = clone base;
/**
* Mark the object as persistent
*/
instance->setDirtyState(dirtyState);
for key, value in data {
if unlikely typeof key !== "string" {
throw new Exception(
"Invalid key in array data provided to dumpResult() in '" . get_class(base) . "'"
);
}
let instance->{key} = value;
}
/**
* Call afterFetch, this allows the developer to execute actions after a
* record is fetched from the database
*/
(<ModelInterface> instance)->fireEvent("afterFetch");
return instance;
}
/**
* Assigns values to a model from an array, returning a new model.
*
*```php
* $robot = \Phalcon\Mvc\Model::cloneResultMap(
* new Robots(),
* [
* "type" => "mechanical",
* "name" => "Astro Boy",
* "year" => 1952,
* ]
* );
*```
*
* @param ModelInterface|\Phalcon\Mvc\Model\Row base
* @param mixed columnMap
* @param int dirtyState
* @param bool keepSnapshots
*
* @return ModelInterface
*/
public static function cloneResultMap(var base, array! data, var columnMap, int dirtyState = 0, bool keepSnapshots = null) -> <ModelInterface>
{
var instance, attribute, key, value, castValue, attributeName, metaData, reverseMap;
let instance = clone base;
// Change the dirty state to persistent
instance->setDirtyState(dirtyState);
/**
* Assign the data in the model
*/
for key, value in data {
// Only string keys in the data are valid
if typeof key !== "string" {
continue;
}
if typeof columnMap !== "array" {
let instance->{key} = value;
continue;
}
// Every field must be part of the column map
if !fetch attribute, columnMap[key] {
if typeof columnMap === "array" && !empty columnMap {
let metaData = instance->getModelsMetaData();
let reverseMap = metaData->getReverseColumnMap(instance);
if !fetch attribute, reverseMap[key] {
if unlikely !globals_get("orm.ignore_unknown_columns") {
throw new Exception(
"Column '" . key . "' doesn't make part of the column map in '" . get_class(base) . "'"
);
}
continue;
}
} else {
if unlikely !globals_get("orm.ignore_unknown_columns") {
throw new Exception(
"Column '" . key . "' doesn't make part of the column map in '" . get_class(base) . "'"
);
}
continue;
}
}
if typeof attribute !== "array" {
let instance->{attribute} = value;
continue;
}
if value != "" && value !== null {
switch attribute[1] {
case Column::TYPE_INTEGER:
case Column::TYPE_MEDIUMINTEGER:
case Column::TYPE_SMALLINTEGER:
case Column::TYPE_TINYINTEGER:
let castValue = intval(value, 10);
break;
case Column::TYPE_DECIMAL:
case Column::TYPE_DOUBLE:
case Column::TYPE_FLOAT:
let castValue = doubleval(value);
break;
case Column::TYPE_BOOLEAN:
let castValue = (bool) value;
break;
default:
let castValue = value;