4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\PropertyAccess
;
15 * Writes and reads values to/from an object/array graph.
17 * @author Bernhard Schussek <bschussek@gmail.com>
19 interface PropertyAccessorInterface
22 * Sets the value at the end of the property path of the object
26 * use Symfony\Component\PropertyAccess\PropertyAccess;
28 * $propertyAccessor = PropertyAccess::getPropertyAccessor();
30 * echo $propertyAccessor->setValue($object, 'child.name', 'Fabien');
31 * // equals echo $object->getChild()->setName('Fabien');
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".
37 * If the setter does not exist, this method tries to find a public
38 * property. The value of the property is then changed.
40 * If neither is found, an exception is thrown.
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
46 * @throws Exception\NoSuchPropertyException If a property does not exist or is not public.
47 * @throws Exception\UnexpectedTypeException If a value within the path is neither object
50 public function setValue(&$objectOrArray, $propertyPath, $value);
53 * Returns the value at the end of the property path of the object
57 * use Symfony\Component\PropertyAccess\PropertyAccess;
59 * $propertyAccessor = PropertyAccess::getPropertyAccessor();
61 * echo $propertyAccessor->getValue($object, 'child.name);
62 * // equals echo $object->getChild()->getName();
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".
68 * If the getter does not exist, this method tries to find a public
69 * property. The value of the property is then returned.
71 * If none of them are found, an exception is thrown.
73 * @param object|array $objectOrArray The object or array to traverse
74 * @param string|PropertyPathInterface $propertyPath The property path to read
76 * @return mixed The value at the end of the property path
78 * @throws Exception\NoSuchPropertyException If a property does not exist or is not public.
80 public function getValue($objectOrArray, $propertyPath);