1 | <?php |
||
21 | trait ModelSave |
||
22 | { |
||
23 | /******************************************* |
||
24 | * ABSTRACTS |
||
25 | *******************************************/ |
||
26 | |||
27 | /** |
||
28 | * @param Model $model |
||
29 | * @param bool $mirrorScenario |
||
30 | * @return Record |
||
31 | */ |
||
32 | abstract protected function modelToRecord(Model $model, bool $mirrorScenario = true): Record; |
||
33 | |||
34 | /** |
||
35 | * @param Model $model |
||
36 | * @return bool |
||
37 | */ |
||
38 | abstract protected function isNew(Model $model): bool; |
||
39 | |||
40 | /******************************************* |
||
41 | * SAVE |
||
42 | *******************************************/ |
||
43 | |||
44 | /** |
||
45 | * @param Model $model |
||
46 | * @param bool $runValidation |
||
47 | * @param null $attributes |
||
48 | * @param bool $mirrorScenario |
||
49 | * @return bool |
||
50 | * @throws \Exception |
||
51 | */ |
||
52 | public function save(Model $model, bool $runValidation = true, $attributes = null, bool $mirrorScenario = true) |
||
107 | |||
108 | /** |
||
109 | * @param Model $model |
||
110 | * @param bool $isNew |
||
111 | * @return bool |
||
112 | */ |
||
113 | protected function beforeSave(Model $model, bool $isNew): bool |
||
117 | |||
118 | /** |
||
119 | * @param Model $model |
||
120 | * @param bool $isNew |
||
121 | */ |
||
122 | protected function afterSave(Model $model, bool $isNew) |
||
130 | |||
131 | /** |
||
132 | * @param Model $model |
||
133 | * @param Record $record |
||
134 | * @param bool $isNew |
||
135 | * @return void |
||
136 | */ |
||
137 | protected function transferFromRecord(Model $model, Record $record, bool $isNew) |
||
147 | |||
148 | /** |
||
149 | * @param Model $model |
||
150 | * @param Record $record |
||
151 | * @param bool $isNew |
||
152 | */ |
||
153 | protected function transferAuditAttributes(Model $model, Record $record, bool $isNew) |
||
169 | } |
||
170 |