symfony/property-access
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
symfony/property-info | v7.0.7 | - | MIT | prod |
The Symfony PropertyAccess component offers the utility of reading and writing from/to any object or array leveraging a straightforward string notation. This PHP package simplifies interaction with arrays or objects, especially when dealing with dynamic key or property names.
Making use of the Symfony PropertyAccess is quite simple. We start by installing it using composer.
composer require symfony/property-access
Here's an example of how to use this package:
use Symfony\Component\PropertyAccess\PropertyAccess;
$accessor = PropertyAccess::createPropertyAccessor();
$arrayData = array(
'firstName' => 'Johnny',
'lastName' => 'Cash'
);
echo $accessor->getValue($arrayData, '[firstName]');
// output: Johnny
$accessor->setValue($arrayData, '[firstName]', 'Elvis');
echo $accessor->getValue($arrayData, '[firstName]');
// output: Elvis
In this code, we create a property accessor, and define an array. We can get and set values in the array using the getValue()
and setValue()
functions respectively, alongside the string notation to refer to the array keys.
The full documentation for the Symfony PropertyAccess package can be found on the Symfony Documentation Website. It provides in-depth knowledge, including detailed usage, functionality, and configuration options for the package.