web-fu/proxy

Library that allows to access array and object and proxy them

v1.0.1 2025-01-30 11:33 UTC

This package is auto-updated.

Last update: 2025-01-30 11:36:14 UTC


README

Latest Stable Version PHP Version Require Test status Static analysis status Code style status

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