Exception
8 months ago
AbstractEnum.php
8 months ago
EnumMap.php
8 months ago
NullValue.php
8 months ago
NullValue.php
76 lines
| 1 | <?php |
| 2 | declare(strict_types = 1); |
| 3 | |
| 4 | namespace DASPRiD\Enum; |
| 5 | |
| 6 | use DASPRiD\Enum\Exception\CloneNotSupportedException; |
| 7 | use DASPRiD\Enum\Exception\SerializeNotSupportedException; |
| 8 | use DASPRiD\Enum\Exception\UnserializeNotSupportedException; |
| 9 | |
| 10 | final class NullValue |
| 11 | { |
| 12 | /** |
| 13 | * @var self |
| 14 | */ |
| 15 | private static $instance; |
| 16 | |
| 17 | private function __construct() |
| 18 | { |
| 19 | } |
| 20 | |
| 21 | public static function instance() : self |
| 22 | { |
| 23 | return self::$instance ?: self::$instance = new self(); |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * Forbid cloning enums. |
| 28 | * |
| 29 | * @throws CloneNotSupportedException |
| 30 | */ |
| 31 | final public function __clone() |
| 32 | { |
| 33 | throw new CloneNotSupportedException(); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Forbid serializing enums. |
| 38 | * |
| 39 | * @throws SerializeNotSupportedException |
| 40 | */ |
| 41 | final public function __sleep() : array |
| 42 | { |
| 43 | throw new SerializeNotSupportedException(); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Forbid serializing enums. |
| 48 | * |
| 49 | * @throws SerializeNotSupportedException |
| 50 | */ |
| 51 | final public function __serialize() : array |
| 52 | { |
| 53 | throw new SerializeNotSupportedException(); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Forbid unserializing enums. |
| 58 | * |
| 59 | * @throws UnserializeNotSupportedException |
| 60 | */ |
| 61 | final public function __wakeup() : void |
| 62 | { |
| 63 | throw new UnserializeNotSupportedException(); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Forbid unserializing enums. |
| 68 | * |
| 69 | * @throws UnserializeNotSupportedException |
| 70 | */ |
| 71 | final public function __unserialize($arg) : void |
| 72 | { |
| 73 | throw new UnserializeNotSupportedException(); |
| 74 | } |
| 75 | } |
| 76 |