rekalogika/direct-property-access
Implementation of Symfony's PropertyAccessorInterface
that reads and writes
directly to the object's properties, bypassing getters and setters.
Synopsis
use Rekalogika\DirectPropertyAccess\DirectPropertyAccessor;
class Person
{
private string $name = 'Jane';
}
$propertyAccessor = new DirectPropertyAccessor();
$name = $propertyAccessor->getValue($person, 'name'); // Jane
$propertyAccessor->setValue($person, 'name', 'John');
Installation
Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.
- With Symfony Flex
- Without Symfony Flex
- Non-Symfony Projects
Open a command console, enter your project directory, and execute:
composer require rekalogika/direct-property-access
Step 1: Download the Bundle
Open a command console, enter your project directory, and execute the following command to download the latest stable version of this bundle:
composer require rekalogika/direct-property-access
Step 2: Enable the Bundle
Then, enable the bundle by adding it to the list of registered bundles
in the config/bundles.php
file of your project:
return [
// ...
Rekalogika\DirectPropertyAccess\RekalogikaDirectPropertyAccessBundle::class => ['all' => true],
];
Open a command console, enter your project directory, and execute:
composer require rekalogika/direct-property-access
Usage
In Symfony projects, you can autowire DirectPropertyAccessor
. In other
projects, you can simply instantiate it.
Read Symfony's PropertyAccess
documentation
for more information on how to use it. The difference is that
DirectPropertyAccessor
does not call any of the object's methods, but reads
and writes directly to the object's properties, even if they are private.
Caveats
Currently does not support arrays and paths beyond one level deep.
Credits
This project took inspiration from the following projects.
License
MIT
Contributing
Issues and pull requests should be filed in the GitHub repository rekalogika/direct-property-access.