Drupal investigation

ValidationVisitorInterface.php 3.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Validator;
  11. /**
  12. * Validates values against constraints defined in {@link MetadataInterface}
  13. * instances.
  14. *
  15. * This interface is an implementation of the Visitor design pattern. A value
  16. * is validated by first passing it to the {@link validate} method. That method
  17. * will determine the matching {@link MetadataInterface} for validating the
  18. * value. It then calls the {@link MetadataInterface::accept} method of that
  19. * metadata. <tt>accept()</tt> does two things:
  20. *
  21. * <ol>
  22. * <li>It calls {@link visit} to validate the value against the constraints of
  23. * the metadata.</li>
  24. * <li>It calls <tt>accept()</tt> on all nested metadata instances with the
  25. * corresponding values extracted from the current value. For example, if the
  26. * current metadata represents a class and the current value is an object of
  27. * that class, the metadata contains nested instances for each property of that
  28. * class. It forwards the call to these nested metadata with the values of the
  29. * corresponding properties in the original object.</li>
  30. * </ol>
  31. *
  32. * @author Bernhard Schussek <bschussek@gmail.com>
  33. *
  34. * @deprecated since version 2.5, to be removed in 3.0.
  35. */
  36. interface ValidationVisitorInterface
  37. {
  38. /**
  39. * Validates a value.
  40. *
  41. * If the value is an array or a traversable object, you can set the
  42. * parameter <tt>$traverse</tt> to <tt>true</tt> in order to run through
  43. * the collection and validate each element. If these elements can be
  44. * collections again and you want to traverse them recursively, set the
  45. * parameter <tt>$deep</tt> to <tt>true</tt> as well.
  46. *
  47. * If you set <tt>$traversable</tt> to <tt>true</tt>, the visitor will
  48. * nevertheless try to find metadata for the collection and validate its
  49. * constraints. If no such metadata is found, the visitor ignores that and
  50. * only iterates the collection.
  51. *
  52. * If you don't set <tt>$traversable</tt> to <tt>true</tt> and the visitor
  53. * does not find metadata for the given value, it will fail with an
  54. * exception.
  55. *
  56. * @param mixed $value The value to validate
  57. * @param string $group The validation group to validate
  58. * @param string $propertyPath The current property path in the validation graph
  59. * @param bool $traverse Whether to traverse the value if it is traversable
  60. * @param bool $deep Whether to traverse nested traversable values recursively
  61. *
  62. * @throws Exception\NoSuchMetadataException If no metadata can be found for
  63. * the given value.
  64. */
  65. public function validate($value, $group, $propertyPath, $traverse = false, $deep = false);
  66. /**
  67. * Validates a value against the constraints defined in some metadata.
  68. *
  69. * This method implements the Visitor design pattern. See also
  70. * {@link ValidationVisitorInterface}.
  71. *
  72. * @param MetadataInterface $metadata The metadata holding the constraints
  73. * @param mixed $value The value to validate
  74. * @param string $group The validation group to validate
  75. * @param string $propertyPath The current property path in the validation graph
  76. */
  77. public function visit(MetadataInterface $metadata, $value, $group, $propertyPath);
  78. }