Exception
1 year ago
CHANGELOG.md
1 year ago
LICENSE
1 year ago
PropertyAccess.php
4 years ago
PropertyAccessor.php
1 year ago
PropertyAccessorBuilder.php
1 year ago
PropertyAccessorInterface.php
1 year ago
PropertyPath.php
1 year ago
PropertyPathBuilder.php
1 year ago
PropertyPathInterface.php
1 year ago
PropertyPathIterator.php
1 year ago
PropertyPathIteratorInterface.php
1 year ago
README.md
4 years ago
composer.json
1 year ago
PropertyAccessorInterface.php
115 lines
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | * This file is part of the Symfony package. |
| 5 | * |
| 6 | * (c) Fabien Potencier <fabien@symfony.com> |
| 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\PropertyAccess; |
| 13 | |
| 14 | /** |
| 15 | * Writes and reads values to/from an object/array graph. |
| 16 | * |
| 17 | * @author Bernhard Schussek <bschussek@gmail.com> |
| 18 | */ |
| 19 | interface PropertyAccessorInterface |
| 20 | { |
| 21 | /** |
| 22 | * Sets the value at the end of the property path of the object graph. |
| 23 | * |
| 24 | * Example: |
| 25 | * |
| 26 | * use Symfony\Component\PropertyAccess\PropertyAccess; |
| 27 | * |
| 28 | * $propertyAccessor = PropertyAccess::createPropertyAccessor(); |
| 29 | * |
| 30 | * echo $propertyAccessor->setValue($object, 'child.name', 'Fabien'); |
| 31 | * // equals echo $object->getChild()->setName('Fabien'); |
| 32 | * |
| 33 | * This method first tries to find a public setter for each property in the |
| 34 | * path. The name of the setter must be the camel-cased property name |
| 35 | * prefixed with "set". |
| 36 | * |
| 37 | * If the setter does not exist, this method tries to find a public |
| 38 | * property. The value of the property is then changed. |
| 39 | * |
| 40 | * If neither is found, an exception is thrown. |
| 41 | * |
| 42 | * @param object|array $objectOrArray The object or array to modify |
| 43 | * @param string|PropertyPathInterface $propertyPath The property path to modify |
| 44 | * @param mixed $value The value to set at the end of the property path |
| 45 | * |
| 46 | * @throws Exception\InvalidArgumentException If the property path is invalid |
| 47 | * @throws Exception\AccessException If a property/index does not exist or is not public |
| 48 | * @throws Exception\UnexpectedTypeException If a value within the path is neither object nor array |
| 49 | */ |
| 50 | public function setValue(&$objectOrArray, $propertyPath, $value); |
| 51 | |
| 52 | /** |
| 53 | * Returns the value at the end of the property path of the object graph. |
| 54 | * |
| 55 | * Example: |
| 56 | * |
| 57 | * use Symfony\Component\PropertyAccess\PropertyAccess; |
| 58 | * |
| 59 | * $propertyAccessor = PropertyAccess::createPropertyAccessor(); |
| 60 | * |
| 61 | * echo $propertyAccessor->getValue($object, 'child.name'); |
| 62 | * // equals echo $object->getChild()->getName(); |
| 63 | * |
| 64 | * This method first tries to find a public getter for each property in the |
| 65 | * path. The name of the getter must be the camel-cased property name |
| 66 | * prefixed with "get", "is", or "has". |
| 67 | * |
| 68 | * If the getter does not exist, this method tries to find a public |
| 69 | * property. The value of the property is then returned. |
| 70 | * |
| 71 | * If none of them are found, an exception is thrown. |
| 72 | * |
| 73 | * @param object|array $objectOrArray The object or array to traverse |
| 74 | * @param string|PropertyPathInterface $propertyPath The property path to read |
| 75 | * |
| 76 | * @return mixed |
| 77 | * |
| 78 | * @throws Exception\InvalidArgumentException If the property path is invalid |
| 79 | * @throws Exception\AccessException If a property/index does not exist or is not public |
| 80 | * @throws Exception\UnexpectedTypeException If a value within the path is neither object |
| 81 | * nor array |
| 82 | */ |
| 83 | public function getValue($objectOrArray, $propertyPath); |
| 84 | |
| 85 | /** |
| 86 | * Returns whether a value can be written at a given property path. |
| 87 | * |
| 88 | * Whenever this method returns true, {@link setValue()} is guaranteed not |
| 89 | * to throw an exception when called with the same arguments. |
| 90 | * |
| 91 | * @param object|array $objectOrArray The object or array to check |
| 92 | * @param string|PropertyPathInterface $propertyPath The property path to check |
| 93 | * |
| 94 | * @return bool |
| 95 | * |
| 96 | * @throws Exception\InvalidArgumentException If the property path is invalid |
| 97 | */ |
| 98 | public function isWritable($objectOrArray, $propertyPath); |
| 99 | |
| 100 | /** |
| 101 | * Returns whether a property path can be read from an object graph. |
| 102 | * |
| 103 | * Whenever this method returns true, {@link getValue()} is guaranteed not |
| 104 | * to throw an exception when called with the same arguments. |
| 105 | * |
| 106 | * @param object|array $objectOrArray The object or array to check |
| 107 | * @param string|PropertyPathInterface $propertyPath The property path to check |
| 108 | * |
| 109 | * @return bool |
| 110 | * |
| 111 | * @throws Exception\InvalidArgumentException If the property path is invalid |
| 112 | */ |
| 113 | public function isReadable($objectOrArray, $propertyPath); |
| 114 | } |
| 115 |