MetadataInterface.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. * A container for validation metadata.
  13. *
  14. * The container contains constraints that may belong to different validation
  15. * groups. Constraints for a specific group can be fetched by calling
  16. * {@link findConstraints}.
  17. *
  18. * Implement this interface to add validation metadata to your own metadata
  19. * layer. Each metadata may have named properties. Each property can be
  20. * represented by one or more {@link PropertyMetadataInterface} instances that
  21. * are returned by {@link getPropertyMetadata}. Since
  22. * <tt>PropertyMetadataInterface</tt> inherits from <tt>MetadataInterface</tt>,
  23. * each property may be divided into further properties.
  24. *
  25. * The {@link accept} method of each metadata implements the Visitor pattern.
  26. * The method should forward the call to the visitor's
  27. * {@link ValidationVisitorInterface::visit} method and additionally call
  28. * <tt>accept()</tt> on all structurally related metadata instances.
  29. *
  30. * For example, to store constraints for PHP classes and their properties,
  31. * create a class <tt>ClassMetadata</tt> (implementing <tt>MetadataInterface</tt>)
  32. * and a class <tt>PropertyMetadata</tt> (implementing <tt>PropertyMetadataInterface</tt>).
  33. * <tt>ClassMetadata::getPropertyMetadata($property)</tt> returns all
  34. * <tt>PropertyMetadata</tt> instances for a property of that class. Its
  35. * <tt>accept()</tt>-method simply forwards to <tt>ValidationVisitorInterface::visit()</tt>
  36. * and calls <tt>accept()</tt> on all contained <tt>PropertyMetadata</tt>
  37. * instances, which themselves call <tt>ValidationVisitorInterface::visit()</tt>
  38. * again.
  39. *
  40. * @author Bernhard Schussek <bschussek@gmail.com>
  41. *
  42. * @deprecated since version 2.5, to be removed in 3.0.
  43. * Use {@link Mapping\MetadataInterface} instead.
  44. */
  45. interface MetadataInterface
  46. {
  47. /**
  48. * Implementation of the Visitor design pattern.
  49. *
  50. * Calls {@link ValidationVisitorInterface::visit} and then forwards the
  51. * <tt>accept()</tt>-call to all property metadata instances.
  52. *
  53. * @param ValidationVisitorInterface $visitor The visitor implementing the validation logic
  54. * @param mixed $value The value to validate
  55. * @param string|string[] $group The validation group to validate in
  56. * @param string $propertyPath The current property path in the validation graph
  57. *
  58. * @deprecated since version 2.5, to be removed in 3.0.
  59. */
  60. public function accept(ValidationVisitorInterface $visitor, $value, $group, $propertyPath);
  61. /**
  62. * Returns all constraints for a given validation group.
  63. *
  64. * @param string $group The validation group
  65. *
  66. * @return Constraint[] A list of constraint instances
  67. */
  68. public function findConstraints($group);
  69. }