Nullable.php 920 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /*
  3. * Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
  4. * SPDX-License-Identifier: MIT
  5. */
  6. declare(strict_types=1);
  7. namespace Respect\Validation\Rules;
  8. /**
  9. * Validates the given input with a defined rule when input is not NULL.
  10. *
  11. * @author Jens Segers <segers.jens@gmail.com>
  12. */
  13. final class Nullable extends AbstractWrapper
  14. {
  15. /**
  16. * {@inheritDoc}
  17. */
  18. public function assert($input): void
  19. {
  20. if ($input === null) {
  21. return;
  22. }
  23. parent::assert($input);
  24. }
  25. /**
  26. * {@inheritDoc}
  27. */
  28. public function check($input): void
  29. {
  30. if ($input === null) {
  31. return;
  32. }
  33. parent::check($input);
  34. }
  35. /**
  36. * {@inheritDoc}
  37. */
  38. public function validate($input): bool
  39. {
  40. if ($input === null) {
  41. return true;
  42. }
  43. return parent::validate($input);
  44. }
  45. }