Skip to content

Commit

Permalink
feature #3729 Added documentation for the new PropertyAccessor::isRea…
Browse files Browse the repository at this point in the history
…dable() and isWritable() methods (webmozart)

This PR was merged into the master branch.

Discussion
----------

Added documentation for the new PropertyAccessor::isReadable() and isWritable() methods

| Q             | A
| ------------- | ---
| Doc fix?      | no
| New docs?     | yes (symfony/symfony#10570)
| Applies to    | 2.5+
| Fixed tickets | -

Commits
-------

bb8e3ed Added documentation for the new PropertyAccessor::isReadable() and isWritable() methods
  • Loading branch information
weaverryan committed Apr 12, 2014
2 parents cedfdce + bb8e3ed commit be4b9d3
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 be4b9d3

Please sign in to comment.