Optional.php 967 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. use Respect\Validation\Helpers\CanValidateUndefined;
  9. /**
  10. * @author Henrique Moody <henriquemoody@gmail.com>
  11. */
  12. final class Optional extends AbstractWrapper
  13. {
  14. use CanValidateUndefined;
  15. /**
  16. * {@inheritDoc}
  17. */
  18. public function assert($input): void
  19. {
  20. if ($this->isUndefined($input)) {
  21. return;
  22. }
  23. parent::assert($input);
  24. }
  25. /**
  26. * {@inheritDoc}
  27. */
  28. public function check($input): void
  29. {
  30. if ($this->isUndefined($input)) {
  31. return;
  32. }
  33. parent::check($input);
  34. }
  35. /**
  36. * {@inheritDoc}
  37. */
  38. public function validate($input): bool
  39. {
  40. if ($this->isUndefined($input)) {
  41. return true;
  42. }
  43. return parent::validate($input);
  44. }
  45. }