AbstractWrapper.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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\Validatable;
  9. /**
  10. * Abstract class to help on creating rules that wrap rules.
  11. *
  12. * @author Alasdair North <alasdair@runway.io>
  13. * @author Henrique Moody <henriquemoody@gmail.com>
  14. */
  15. abstract class AbstractWrapper extends AbstractRule
  16. {
  17. /**
  18. * @var Validatable
  19. */
  20. private $validatable;
  21. /**
  22. * Initializes the rule.
  23. */
  24. public function __construct(Validatable $validatable)
  25. {
  26. $this->validatable = $validatable;
  27. }
  28. /**
  29. * {@inheritDoc}
  30. */
  31. public function assert($input): void
  32. {
  33. $this->validatable->assert($input);
  34. }
  35. /**
  36. * {@inheritDoc}
  37. */
  38. public function check($input): void
  39. {
  40. $this->validatable->check($input);
  41. }
  42. /**
  43. * {@inheritDoc}
  44. */
  45. public function validate($input): bool
  46. {
  47. return $this->validatable->validate($input);
  48. }
  49. /**
  50. * {@inheritDoc}
  51. */
  52. public function setName(string $name): Validatable
  53. {
  54. $this->validatable->setName($name);
  55. return parent::setName($name);
  56. }
  57. }