Identical.php 710 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 identical to some value.
  10. *
  11. * @author Henrique Moody <henriquemoody@gmail.com>
  12. */
  13. final class Identical extends AbstractRule
  14. {
  15. /**
  16. * @var mixed
  17. */
  18. private $compareTo;
  19. /**
  20. * Initializes the rule.
  21. *
  22. * @param mixed $compareTo
  23. */
  24. public function __construct($compareTo)
  25. {
  26. $this->compareTo = $compareTo;
  27. }
  28. /**
  29. * {@inheritDoc}
  30. */
  31. public function validate($input): bool
  32. {
  33. return $input === $this->compareTo;
  34. }
  35. }