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 | * Get the value of a property of this class. |
||
60 | * |
||
61 | * @param $name |
||
62 | * @return mixed |
||
63 | * @throws Exception |
||
64 | */ |
||
65 | public function __get($name) |
||
75 | |||
76 | /** |
||
77 | * Get a fresh instance of this class. |
||
78 | * |
||
79 | * @return RevisionOptions |
||
80 | */ |
||
81 | public static function instance(): self |
||
85 | |||
86 | /** |
||
87 | * Set the $revisionOnCreate to work with in the Neurony\Revisions\Traits\HasRevisions trait. |
||
88 | * |
||
89 | * @return RevisionOptions |
||
90 | */ |
||
91 | public function enableRevisionOnCreate(): self |
||
97 | |||
98 | /** |
||
99 | * Set the $revisionLimit to work with in the Neurony\Revisions\Traits\HasRevisions trait. |
||
100 | * |
||
101 | * @param int $limit |
||
102 | * @return RevisionOptions |
||
103 | */ |
||
104 | public function limitRevisionsTo(int $limit): self |
||
110 | |||
111 | /** |
||
112 | * Set the $revisionFields to work with in the Neurony\Revisions\Traits\HasRevisions trait. |
||
113 | * |
||
114 | * @param $fields |
||
115 | * @return RevisionOptions |
||
116 | */ |
||
117 | public function fieldsToRevision(...$fields): self |
||
123 | |||
124 | /** |
||
125 | * Set the $revisionNotFields to work with in the Neurony\Revisions\Traits\HasRevisions trait. |
||
126 | * |
||
127 | * @param $fields |
||
128 | * @return RevisionOptions |
||
129 | */ |
||
130 | public function fieldsToNotRevision(...$fields): self |
||
136 | |||
137 | /** |
||
138 | * Set the $revisionRelations to work with in the Neurony\Revisions\Traits\HasRevisions trait. |
||
139 | * |
||
140 | * @param $relations |
||
141 | * @return RevisionOptions |
||
142 | */ |
||
143 | public function relationsToRevision(...$relations): self |
||
149 | |||
150 | /** |
||
151 | * Set the $createRevisionWhenRollingBack to work with in the Neurony\Revisions\Traits\HasRevisions trait. |
||
152 | * |
||
153 | * @return RevisionOptions |
||
154 | */ |
||
155 | public function disableRevisioningWhenRollingBack(): self |
||
161 | } |
||
162 |