66use Dbalabka \Enumeration \Exception \EnumerationException ;
77use Dbalabka \Enumeration \Exception \InvalidArgumentException ;
88use Dbalabka \StaticConstructorLoader \StaticConstructorInterface ;
9+ use Serializable ;
910use function array_search ;
1011use function get_class_vars ;
1112use function sprintf ;
1819 *
1920 * @author Dmitry Balabka <dmitry.balabka@gmail.com>
2021 */
21- abstract class Enumeration implements StaticConstructorInterface
22+ abstract class Enumeration implements StaticConstructorInterface, Serializable
2223{
2324 const INITIAL_ORDINAL = 0 ;
2425
@@ -158,6 +159,7 @@ final public function __clone()
158159
159160 /**
160161 * Serialization is not allowed right now. It is not possible to properly serialize the singleton.
162+ * See the documentation for workaround.
161163 */
162164 final public function __sleep ()
163165 {
@@ -168,4 +170,24 @@ final public function __wakeup()
168170 {
169171 throw new EnumerationException ('Enum unserialization is not allowed ' );
170172 }
173+
174+ final public function __serialize ()
175+ {
176+ throw new EnumerationException ('Enum serialization is not allowed ' );
177+ }
178+
179+ final public function __unserialize ()
180+ {
181+ throw new EnumerationException ('Enum unserialization is not allowed ' );
182+ }
183+
184+ final public function serialize ()
185+ {
186+ throw new EnumerationException ('Enum serialization is not allowed ' );
187+ }
188+
189+ final public function unserialize ($ data )
190+ {
191+ throw new EnumerationException ('Enum unserialization is not allowed ' );
192+ }
171193}
0 commit comments