ArrayVal.php 818 B

1234567891011121314151617181920212223242526272829303132333435
  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 ArrayAccess;
  9. use SimpleXMLElement;
  10. use function is_array;
  11. /**
  12. * Validates if the input is an array or if the input can be used as an array.
  13. *
  14. * Instance of `ArrayAccess` or `SimpleXMLElement` are also considered as valid.
  15. *
  16. * @author Alexandre Gomes Gaigalas <alganet@gmail.com>
  17. * @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
  18. * @author Henrique Moody <henriquemoody@gmail.com>
  19. */
  20. final class ArrayVal extends AbstractRule
  21. {
  22. /**
  23. * {@inheritDoc}
  24. */
  25. public function validate($input): bool
  26. {
  27. return is_array($input) || $input instanceof ArrayAccess || $input instanceof SimpleXMLElement;
  28. }
  29. }