1 | <?php |
||
50 | trait WriteProtectTab |
||
51 | { |
||
52 | /** |
||
53 | * we start in read-write mode |
||
54 | * @var boolean |
||
55 | */ |
||
56 | private $readOnly = false; |
||
57 | |||
58 | /** |
||
59 | * by default, the read-only mode can be togged on and off |
||
60 | * @var boolean |
||
61 | */ |
||
62 | private $readOnlyForever = false; |
||
63 | |||
64 | /** |
||
65 | * can we edit this entity? |
||
66 | * |
||
67 | * @return boolean |
||
68 | * FALSE if we can edit this entity |
||
69 | * TRUE otherwise |
||
70 | */ |
||
71 | public function isReadOnly() |
||
75 | |||
76 | /** |
||
77 | * can we edit this entity? |
||
78 | * |
||
79 | * @return boolean |
||
80 | * TRUE if we can edit this entity |
||
81 | * FALSE otherwise |
||
82 | */ |
||
83 | public function isReadWrite() |
||
91 | |||
92 | /** |
||
93 | * disable editing this entity |
||
94 | * |
||
95 | * you can re-enable editing this entity by calling ::setReadWrite() |
||
96 | * |
||
97 | * @return void |
||
98 | */ |
||
99 | public function setReadOnly() |
||
103 | |||
104 | /** |
||
105 | * disable editing this entity forever |
||
106 | * |
||
107 | * after calling this method, any attempt to call ::setReadWrite() will |
||
108 | * cause a ReadOnlyForever exception |
||
109 | * |
||
110 | * @return void |
||
111 | */ |
||
112 | public function setReadOnlyForever() |
||
117 | |||
118 | /** |
||
119 | * enable editing this entity |
||
120 | * |
||
121 | * @throws ReadOnlyForeverException |
||
122 | * @return void |
||
123 | */ |
||
124 | public function setReadWrite() |
||
137 | |||
138 | /** |
||
139 | * throw an exception if the object is not in read-write mode |
||
140 | * |
||
141 | * @return void |
||
142 | * @throws ReadOnlyException |
||
143 | */ |
||
144 | protected function requireReadWrite() |
||
155 | } |
||
156 |