1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the Zemit Framework. |
5
|
|
|
* |
6
|
|
|
* (c) Zemit Team <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE.txt |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Zemit\Mvc; |
13
|
|
|
|
14
|
|
|
use Phalcon\Events\Manager as EventsManager; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Events |
18
|
|
|
* - afterCreate |
19
|
|
|
* - afterDelete |
20
|
|
|
* - afterFetch |
21
|
|
|
* - afterSave |
22
|
|
|
* - afterUpdate |
23
|
|
|
* - afterValidation |
24
|
|
|
* - afterValidationOnCreate |
25
|
|
|
* - afterValidationOnUpdate |
26
|
|
|
* - beforeDelete |
27
|
|
|
* - beforeCreate |
28
|
|
|
* - beforeSave |
29
|
|
|
* - beforeUpdate |
30
|
|
|
* - beforeValidation |
31
|
|
|
* - beforeValidationOnCreate |
32
|
|
|
* - beforeValidationOnUpdate |
33
|
|
|
* - notDeleted |
34
|
|
|
* - notSaved |
35
|
|
|
* - onValidationFails |
36
|
|
|
* - prepareSave |
37
|
|
|
* - validation |
38
|
|
|
* @link https://docs.phalcon.io/4.0/en/db-models#events |
39
|
|
|
* |
40
|
|
|
* {@inheritdoc} \Phalcon\Mvc\Model |
41
|
|
|
* @package Zemit\Mvc |
42
|
|
|
*/ |
43
|
|
|
class Model extends \Phalcon\Mvc\Model |
44
|
|
|
{ |
45
|
|
|
// Model Feature Traits |
46
|
|
|
use \Zemit\Mvc\Model\Options; |
47
|
|
|
use \Zemit\Mvc\Model\Events; |
48
|
|
|
use \Zemit\Mvc\Model\Security; |
49
|
|
|
use \Zemit\Mvc\Model\EagerLoad; |
50
|
|
|
use \Zemit\Mvc\Model\Relationship; |
51
|
|
|
use \Zemit\Mvc\Model\Expose; |
52
|
|
|
use \Zemit\Mvc\Model\FindIn; |
53
|
|
|
use \Zemit\Mvc\Model\SoftDelete; |
54
|
|
|
use \Zemit\Mvc\Model\Identity; |
55
|
|
|
use \Zemit\Mvc\Model\Replication; |
56
|
|
|
use \Zemit\Mvc\Model\Cache; |
57
|
|
|
use \Zemit\Mvc\Model\Hash; |
58
|
|
|
use \Zemit\Mvc\Model\Attribute; |
59
|
|
|
use \Zemit\Mvc\Model\Json; |
60
|
|
|
use \Zemit\Mvc\Model\Position; |
61
|
|
|
use \Zemit\Mvc\Model\Blameable; |
62
|
|
|
use \Zemit\Mvc\Model\FindIn; |
63
|
|
|
use \Zemit\Mvc\Model\Snapshot; |
64
|
|
|
use \Zemit\Mvc\Model\LifeCycle; |
65
|
|
|
use \Zemit\Mvc\Model\PrimaryKeys; |
66
|
|
|
use \Zemit\Mvc\Model\Options; |
67
|
|
|
use \Zemit\Mvc\Model\Uuid; |
68
|
|
|
use \Zemit\Mvc\Model\Slug; |
69
|
|
|
use \Zemit\Mvc\Model\Validate; |
70
|
|
|
use \Zemit\Mvc\Model\Locale; |
71
|
|
|
|
72
|
4 |
|
public function initialize(): void |
73
|
|
|
{ |
74
|
|
|
// Initialize options manager |
75
|
4 |
|
$this->initializeOptions(); |
76
|
|
|
|
77
|
|
|
// Initialize setup & events manager |
78
|
4 |
|
self::setup($this->getOptionsManager()->get('setup')); |
79
|
4 |
|
$this->setEventsManager(new EventsManager()); |
80
|
4 |
|
$this->useDynamicUpdate(true); |
81
|
|
|
|
82
|
|
|
// Initialize features |
83
|
4 |
|
$this->initializeCache(); |
84
|
4 |
|
$this->initializeSnapshot(); |
85
|
4 |
|
$this->initializeReplication(); |
86
|
4 |
|
$this->initializeSoftDelete(); |
87
|
4 |
|
$this->initializePosition(); |
88
|
4 |
|
$this->initializeSecurity(); |
89
|
4 |
|
$this->initializeBlameable(); |
90
|
4 |
|
$this->initializeCreated(); |
91
|
4 |
|
$this->initializeUpdated(); |
92
|
4 |
|
$this->initializeDeleted(); |
93
|
4 |
|
$this->initializeRestored(); |
94
|
4 |
|
$this->initializeSlug(); |
95
|
4 |
|
$this->initializeUuid(); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Enables/disables options in the ORM |
100
|
|
|
* - We do this here in order to keep behaviour consistencies between different environments |
101
|
|
|
* -------------------------------- |
102
|
|
|
* caseInsensitiveColumnMap - false - Case insensitive column map |
103
|
|
|
* castLastInsertIdToInt - false - Casts the lastInsertId to an integer |
104
|
|
|
* castOnHydrate - false - Automatic cast to original types on hydration |
105
|
|
|
* columnRenaming - true - Column renaming |
106
|
|
|
* disableAssignSetters - false - Disable setters |
107
|
|
|
* enableImplicitJoins - true - Enable implicit joins |
108
|
|
|
* events - true - Callbacks, hooks and event notifications from all the models |
109
|
|
|
* exceptionOnFailedMetaDataSave - false - Throw an exception when there is a failed meta-data save |
110
|
|
|
* exceptionOnFailedSave - false - Throw an exception when there is a failed save() |
111
|
|
|
* ignoreUnknownColumns - false - Ignore unknown columns on the model |
112
|
|
|
* lateStateBinding - false - Late state binding of the Phalcon\Mvc\Model::cloneResultMap() method |
113
|
|
|
* notNullValidations - true - Automatically validate the not null columns present |
114
|
|
|
* phqlLiterals - true - Literals in the PHQL parser |
115
|
|
|
* prefetchRecords - 0 - The number of records to prefetch when getting data from the ORM |
116
|
|
|
* updateSnapshotOnSave - true - Update snapshots on save() |
117
|
|
|
* virtualForeignKeys - true - Virtual foreign keys |
118
|
|
|
* -------------------------------- |
119
|
|
|
* @link https://docs.phalcon.io/4.0/en/db-models#model-features |
120
|
|
|
* |
121
|
|
|
* @param array|null $options |
122
|
|
|
*/ |
123
|
4 |
|
public static function setup(?array $options = null): void |
124
|
|
|
{ |
125
|
4 |
|
parent::setup(array_merge([ |
126
|
4 |
|
'caseInsensitiveColumnMap' => false, |
127
|
4 |
|
'castLastInsertIdToInt' => true, // changed from default |
128
|
|
|
// 'castOnHydrate' => true, // changed from default |
129
|
4 |
|
'castOnHydrate' => false, // problems with binary when true |
130
|
4 |
|
'columnRenaming' => true, |
131
|
4 |
|
'disableAssignSetters' => false, |
132
|
4 |
|
'enableImplicitJoins' => true, |
133
|
4 |
|
'events' => true, |
134
|
4 |
|
'exceptionOnFailedMetaDataSave' => false, |
135
|
4 |
|
'exceptionOnFailedSave' => false, |
136
|
4 |
|
'ignoreUnknownColumns' => false, |
137
|
4 |
|
'lateStateBinding' => false, |
138
|
4 |
|
'notNullValidations' => false, // changed from default @todo see if we can |
139
|
4 |
|
'phqlLiterals' => true, |
140
|
4 |
|
'prefetchRecords' => 0, |
141
|
4 |
|
'updateSnapshotOnSave' => true, |
142
|
4 |
|
'virtualForeignKeys' => true, |
143
|
4 |
|
], $options ?? [])); |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|