|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <[email protected]> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Component\Validator\Context; |
| 13 | + |
| 14 | +use Symfony\Component\Validator\ConstraintViolationListInterface; |
| 15 | +use Symfony\Component\Validator\Mapping\MetadataInterface; |
| 16 | +use Symfony\Component\Validator\Validator\ValidatorInterface; |
| 17 | + |
| 18 | +/** |
| 19 | + * @since %%NextVersion%% |
| 20 | + * @author Bernhard Schussek <[email protected]> |
| 21 | + */ |
| 22 | +interface ExecutionContextInterface |
| 23 | +{ |
| 24 | + /** |
| 25 | + * @return ValidatorInterface |
| 26 | + */ |
| 27 | + public function getValidator(); |
| 28 | + |
| 29 | + /** |
| 30 | + * Adds a violation at the current node of the validation graph. |
| 31 | + * |
| 32 | + * @param string $message The error message. |
| 33 | + * @param array $params The parameters substituted in the error message. |
| 34 | + * |
| 35 | + * @api |
| 36 | + */ |
| 37 | + public function addViolation($message, array $params = array()); |
| 38 | + |
| 39 | + public function buildViolation($message); |
| 40 | + |
| 41 | + /** |
| 42 | + * Returns the violations generated by the validator so far. |
| 43 | + * |
| 44 | + * @return ConstraintViolationListInterface The constraint violation list. |
| 45 | + * |
| 46 | + * @api |
| 47 | + */ |
| 48 | + public function getViolations(); |
| 49 | + |
| 50 | + /** |
| 51 | + * Returns the value at which validation was started in the object graph. |
| 52 | + * |
| 53 | + * The validator, when given an object, traverses the properties and |
| 54 | + * related objects and their properties. The root of the validation is the |
| 55 | + * object from which the traversal started. |
| 56 | + * |
| 57 | + * The current value is returned by {@link getValue}. |
| 58 | + * |
| 59 | + * @return mixed The root value of the validation. |
| 60 | + */ |
| 61 | + public function getRoot(); |
| 62 | + |
| 63 | + /** |
| 64 | + * Returns the value that the validator is currently validating. |
| 65 | + * |
| 66 | + * If you want to retrieve the object that was originally passed to the |
| 67 | + * validator, use {@link getRoot}. |
| 68 | + * |
| 69 | + * @return mixed The currently validated value. |
| 70 | + */ |
| 71 | + public function getValue(); |
| 72 | + |
| 73 | + /** |
| 74 | + * Returns the metadata for the currently validated value. |
| 75 | + * |
| 76 | + * With the core implementation, this method returns a |
| 77 | + * {@link Mapping\ClassMetadata} instance if the current value is an object, |
| 78 | + * a {@link Mapping\PropertyMetadata} instance if the current value is |
| 79 | + * the value of a property and a {@link Mapping\GetterMetadata} instance if |
| 80 | + * the validated value is the result of a getter method. |
| 81 | + * |
| 82 | + * If the validated value is neither of these, for example if the validator |
| 83 | + * has been called with a plain value and constraint, this method returns |
| 84 | + * null. |
| 85 | + * |
| 86 | + * @return MetadataInterface|null The metadata of the currently validated |
| 87 | + * value. |
| 88 | + */ |
| 89 | + public function getMetadata(); |
| 90 | + |
| 91 | + public function getMetadataFor($object); |
| 92 | + |
| 93 | + /** |
| 94 | + * Returns the validation group that is currently being validated. |
| 95 | + * |
| 96 | + * @return string The current validation group. |
| 97 | + */ |
| 98 | + public function getGroup(); |
| 99 | + |
| 100 | + /** |
| 101 | + * Returns the class name of the current node. |
| 102 | + * |
| 103 | + * If the metadata of the current node does not implement |
| 104 | + * {@link ClassBasedInterface} or if no metadata is available for the |
| 105 | + * current node, this method returns null. |
| 106 | + * |
| 107 | + * @return string|null The class name or null, if no class name could be found. |
| 108 | + */ |
| 109 | + public function getClassName(); |
| 110 | + |
| 111 | + /** |
| 112 | + * Returns the property name of the current node. |
| 113 | + * |
| 114 | + * If the metadata of the current node does not implement |
| 115 | + * {@link PropertyMetadataInterface} or if no metadata is available for the |
| 116 | + * current node, this method returns null. |
| 117 | + * |
| 118 | + * @return string|null The property name or null, if no property name could be found. |
| 119 | + */ |
| 120 | + public function getPropertyName(); |
| 121 | + |
| 122 | + /** |
| 123 | + * Returns the property path to the value that the validator is currently |
| 124 | + * validating. |
| 125 | + * |
| 126 | + * For example, take the following object graph: |
| 127 | + * |
| 128 | + * <pre> |
| 129 | + * (Person)---($address: Address)---($street: string) |
| 130 | + * </pre> |
| 131 | + * |
| 132 | + * When the <tt>Person</tt> instance is passed to the validator, the |
| 133 | + * property path is initially empty. When the <tt>$address</tt> property |
| 134 | + * of that person is validated, the property path is "address". When |
| 135 | + * the <tt>$street</tt> property of the related <tt>Address</tt> instance |
| 136 | + * is validated, the property path is "address.street". |
| 137 | + * |
| 138 | + * Properties of objects are prefixed with a dot in the property path. |
| 139 | + * Indices of arrays or objects implementing the {@link \ArrayAccess} |
| 140 | + * interface are enclosed in brackets. For example, if the property in |
| 141 | + * the previous example is <tt>$addresses</tt> and contains an array |
| 142 | + * of <tt>Address</tt> instance, the property path generated for the |
| 143 | + * <tt>$street</tt> property of one of these addresses is for example |
| 144 | + * "addresses[0].street". |
| 145 | + * |
| 146 | + * @param string $subPath Optional. The suffix appended to the current |
| 147 | + * property path. |
| 148 | + * |
| 149 | + * @return string The current property path. The result may be an empty |
| 150 | + * string if the validator is currently validating the |
| 151 | + * root value of the validation graph. |
| 152 | + */ |
| 153 | + public function getPropertyPath($subPath = ''); |
| 154 | +} |
0 commit comments