1 | <?php |
||
8 | class RevisionOptions |
||
9 | { |
||
10 | /** |
||
11 | * Flag whether to make a revision on model creation. |
||
12 | * |
||
13 | * @var bool |
||
14 | */ |
||
15 | private $revisionOnCreate = false; |
||
16 | |||
17 | /** |
||
18 | * The limit of revisions to be created for a model instance. |
||
19 | * If the limit is reached, oldest revisions will start getting deleted to make room for new ones. |
||
20 | * |
||
21 | * @var int |
||
22 | */ |
||
23 | private $revisionLimit; |
||
24 | |||
25 | /** |
||
26 | * The fields that should be revisionable. |
||
27 | * By default (null) all fields are revisionable. |
||
28 | * |
||
29 | * @var array |
||
30 | */ |
||
31 | private $revisionFields = []; |
||
32 | |||
33 | /** |
||
34 | * The fields that should be excluded from revisioning. |
||
35 | * By default (null) no fields are excluded from revisioning. |
||
36 | * |
||
37 | * @var array |
||
38 | */ |
||
39 | private $revisionNotFields = []; |
||
40 | |||
41 | /** |
||
42 | * The model's relations that should be revisionable. |
||
43 | * By default (null) none of the model's relations are revisionable. |
||
44 | * |
||
45 | * @var array |
||
46 | */ |
||
47 | private $revisionRelations = []; |
||
48 | |||
49 | /** |
||
50 | * Flag indicating whether to create a revision for the model, when rolling back another revision of that model. |
||
51 | * If set to "true", before rolling back a revision, the original model instance's data will be stored to a new revision. |
||
52 | * If set to "false", after rolling back a revision, the original model instance's data will NOT be stored to a new revision. |
||
53 | * |
||
54 | * @var bool |
||
55 | */ |
||
56 | private $createRevisionWhenRollingBack = true; |
||
57 | |||
58 | /** |
||
59 | * Flag indicating whether to include timestamps in the revision. |
||
60 | * |
||
61 | * @var bool |
||
62 | */ |
||
63 | private $revisionTimestamps = false; |
||
64 | |||
65 | /** |
||
66 | * Get the value of a property of this class. |
||
67 | * |
||
68 | * @param $name |
||
69 | * @return mixed |
||
70 | * @throws Exception |
||
71 | */ |
||
72 | public function __get($name) |
||
82 | |||
83 | /** |
||
84 | * Get a fresh instance of this class. |
||
85 | * |
||
86 | * @return RevisionOptions |
||
87 | */ |
||
88 | public static function instance(): self |
||
92 | |||
93 | /** |
||
94 | * Set the $revisionOnCreate to work with in the Neurony\Revisions\Traits\HasRevisions trait. |
||
95 | * |
||
96 | * @return RevisionOptions |
||
97 | */ |
||
98 | public function enableRevisionOnCreate(): self |
||
104 | |||
105 | /** |
||
106 | * Set the $revisionLimit to work with in the Neurony\Revisions\Traits\HasRevisions trait. |
||
107 | * |
||
108 | * @param int $limit |
||
109 | * @return RevisionOptions |
||
110 | */ |
||
111 | public function limitRevisionsTo(int $limit): self |
||
117 | |||
118 | /** |
||
119 | * Set the $revisionFields to work with in the Neurony\Revisions\Traits\HasRevisions trait. |
||
120 | * |
||
121 | * @param $fields |
||
122 | * @return RevisionOptions |
||
123 | */ |
||
124 | public function fieldsToRevision(...$fields): self |
||
130 | |||
131 | /** |
||
132 | * Set the $revisionNotFields to work with in the Neurony\Revisions\Traits\HasRevisions trait. |
||
133 | * |
||
134 | * @param $fields |
||
135 | * @return RevisionOptions |
||
136 | */ |
||
137 | public function fieldsToNotRevision(...$fields): self |
||
143 | |||
144 | /** |
||
145 | * Set the $revisionRelations to work with in the Neurony\Revisions\Traits\HasRevisions trait. |
||
146 | * |
||
147 | * @param $relations |
||
148 | * @return RevisionOptions |
||
149 | */ |
||
150 | public function relationsToRevision(...$relations): self |
||
156 | |||
157 | /** |
||
158 | * Set the $createRevisionWhenRollingBack to work with in the Neurony\Revisions\Traits\HasRevisions trait. |
||
159 | * |
||
160 | * @return RevisionOptions |
||
161 | */ |
||
162 | public function disableRevisioningWhenRollingBack(): self |
||
168 | |||
169 | /** |
||
170 | * Enable the revisioning of timestamps. |
||
171 | * |
||
172 | * @return $this |
||
173 | */ |
||
174 | public function withTimestamps() |
||
180 | } |
||
181 |