Skip to content

Commit

Permalink
Added documentation for the new PropertyAccessor::isReadable() and is…
Browse files Browse the repository at this point in the history
…Writable() methods
  • Loading branch information
webmozart committed Mar 28, 2014
1 parent 80045df commit bb8e3ed
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions components/property_access/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,39 @@ see `Enable other Features`_.
echo $person->getWouter(); // array(...)
Checking Property Paths
-----------------------

.. versionadded:: 2.5
The methods
:method:`PropertyAccessor::isReadable<Symfony\\Component\\PropertyAccess\\PropertyAccessor::isReadable>`
and
:method:`PropertyAccessor::isWritable<Symfony\\Component\\PropertyAccess\\PropertyAccessor::isWritable>`
methods were added in Symfony 2.5.

When you want to check whether :method:`PropertyAccessor::getValue<Symfony\\Component\\PropertyAccess\\PropertyAccessor::getValue>`
can safely be called without actually calling that method, you can use
:method:`PropertyAccessor::isReadable<Symfony\\Component\\PropertyAccess\\PropertyAccessor::isReadable>`
instead::

$person = new Person();

if ($accessor->isReadable($person, 'firstName') {
// ...
}

The same is possible for :method:`PropertyAccessor::setValue<Symfony\\Component\\PropertyAccess\\PropertyAccessor::setValue>`:
Call the
:method:`PropertyAccessor::isWritable<Symfony\\Component\\PropertyAccess\\PropertyAccessor::isWritable>`
method to find out whether a property path can be updated. In the third
argument, you should pass the value that you want to write::

$person = new Person();

if ($accessor->isWritable($person, 'firstName', 'Wouter') {
// ...
}

Mixing Objects and Arrays
-------------------------

Expand Down

0 comments on commit bb8e3ed

Please sign in to comment.