-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disallow serialization with Serializable interface (#11)
- Loading branch information
Showing
2 changed files
with
29 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
use Dbalabka\Enumeration\Exception\EnumerationException; | ||
use Dbalabka\Enumeration\Exception\InvalidArgumentException; | ||
use Dbalabka\StaticConstructorLoader\StaticConstructorInterface; | ||
use Serializable; | ||
use function array_search; | ||
use function get_class_vars; | ||
use function sprintf; | ||
|
@@ -18,7 +19,7 @@ | |
* | ||
* @author Dmitry Balabka <[email protected]> | ||
*/ | ||
abstract class Enumeration implements StaticConstructorInterface | ||
abstract class Enumeration implements StaticConstructorInterface, Serializable | ||
{ | ||
const INITIAL_ORDINAL = 0; | ||
|
||
|
@@ -158,6 +159,7 @@ final public function __clone() | |
|
||
/** | ||
* Serialization is not allowed right now. It is not possible to properly serialize the singleton. | ||
* See the documentation for workaround. | ||
*/ | ||
final public function __sleep() | ||
{ | ||
|
@@ -168,4 +170,24 @@ final public function __wakeup() | |
{ | ||
throw new EnumerationException('Enum unserialization is not allowed'); | ||
} | ||
|
||
final public function __serialize() | ||
{ | ||
throw new EnumerationException('Enum serialization is not allowed'); | ||
} | ||
|
||
final public function __unserialize() | ||
{ | ||
throw new EnumerationException('Enum unserialization is not allowed'); | ||
} | ||
|
||
final public function serialize() | ||
{ | ||
throw new EnumerationException('Enum serialization is not allowed'); | ||
} | ||
|
||
final public function unserialize($data) | ||
{ | ||
throw new EnumerationException('Enum unserialization is not allowed'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters