NullValue.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. declare(strict_types = 1);
  3. namespace DASPRiD\Enum;
  4. use DASPRiD\Enum\Exception\CloneNotSupportedException;
  5. use DASPRiD\Enum\Exception\SerializeNotSupportedException;
  6. use DASPRiD\Enum\Exception\UnserializeNotSupportedException;
  7. final class NullValue
  8. {
  9. /**
  10. * @var self
  11. */
  12. private static $instance;
  13. private function __construct()
  14. {
  15. }
  16. public static function instance() : self
  17. {
  18. return self::$instance ?: self::$instance = new self();
  19. }
  20. /**
  21. * Forbid cloning enums.
  22. *
  23. * @throws CloneNotSupportedException
  24. */
  25. final public function __clone()
  26. {
  27. throw new CloneNotSupportedException();
  28. }
  29. /**
  30. * Forbid serializing enums.
  31. *
  32. * @throws SerializeNotSupportedException
  33. */
  34. final public function __sleep() : array
  35. {
  36. throw new SerializeNotSupportedException();
  37. }
  38. /**
  39. * Forbid unserializing enums.
  40. *
  41. * @throws UnserializeNotSupportedException
  42. */
  43. final public function __wakeup() : void
  44. {
  45. throw new UnserializeNotSupportedException();
  46. }
  47. }