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