@@ -90,6 +90,8 @@ file looks like this::
90
90
[]
91
91
);
92
92
93
+ .. _instantiating-php-classes :
94
+
93
95
Instantiating & Hydrating PHP Classes
94
96
-------------------------------------
95
97
@@ -101,18 +103,18 @@ their properties without calling their constructors or any other methods::
101
103
102
104
use Symfony\Component\VarExporter\Instantiator;
103
105
104
- // Creates an empty instance of Foo
106
+ // creates an empty instance of Foo
105
107
$fooObject = Instantiator::instantiate(Foo::class);
106
108
107
- // Creates a Foo instance and sets one of its properties
109
+ // creates a Foo instance and sets one of its properties
108
110
$fooObject = Instantiator::instantiate(Foo::class, ['propertyName' => $propertyValue]);
109
111
110
- The instantiator also allows you to populate the property of a parent class. Assuming
111
- `` Bar `` is the parent class of ``Foo `` and defines a ``privateBarProperty `` attribute::
112
+ The instantiator can also populate the property of a parent class. Assuming `` Bar ``
113
+ is the parent class of ``Foo `` and defines a ``privateBarProperty `` attribute::
112
114
113
115
use Symfony\Component\VarExporter\Instantiator;
114
116
115
- // Creates a Foo instance and sets a private property defined on its parent Bar class
117
+ // creates a Foo instance and sets a private property defined on its parent Bar class
116
118
$fooObject = Instantiator::instantiate(Foo::class, [], [
117
119
Bar::class => ['privateBarProperty' => $propertyValue],
118
120
]);
@@ -122,7 +124,7 @@ created by using the special ``"\0"`` property name to define their internal val
122
124
123
125
use Symfony\Component\VarExporter\Instantiator;
124
126
125
- // Creates an SplObjectStorage where $info1 is associated with $object1, etc.
127
+ // creates an SplObjectStorage where $info1 is associated with $object1, etc.
126
128
$theObject = Instantiator::instantiate(SplObjectStorage::class, [
127
129
"\0" => [$object1, $info1, $object2, $info2...],
128
130
]);
@@ -135,8 +137,8 @@ created by using the special ``"\0"`` property name to define their internal val
135
137
Hydrator
136
138
~~~~~~~~
137
139
138
- The instantiator assumes the object you want to populate doesn 't exist yet.
139
- Somehow, you may want to fill properties of an already existing object. This is
140
+ Instead of populating objects that don 't exist yet (using the instantiator),
141
+ sometimes you want to populate properties of an already existing object. This is
140
142
the goal of the :class: `Symfony\\ Component\\ VarExporter\\ Hydrator `. Here is a
141
143
basic usage of the hydrator populating a property of an object::
142
144
@@ -145,8 +147,8 @@ basic usage of the hydrator populating a property of an object::
145
147
$object = new Foo();
146
148
Hydrator::hydrate($object, ['propertyName' => $propertyValue]);
147
149
148
- The hydrator also allows you to populate the property of a parent class. Assuming
149
- `` Bar `` is the parent class of ``Foo `` and defines a ``privateBarProperty `` attribute::
150
+ The hydrator can also populate the property of a parent class. Assuming `` Bar ``
151
+ is the parent class of ``Foo `` and defines a ``privateBarProperty `` attribute::
150
152
151
153
use Symfony\Component\VarExporter\Hydrator;
152
154
@@ -155,15 +157,15 @@ The hydrator also allows you to populate the property of a parent class. Assumin
155
157
Bar::class => ['privateBarProperty' => $propertyValue],
156
158
]);
157
159
158
- // Alternatively , you can use the special "\0" syntax
160
+ // alternatively , you can use the special "\0" syntax
159
161
Hydrator::hydrate($object, ["\0Bar\0privateBarProperty" => $propertyValue]);
160
162
161
163
Instances of ``ArrayObject ``, ``ArrayIterator `` and ``SplObjectHash `` can be
162
164
populated by using the special ``"\0" `` property name to define their internal value::
163
165
164
166
use Symfony\Component\VarExporter\Hydrator;
165
167
166
- // Creates an SplObjectHash where $info1 is associated with $object1, etc.
168
+ // creates an SplObjectHash where $info1 is associated with $object1, etc.
167
169
$storage = new SplObjectStorage();
168
170
Hydrator::hydrate($storage, [
169
171
"\0" => [$object1, $info1, $object2, $info2...],
0 commit comments