web-fu / proxy
Library that allows to access array and object and proxy them
v1.0.1
2025-01-30 11:33 UTC
Requires
- php: 8.0.* || 8.1.* || 8.2.* || 8.3.* || 8.4.*
- web-fu/reflection: ^2.4
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.13
- phpstan/phpstan: ^1.9
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2025-01-30 11:36:14 UTC
README
A library that allows to create proxies for array and objects
This library allows to create proxies for arrays and objects.
This is a spin-off of the PHP Dot Notation library.
Installation
composer require web-fu/proxy
Create a Proxy
$element = [ 'foo' => 'bar', 'zod' => [ 'baz' => 'qux', ], ]; $proxy = new Proxy($element);
Getting and setting values
echo $proxy->get('foo'); //bar $proxy->set('foo', 'baz'); echo $element['foo']; //baz
Checking keys
echo $proxy->has('foo'); //true echo $proxy->isInitialised('foo'); //true echo $proxy->dynamicKeysAllowed(); //true;
Creating and destroying keys
$proxy->create('rol', 'foo'); echo $element['rol']; //foo $proxy->unset('zod'); var_dump($element); //['foo' => 'bar']
Getting a proxy for a key
$proxy->getProxy('zod')->set('baz', 'qux'); echo $element['zod']['baz']; //qux
See /examples
folder for full examples