PHPackages                             stratadox/proxy - 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. stratadox/proxy

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

stratadox/proxy
===============

v0.4(5y ago)1408[2 PRs](https://github.com/Stratadox/Proxy/pulls)2MITPHPPHP &gt;=7.2

Since Feb 9Pushed 3y ago1 watchersCompare

[ Source](https://github.com/Stratadox/Proxy)[ Packagist](https://packagist.org/packages/stratadox/proxy)[ RSS](/packages/stratadox-proxy/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (8)Versions (11)Used By (2)

Proxy
=====

[](#proxy)

[![Build Status](https://camo.githubusercontent.com/b23773dd6cd8de6121408f149f35afff83ee085c47706956ca3b2975a973e9c3/68747470733a2f2f7472617669732d63692e6f72672f537472617461646f782f50726f78792e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Stratadox/Proxy)[![Coverage Status](https://camo.githubusercontent.com/0bbff2755eaab666738b8fe079ab54e7d34be61521f59b9425a1a2517a924f51/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f537472617461646f782f50726f78792f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/Stratadox/Proxy?branch=master)[![Infection Minimum](https://camo.githubusercontent.com/416cfd74a77aee9719fd9a0c0b5f9dd6970485b055c1e9a4cd01ce05e08a1754/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6d73692d3130302d627269676874677265656e2e737667)](https://travis-ci.org/Stratadox/Proxy)[![PhpStan level](https://camo.githubusercontent.com/e58915c82e085736fd9da556ddfcae809f3d34c62575773ffeae09481619c66a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068707374616e2d372d627269676874677265656e2e737667)](https://travis-ci.org/Stratadox/Proxy)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/d69947cad0d111e977aec24b10d62f546e685b524daf25b4d930a0d1ebbad76d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f537472617461646f782f50726f78792f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Stratadox/Proxy/?branch=master)[![Maintainability](https://camo.githubusercontent.com/95904a61a76e553861d26f9996e8a49fa030e757e4ba92726bc7b27a86d63478/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f66656533313231393032343131636539393464612f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/Stratadox/Proxy/maintainability)[![Latest Stable Version](https://camo.githubusercontent.com/cd3f214a0929ef9d043d97e85d002421d85c4c007110f927d6760d1d013cf756/68747470733a2f2f706f7365722e707567782e6f72672f737472617461646f782f70726f78792f762f737461626c65)](https://packagist.org/packages/stratadox/proxy)[![License](https://camo.githubusercontent.com/a3b23b37a5701c61824208e777f11f79e5c144183affbf8dd34009e996162cea/68747470733a2f2f706f7365722e707567782e6f72672f737472617461646f782f70726f78792f6c6963656e7365)](https://packagist.org/packages/stratadox/proxy)

[![Implements](https://camo.githubusercontent.com/6bcfbb03d5cf753c1c7d010fc4cab923b88b7231cb9e7827e40176c4c5787637/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f696e74657266616365732d6769746875622d626c75652e737667)](https://github.com/Stratadox/ProxyContracts)[![Latest Stable Version](https://camo.githubusercontent.com/b97deebea81db404ddc8fb744706d6ef851106f669d2aa46882a76010191f0b8/68747470733a2f2f706f7365722e707567782e6f72672f737472617461646f782f70726f78792d636f6e7472616374732f762f737461626c65)](https://packagist.org/packages/stratadox/proxy-contracts)[![License](https://camo.githubusercontent.com/562c0ba3fea26f5c810bc358e11259459c9a676e8f5a5926e7ff6d032aee509c/68747470733a2f2f706f7365722e707567782e6f72672f737472617461646f782f70726f78792d636f6e7472616374732f6c6963656e7365)](https://packagist.org/packages/stratadox/proxy-contracts)

Virtual proxies, fine-tuned for use in lazy loading.

Installation
------------

[](#installation)

Install using composer:

`composer require stratadox/proxy`

What is this?
-------------

[](#what-is-this)

An implementation of the [Virtual Proxy pattern](https://en.wikipedia.org/wiki/Proxy_pattern#Virtual_proxy). Virtual proxies can take the place of "real" objects. They serve as placeholders for objects that are expensive to load.

The proxied objects may have to be retrieved from a database or remote web server. They may just require loads of memory, or require plenty of other such objects. When requests need only **some** of these objects, it can cause terrible performance problems to load **all** of them.

Why use this?
-------------

[](#why-use-this)

Using this package, you can provide your objects with proxies. These surrogates do not require database queries, and require only little memory. They satisfy the dependency demands of your class, without the overhead of the "actual" objects.

When to use this?
-----------------

[](#when-to-use-this)

Virtual proxies like these are great for lazily loading the relationships of the entities in the domain model.

Let's say that you have a Shop. We all hope for the shop to have a lot of Customers. And for the Customers to place a lot of Orders. The more the better!

However... **loading** *all* those Customers, with *all* their orders, requires a lot of memory. Retrieving, organizing and sending the data may take a very long time.

In order to provide the Shop access to any customer, without loading all the customers, we can use CustomerProxy objects.

How does it work?
-----------------

[](#how-does-it-work)

The [proxies](https://github.com/Stratadox/Proxy#proxies) are subclasses of the real entities. That way, they satisfy all type checks. Proxies overwrite all public methods of the base class.

When one of these methods is called, the proxy gets loaded. This triggers the construction of the "expensive" object. Once loaded, the method that was called on the proxy is now called on the [real object](https://github.com/Stratadox/Proxy#real-object). All future calls upon the proxy get redirected immediately, without loading.

How to use?
-----------

[](#how-to-use)

### Creating a proxy loader

[](#creating-a-proxy-loader)

Proxy loaders implement the ProxyLoader interface:

```
