Skip to content

Commit bb8e3ed

Browse files
committed
Added documentation for the new PropertyAccessor::isReadable() and isWritable() methods
1 parent 80045df commit bb8e3ed

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

components/property_access/introduction.rst

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,39 @@ see `Enable other Features`_.
309309
310310
echo $person->getWouter(); // array(...)
311311
312+
Checking Property Paths
313+
-----------------------
314+
315+
.. versionadded:: 2.5
316+
The methods
317+
:method:`PropertyAccessor::isReadable<Symfony\\Component\\PropertyAccess\\PropertyAccessor::isReadable>`
318+
and
319+
:method:`PropertyAccessor::isWritable<Symfony\\Component\\PropertyAccess\\PropertyAccessor::isWritable>`
320+
methods were added in Symfony 2.5.
321+
322+
When you want to check whether :method:`PropertyAccessor::getValue<Symfony\\Component\\PropertyAccess\\PropertyAccessor::getValue>`
323+
can safely be called without actually calling that method, you can use
324+
:method:`PropertyAccessor::isReadable<Symfony\\Component\\PropertyAccess\\PropertyAccessor::isReadable>`
325+
instead::
326+
327+
$person = new Person();
328+
329+
if ($accessor->isReadable($person, 'firstName') {
330+
// ...
331+
}
332+
333+
The same is possible for :method:`PropertyAccessor::setValue<Symfony\\Component\\PropertyAccess\\PropertyAccessor::setValue>`:
334+
Call the
335+
:method:`PropertyAccessor::isWritable<Symfony\\Component\\PropertyAccess\\PropertyAccessor::isWritable>`
336+
method to find out whether a property path can be updated. In the third
337+
argument, you should pass the value that you want to write::
338+
339+
$person = new Person();
340+
341+
if ($accessor->isWritable($person, 'firstName', 'Wouter') {
342+
// ...
343+
}
344+
312345
Mixing Objects and Arrays
313346
-------------------------
314347

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy