From bb8e3ed3ee2ebd141acb5c572efcdfbecf5d5b2d Mon Sep 17 00:00:00 2001 From: Bernhard Schussek Date: Fri, 28 Mar 2014 17:33:52 +0100 Subject: [PATCH] Added documentation for the new PropertyAccessor::isReadable() and isWritable() methods --- components/property_access/introduction.rst | 33 +++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/components/property_access/introduction.rst b/components/property_access/introduction.rst index 07177d15b5f..2fabbf2119b 100644 --- a/components/property_access/introduction.rst +++ b/components/property_access/introduction.rst @@ -309,6 +309,39 @@ see `Enable other Features`_. echo $person->getWouter(); // array(...) +Checking Property Paths +----------------------- + +.. versionadded:: 2.5 + The methods + :method:`PropertyAccessor::isReadable` + and + :method:`PropertyAccessor::isWritable` + methods were added in Symfony 2.5. + +When you want to check whether :method:`PropertyAccessor::getValue` +can safely be called without actually calling that method, you can use +:method:`PropertyAccessor::isReadable` +instead:: + + $person = new Person(); + + if ($accessor->isReadable($person, 'firstName') { + // ... + } + +The same is possible for :method:`PropertyAccessor::setValue`: +Call the +:method:`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 -------------------------