web-fu / proxy
Library that allows to access array and object and proxy them
v1.0.0
2024-10-09 13:02 UTC
Requires
- php: 8.0.* || 8.1.* || 8.2.* || 8.3.*
- web-fu/reflection: ^2.3
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.13
- phpstan/phpstan: ^1.9
- phpunit/phpunit: ^9.5
- vimeo/psalm: ^5.4
This package is auto-updated.
Last update: 2024-11-10 07:54:30 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
Usage
For arrays:
$element = [ 'foo' => 'bar', ]; $proxy = new ArrayProxy($element); echo $proxy->has('foo'); //true echo $proxy->isInitialised('foo'); //true echo $proxy->get('foo'); //bar $proxy->set('foo', 'baz'); echo $element['foo']; //baz
For objects:
$element = new class() { public string $property = 'test'; public function method(): string { return 'foo'; } }; $proxy = new ClassProxy($element); echo $proxy->has('property'); //true echo $proxy->isInitialised('property'); //true echo $proxy->get('property'); //test echo $proxy->has('method()'); //true echo $proxy->isInitialised('method()'); //true echo $proxy->get('method()'); //foo $proxy->set('property', 'baz'); echo $element->property; //baz
For both:
$element = [ 'foo' => 'bar', ]; $proxy = ProxyFactory::create($element);