Debian Codegraph @

lib/3rdParty/composer/symfony/property-access/PropertyAccessorInterface.php

raw symbols SCIP
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\PropertyAccess;
13
14 /**
15 * Writes and reads values to/from an object/array graph.
16 *
17 * @author Bernhard Schussek <[email protected]>
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 * @template T of object|array
43 *
44 * @param T $objectOrArray
45 *
46 * @param-out ($objectOrArray is array ? array : T) $objectOrArray
47 *
48 * @throws Exception\InvalidArgumentException If the property path is invalid
49 * @throws Exception\AccessException If a property/index does not exist or is not public
50 * @throws Exception\UnexpectedTypeException If a value within the path is neither object nor array
51 */
52 public function setValue(object|array &$objectOrArray, string|PropertyPathInterface $propertyPath, mixed $value): void;
53
54 /**
55 * Returns the value at the end of the property path of the object graph.
56 *
57 * Example:
58 *
59 * use Symfony\Component\PropertyAccess\PropertyAccess;
60 *
61 * $propertyAccessor = PropertyAccess::createPropertyAccessor();
62 *
63 * echo $propertyAccessor->getValue($object, 'child.name');
64 * // equals echo $object->getChild()->getName();
65 *
66 * This method first tries to find a public getter for each property in the
67 * path. The name of the getter must be the camel-cased property name
68 * prefixed with "get", "is", or "has".
69 *
70 * If the getter does not exist, this method tries to find a public
71 * property. The value of the property is then returned.
72 *
73 * If none of them are found, an exception is thrown.
74 *
75 * @throws Exception\InvalidArgumentException If the property path is invalid
76 * @throws Exception\AccessException If a property/index does not exist or is not public
77 * @throws Exception\UnexpectedTypeException If a value within the path is neither object
78 * nor array
79 */
80 public function getValue(object|array $objectOrArray, string|PropertyPathInterface $propertyPath): mixed;
81
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 * @throws Exception\InvalidArgumentException If the property path is invalid
89 */
90 public function isWritable(object|array $objectOrArray, string|PropertyPathInterface $propertyPath): bool;
91
92 /**
93 * Returns whether a property path can be read from an object graph.
94 *
95 * Whenever this method returns true, {@link getValue()} is guaranteed not
96 * to throw an exception when called with the same arguments.
97 *
98 * @throws Exception\InvalidArgumentException If the property path is invalid
99 */
100 public function isReadable(object|array $objectOrArray, string|PropertyPathInterface $propertyPath): bool;
101 }