PHPackages                             alpa/tools\_proxy\_object - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. alpa/tools\_proxy\_object

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

alpa/tools\_proxy\_object
=========================

Creates a proxy object and assigns getter / setter handlers to the object's members when accessing them.

v1.0.14(2y ago)0612MITPHPPHP ^7.4||^8

Since Mar 20Pushed 2y ago1 watchersCompare

[ Source](https://github.com/alexeyp0708/php_tools_proxy_object)[ Packagist](https://packagist.org/packages/alpa/tools_proxy_object)[ RSS](/packages/alpa-tools-proxy-object/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (1)Versions (12)Used By (2)

Dev work plan
-------------

[](#dev-work-plan)

install
-------

[](#install)

`composer require alpa/tools_proxy_object:1.0.14`

Changes
-------

[](#changes)

- v1.0.12 Added the ability to return the result by reference (For actions: get,call,invoke) - Warn: No backward compatibility
- v1.0.13 Added check for property initialization before passing by reference- compatible with prev version
- v1.0.14 Bugs fixed error :Only variable references should be retuned (or assigned) by reference . - Warn: No backward compatibility . Closures for get action, call action, invoke action now needs to be declared by reference ( `function & (){}` ), and the result returned via a variable. There is now an abstract class for creating new proxies. Interfaces were created for the purpose of dependency inversion.

Description
-----------

[](#description)

A proxy object is an object that implements all the available magic methods that run the corresponding handlers. These handlers perform a number of custom actions on the target object.
Basically, this behavior is necessary for processing the result when accessing properties or methods of the target object.
In simple words:

- before getting / writing the value of the property of the target object, it must be processed in the sandbox.
- before executing the target object method, it needs to be processed in the sandbox.

The component creates a proxy object for the observed object or class.
Action handlers (get | set | call | isset | unset | invoke | toString | iterator) are assigned for each member of the observable object or class .
A similar principle is implemented in javascript through the Proxy constructor.
When accessing a member of an object, through the proxy object, the assigned handler for the specific action will be invoked.

Where the component can be applied:

- mediator for data validation;
- access to private data of an object through reflection;
- dynamic data formation, and generation of other properties;
- dynamic data requests, for example from a database;
- other options.

Note
----

[](#note)

### 1

[](#1)

From version 1.0.0 to version 1.1.0 is experimental development, where the API will be subject to modification.
See the tag description on GitHub for version compatibility.
When including a component in a project, specify a specific version.
The description of the api for a specific version can be found in the commit version.

### 2

[](#2)

If for some reason you have bugs or other problems, then it is recommended to implement your own handlers classes that fix this problem. See - [Creating handler classes](#creating-handler-classes)

### 3

[](#3)

The proxy object is a wrapper object that implements magic methods. By default it is not possible to access protected / private members of an observable object / class. The default proxy only works with the public members of the observable / class. If you need the ability to work with protected / private members of an object / class, use Reflector classes in action handlers.

### 4

[](#4)

Not the fact that the use of proxy objects will be fast. But in any case, this is the optimal solution for creating complex combinations and in a simple way.

Install
-------

[](#install-1)

`composer require alpa/tools_proxy_object`

Getting started
---------------

[](#getting-started)

example 1:

```
