5
5
The PropertyAccess Component
6
6
============================
7
7
8
- PropertyAccess component provides function to read and write from/to an
8
+ The PropertyAccess component provides function to read and write from/to an
9
9
object or array using a simple string notation.
10
10
11
11
.. versionadded :: 2.2
@@ -18,26 +18,26 @@ Installation
18
18
You can install the component in two different ways:
19
19
20
20
* Use the official Git repository (https://github.com/symfony/PropertyAccess);
21
- * :doc: `Install it via Composer</components/using_components> ` * (``symfony/property-access `` on `Packagist `_).
21
+ * :doc: `Install it via Composer</components/using_components> ` (``symfony/property-access `` on `Packagist `_).
22
22
23
23
Usage
24
24
-----
25
25
26
26
The entry point of this component is the
27
- :method: `Symfony\\ Component\\ PropertyAccess\\ PropertyAccess::getPropertyAccessor `
27
+ :method: `PropertyAccess::getPropertyAccessor< Symfony\\ Component\\ PropertyAccess\\ PropertyAccess::getPropertyAccessor> `
28
28
factory. This factory will create a new instance of the
29
- :class: `Symfony\\ Component\\ PropertyAccess\P ropertyAccessor ` class with the
29
+ :class: `Symfony\\ Component\\ PropertyAccess\\ PropertyAccessor ` class with the
30
30
default configuration::
31
31
32
32
use Symfony\Component\PropertyAccess\PropertyAccess;
33
33
34
- $accessor = PropertyAccess:getPropertyAccessor();
34
+ $accessor = PropertyAccess:: getPropertyAccessor();
35
35
36
- Reading from arrays
36
+ Reading from Arrays
37
37
-------------------
38
38
39
39
You can read an array with the
40
- :method: `Symfony\\ Component\\ PropertyAccess\P ropertyAccessor::getValue `
40
+ :method: `PropertyAccessor::getValue< Symfony\\ Component\\ PropertyAccess\\ PropertyAccessor::getValue> `
41
41
method. This is done using the index notation that is used in PHP::
42
42
43
43
// ...
@@ -65,37 +65,37 @@ You can also use multi dimensional arrays::
65
65
echo $accessor->getValue($persons, '[0][first_name]'); // 'Wouter'
66
66
echo $accessor->getValue($persons, '[1][first_name]'); // 'Ryan'
67
67
68
- Reading from objects
68
+ Reading from Objects
69
69
--------------------
70
70
71
- The ``getValue `` method is a very robust method. You can see all features if
72
- you are working with objects.
71
+ The ``getValue `` method is a very robust method, and you can see all of its
72
+ features when working with objects.
73
73
74
- Using properties
75
- ~~~~~~~~~~~~~~~~
74
+ Accessing public Properties
75
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
76
76
77
- We can read properties without the index notation, instead we use the dot
78
- notation::
77
+ To read from properties, use the "dot" notation::
79
78
80
79
// ...
81
80
$person = new Person();
82
81
$person->firstName = 'Wouter';
83
82
84
- echo $accessor->getValue($person, 'first_name '); // 'Wouter'
83
+ echo $accessor->getValue($person, 'firstName '); // 'Wouter'
85
84
86
85
$child = new Person();
87
86
$child->firstName = 'Bar';
88
87
$person->children = array($child);
89
88
90
- echo $accessor->getValue($person, 'children[0].first_name '); // 'Bar'
89
+ echo $accessor->getValue($person, 'children[0].firstName '); // 'Bar'
91
90
92
91
.. caution ::
93
92
94
- This option is the last option used by the ``PropertyAccessor ``. It tries
95
- to find the other options before using the property. If you have a public
96
- property that have a getter to, it will use the getter.
93
+ Accessing public properties is the last option used by ``PropertyAccessor ``.
94
+ It tries to access the value using the below methods first before using
95
+ the property directly. For example, if you have a public property that
96
+ has a getter method, it will use the getter.
97
97
98
- Using getters
98
+ Using Getters
99
99
~~~~~~~~~~~~~
100
100
101
101
The ``getValue `` method also supports reading using getters. The method will
@@ -118,11 +118,11 @@ property name (``first_name`` becomes ``FirstName``) and prefixes it with
118
118
119
119
echo $accessor->getValue($person, 'first_name'); // 'Wouter'
120
120
121
- Using hassers/issers
121
+ Using Hassers/Issers
122
122
~~~~~~~~~~~~~~~~~~~~
123
123
124
124
And it doesn't even stop there. If there is no getter found, the accessor will
125
- look for a isser or hasser. This method is created using the same way as
125
+ look for an isser or hasser. This method is created using the same way as
126
126
getters, this means that you can do something like this::
127
127
128
128
// ...
@@ -156,7 +156,7 @@ This will produce: ``He is an author``
156
156
Magic Methods
157
157
~~~~~~~~~~~~~
158
158
159
- At last, the ``getValue `` can use the magic ``__get `` too::
159
+ At last, ``getValue `` can use the magic ``__get `` method too::
160
160
161
161
// ...
162
162
class Person
@@ -175,12 +175,12 @@ At last, the ``getValue`` can use the magic ``__get`` too::
175
175
176
176
echo $accessor->getValue($person, 'Wouter'); // array(...)
177
177
178
- Writing to arrays
178
+ Writing to Arrays
179
179
-----------------
180
180
181
- The ``PropertyAccessor `` class can do more than just reading an array, it can
181
+ The ``PropertyAccessor `` class can do more than just read an array, it can
182
182
also write to an array. This can be achieved using the
183
- :method: `Symfony\\ Component\\ PropertyAccess\\ PropertyAccessor::setValue `
183
+ :method: `PropertyAccessor::setValue< Symfony\\ Component\\ PropertyAccess\\ PropertyAccessor::setValue> `
184
184
method::
185
185
186
186
// ...
@@ -192,7 +192,7 @@ method::
192
192
// or
193
193
// echo $person['first_name']; // 'Wouter'
194
194
195
- Writing to objects
195
+ Writing to Objects
196
196
------------------
197
197
198
198
The ``setValue `` method has the same features as the ``getValue `` method. You
@@ -228,7 +228,7 @@ can use setters, the magic ``__set`` or properties to set values::
228
228
echo $person->getLastName(); // 'de Jong'
229
229
echo $person->children; // array(Person());
230
230
231
- Mixing objects and arrays
231
+ Mixing Objects and Arrays
232
232
-------------------------
233
233
234
234
You can also mix objects and arrays::
0 commit comments