NotOptional.php 674 B

123456789101112131415161718192021222324252627282930313233
  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. * Validates if the given input is not optional.
  11. *
  12. * By optional we consider null or an empty string ('').
  13. *
  14. * @author Danilo Correa <danilosilva87@gmail.com>
  15. * @author Henrique Moody <henriquemoody@gmail.com>
  16. */
  17. final class NotOptional extends AbstractRule
  18. {
  19. use CanValidateUndefined;
  20. /**
  21. * {@inheritDoc}
  22. */
  23. public function validate($input): bool
  24. {
  25. return $this->isUndefined($input) === false;
  26. }
  27. }