Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bb8e3ed

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

File tree

Expand file treeCollapse file tree

1 file changed

+33
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+33
-0
lines changed

‎components/property_access/introduction.rst

Copy file name to clipboardExpand all lines: components/property_access/introduction.rst
+33Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.