Equals.php 808 B

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