1 | <?php |
||
30 | abstract class RecordEntity extends AbstractRecord implements RecordInterface |
||
31 | { |
||
32 | use SaturateTrait, SolidableTrait; |
||
33 | |||
34 | /* |
||
35 | * Begin set of behaviour and description constants. |
||
36 | * ================================================ |
||
37 | */ |
||
38 | |||
39 | /** |
||
40 | * Default ORM relation types, see ORM configuration and documentation for more information. |
||
41 | * |
||
42 | * @see RelationSchemaInterface |
||
43 | * @see RelationSchema |
||
44 | */ |
||
45 | const HAS_ONE = 101; |
||
46 | const HAS_MANY = 102; |
||
47 | const BELONGS_TO = 103; |
||
48 | const MANY_TO_MANY = 104; |
||
49 | |||
50 | /** |
||
51 | * Morphed relation types are usually created by inversion or equivalent of primary relation |
||
52 | * types. |
||
53 | * |
||
54 | * @see RelationSchemaInterface |
||
55 | * @see RelationSchema |
||
56 | * @see MorphedRelation |
||
57 | */ |
||
58 | const BELONGS_TO_MORPHED = 108; |
||
59 | const MANY_TO_MORPHED = 109; |
||
60 | |||
61 | /** |
||
62 | * Constants used to declare relations in record schema, used in normalized relation schema. |
||
63 | * |
||
64 | * @see RelationSchemaInterface |
||
65 | */ |
||
66 | const OUTER_KEY = 901; //Outer key name |
||
67 | const INNER_KEY = 902; //Inner key name |
||
68 | const MORPH_KEY = 903; //Morph key name |
||
69 | const PIVOT_TABLE = 904; //Pivot table name |
||
70 | const PIVOT_COLUMNS = 905; //Pre-defined pivot table columns |
||
71 | const PIVOT_DEFAULTS = 906; //Pre-defined pivot table default values |
||
72 | const THOUGHT_INNER_KEY = 907; //Pivot table options |
||
73 | const THOUGHT_OUTER_KEY = 908; //Pivot table options |
||
74 | const WHERE = 909; //Where conditions |
||
75 | const WHERE_PIVOT = 910; //Where pivot conditions |
||
76 | |||
77 | /** |
||
78 | * Additional constants used to control relation schema behaviour. |
||
79 | * |
||
80 | * @see RecordEntity::SCHEMA |
||
81 | * @see RelationSchemaInterface |
||
82 | */ |
||
83 | const INVERSE = 1001; //Relation should be inverted to parent record |
||
84 | const CREATE_CONSTRAINT = 1002; //Relation should create foreign keys (default) |
||
85 | const CONSTRAINT_ACTION = 1003; //Default relation foreign key delete/update action (CASCADE) |
||
86 | const CREATE_PIVOT = 1004; //Many-to-Many should create pivot table automatically (default) |
||
87 | const NULLABLE = 1005; //Relation can be nullable (default) |
||
88 | const CREATE_INDEXES = 1006; //Indication that relation is allowed to create required indexes |
||
89 | const MORPHED_ALIASES = 1007; //Aliases for morphed sub-relations |
||
90 | |||
91 | /** |
||
92 | * Set of columns to be used in relation (attention, make sure that loaded records are set as |
||
93 | * NON SOLID if you planning to modify their data). |
||
94 | */ |
||
95 | const RELATION_COLUMNS = 1009; |
||
96 | |||
97 | /** |
||
98 | * Constants used to declare indexes in record schema. |
||
99 | * |
||
100 | * @see Record::INDEXES |
||
101 | */ |
||
102 | const INDEX = 1000; //Default index type |
||
103 | const UNIQUE = 2000; //Unique index definition |
||
104 | |||
105 | /* |
||
106 | * ================================================ |
||
107 | * End set of behaviour and description constants. |
||
108 | */ |
||
109 | |||
110 | /** |
||
111 | * Model behaviour configurations. |
||
112 | */ |
||
113 | const SECURED = '*'; |
||
114 | const HIDDEN = []; |
||
115 | const FILLABLE = []; |
||
116 | const SETTERS = []; |
||
117 | const GETTERS = []; |
||
118 | const ACCESSORS = []; |
||
119 | |||
120 | /** |
||
121 | * Record relations and columns can be described in one place - record schema. |
||
122 | * Attention: while defining table structure make sure that ACTIVE_SCHEMA constant is set to t |
||
123 | * rue. |
||
124 | * |
||
125 | * Example: |
||
126 | * const SCHEMA = [ |
||
127 | * 'id' => 'primary', |
||
128 | * 'name' => 'string', |
||
129 | * 'biography' => 'text' |
||
130 | * ]; |
||
131 | * |
||
132 | * You can pass additional options for some of your columns: |
||
133 | * const SCHEMA = [ |
||
134 | * 'pinCode' => 'string(128)', //String length |
||
135 | * 'status' => 'enum(active, hidden)', //Enum values |
||
136 | * 'balance' => 'decimal(10, 2)' //Decimal size and precision |
||
137 | * ]; |
||
138 | * |
||
139 | * Every created column will be stated as NOT NULL with forced default value, if you want to |
||
140 | * have nullable columns, specify special data key: protected $schema = [ |
||
141 | * 'name' => 'string, nullable' |
||
142 | * ]; |
||
143 | * |
||
144 | * You can easily combine table and relations definition in one schema: |
||
145 | * const SCHEMA = [ |
||
146 | * 'id' => 'bigPrimary', |
||
147 | * 'name' => 'string', |
||
148 | * 'email' => 'string', |
||
149 | * 'phoneNumber' => 'string(32)', |
||
150 | * |
||
151 | * //Relations |
||
152 | * 'profile' => [ |
||
153 | * self::HAS_ONE => 'Records\Profile', |
||
154 | * self::INVERSE => 'user' |
||
155 | * ], |
||
156 | * 'roles' => [ |
||
157 | * self::MANY_TO_MANY => 'Records\Role', |
||
158 | * self::INVERSE => 'users' |
||
159 | * ] |
||
160 | * ]; |
||
161 | * |
||
162 | * @var array |
||
163 | */ |
||
164 | const SCHEMA = []; |
||
165 | |||
166 | /** |
||
167 | * Default field values. |
||
168 | * |
||
169 | * @var array |
||
170 | */ |
||
171 | const DEFAULTS = []; |
||
172 | |||
173 | /** |
||
174 | * Set of indexes to be created for associated record table, indexes only created when record is |
||
175 | * not abstract and has active schema set to true. |
||
176 | * |
||
177 | * Use constants INDEX and UNIQUE to describe indexes, you can also create compound indexes: |
||
178 | * const INDEXES = [ |
||
179 | * [self::UNIQUE, 'email'], |
||
180 | * [self::INDEX, 'board_id'], |
||
181 | * [self::INDEX, 'board_id', 'check_id'] |
||
182 | * ]; |
||
183 | * |
||
184 | * @var array |
||
185 | */ |
||
186 | const INDEXES = []; |
||
187 | |||
188 | /** |
||
189 | * Record state. |
||
190 | * |
||
191 | * @var int |
||
192 | */ |
||
193 | private $state; |
||
194 | |||
195 | /** |
||
196 | * Points to last queued insert command for this entity, required to properly handle multiple |
||
197 | * entity updates inside one transaction. |
||
198 | * |
||
199 | * @var InsertCommand |
||
200 | */ |
||
201 | private $insertCommand = null; |
||
202 | |||
203 | /** |
||
204 | * Initiate entity inside or outside of ORM scope using given fields and state. |
||
205 | * |
||
206 | * @param array $data |
||
207 | * @param int $state |
||
208 | * @param ORMInterface|null $orm |
||
209 | * @param array|null $recordSchema |
||
210 | */ |
||
211 | public function __construct( |
||
228 | |||
229 | /** |
||
230 | * Check if entity been loaded (non new). |
||
231 | * |
||
232 | * @return bool |
||
233 | */ |
||
234 | public function isLoaded(): bool |
||
239 | |||
240 | /** |
||
241 | * Current model state. |
||
242 | * |
||
243 | * @return int |
||
244 | */ |
||
245 | public function getState(): int |
||
249 | |||
250 | /** |
||
251 | * {@inheritdoc} |
||
252 | * |
||
253 | * @param bool $queueRelations |
||
254 | * |
||
255 | * @throws RecordException |
||
256 | * @throws RelationException |
||
257 | */ |
||
258 | public function queueStore(bool $queueRelations = true): CommandInterface |
||
293 | |||
294 | /** |
||
295 | * {@inheritdoc} |
||
296 | * |
||
297 | * @throws RecordException |
||
298 | * @throws RelationException |
||
299 | */ |
||
300 | public function queueDelete(): CommandInterface |
||
315 | |||
316 | /* |
||
317 | * Code below used to generate transaction commands. |
||
318 | */ |
||
319 | |||
320 | /** |
||
321 | * Change object state. |
||
322 | * |
||
323 | * @param int $state |
||
324 | */ |
||
325 | private function setState(int $state) |
||
329 | |||
330 | /** |
||
331 | * @return InsertCommand |
||
332 | */ |
||
333 | private function prepareInsert(): InsertCommand |
||
347 | |||
348 | /** |
||
349 | * @return UpdateCommand |
||
350 | */ |
||
351 | private function prepareUpdate(): UpdateCommand |
||
375 | |||
376 | /** |
||
377 | * @return DeleteCommand |
||
378 | */ |
||
379 | private function prepareDelete(): DeleteCommand |
||
396 | |||
397 | private function syncState(): \Closure |
||
418 | } |
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.