8000 [PropertyAccess] Update the method directives by javiereguiluz · Pull Request #12811 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

[PropertyAccess] Update the method directives #12811

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 14, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
8000
Diff view
[PropertyAccess] Update the method directives
  • Loading branch information
javiereguiluz committed Dec 13, 2019
commit fc44076e1edb32e8da65cf664f73ba43abfa2b02
25 changes: 11 additions & 14 deletions components/property_access.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ 8000 Usage
-----

The entry point of this component is the
:method:`PropertyAccess::createPropertyAccessor<Symfony\\Component\\PropertyAccess\\PropertyAccess::createPropertyAccessor>`
:method:`Symfony\\Component\\PropertyAccess\\PropertyAccess::createPropertyAccessor`
factory. This factory will create a new instance of the
:class:`Symfony\\Component\\PropertyAccess\\PropertyAccessor` class with the
default configuration::
Expand All @@ -34,8 +34,8 @@ Reading from Arrays
-------------------

You can read an array with the
:method:`PropertyAccessor::getValue<Symfony\\Component\\PropertyAccess\\PropertyAccessor::getValue>`
method. This is done using the index notation that is used in PHP::
:method:`Symfony\\Component\\PropertyAccess\\PropertyAccessor::getValue` method.
This is done using the index notation that is used in PHP::

// ...
$person = [
Expand Down Expand Up @@ -175,7 +175,7 @@ Accessing a non Existing Property Path
Symfony 4.3.

By default a :class:`Symfony\\Component\\PropertyAccess\\Exception\\NoSuchPropertyException`
is thrown if the property path passed to :method:`PropertyAccessor::getValue<Symfony\\Component\\PropertyAccess\\PropertyAccessor::getValue>`
is thrown if the property path passed to :method:`Symfony\\Component\\PropertyAccess\\PropertyAccessor::getValue`
does not exist. You can change this behavior using the
:method:`Symfony\\Component\\PropertyAccess\\PropertyAccessorBuilder::disableExceptionOnInvalidPropertyPath`
method::
Expand Down Expand Up @@ -259,16 +259,15 @@ enable this feature by using :class:`Symfony\\Component\\PropertyAccess\\Propert
.. caution::

The ``__call()`` feature is disabled by default, you can enable it by calling
:method:`PropertyAccessorBuilder::enableMagicCall<Symfony\\Component\\PropertyAccess\\PropertyAccessorBuilder::enableMagicCall>`
:method:`Symfony\\Component\\PropertyAccess\\PropertyAccessorBuilder::enableMagicCall`
see `Enable other Features`_.

Writing to Arrays
-----------------

The ``PropertyAccessor`` class can do more than just read an array, it can
also write to an array. This can be achieved using the
:method:`PropertyAccessor::setValue<Symfony\\Component\\PropertyAccess\\PropertyAccessor::setValue>`
method::
:method:`Symfony\\Component\\PropertyAccess\\PropertyAccessor::setValue` method::

// ...
$person = [];
Expand Down Expand Up @@ -404,20 +403,18 @@ Checking Property Paths
-----------------------

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::
:method:`Symfony\\Component\\PropertyAccess\\PropertyAccessor::getValue` can
safely be called without actually calling that method, you can use
:method:`Symfony\\Component\\PropertyAccess\\PropertyAccessor::isReadable` instead::

$person = new Person();

if ($propertyAccessor->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>`
The same is possible for :method:`Symfony\\Component\\PropertyAccess\\PropertyAccessor::setValue`:
Call the :method:`Symfony\\Component\\PropertyAccess\\PropertyAccessor::isWritable`
method to find out whether a property path can be updated::

$person = new Person();
Expand Down
0