Instance.php 867 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 if the input is an instance of the given class or interface.
  10. *
  11. * @author Alexandre Gomes Gaigalas <alganet@gmail.com>
  12. * @author Danilo Benevides <danilobenevides01@gmail.com>
  13. * @author Henrique Moody <henriquemoody@gmail.com>
  14. */
  15. final class Instance extends AbstractRule
  16. {
  17. /**
  18. * @var string
  19. */
  20. private $instanceName;
  21. /**
  22. * Initializes the rule with the expected instance name.
  23. */
  24. public function __construct(string $instanceName)
  25. {
  26. $this->instanceName = $instanceName;
  27. }
  28. /**
  29. * {@inheritDoc}
  30. */
  31. public function validate($input): bool
  32. {
  33. return $input instanceof $this->instanceName;
  34. }
  35. }