ocramius/proxy-manager
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
laminas/laminas-code | 4.13.0 | 86.34 kB | BSD-3-Clause | prod | |
webimpress/safe-writer | 2.2.0 | 21.49 kB | BSD-2-Clause | prod |
The ocramius/proxy-manager is a PHP library created to provide abstract utilities for generating, instantiating, and manipulating Object Proxies. Object Proxies are vital tools within PHP for creating various kinds of proxy classes. The ocramius/proxy-manager utilises the proxy pattern, granting the ability to control when and how the original objects perform certain actions by creating interfaces that they can interact with.
To make use of the ocramius/proxy-manager, you need to install it via composer. The suggested command for installation is:
php composer.phar require ocramius/proxy-manager
Once installed, an example of how to use ocramius/proxy-manager to build a lazy loading object with ProxyManager using a Virtual Proxy would be:
$factory = new \ProxyManager\Factory\LazyLoadingValueHolderFactory();
$proxy = $factory->createProxy(
\MyApp\HeavyComplexObject::class,
function (& $wrappedObject, $proxy, $method, $parameters, & $initializer) {
$wrappedObject = new \MyApp\HeavyComplexObject(); // instantiation logic here
$initializer = null; // turning off further lazy initialization
return true; // report success
}
);
$proxy->doFoo();
The proxy invokes the instantiation logic for any class only when needed which leads to savings in terms of resources.
The official documentation for the ocramius/proxy-manager, where you can learn about the proxy pattern and how to use the ProxyManager, can be found on its github repository under the docs
folder. In this doc, a broad range of proxy types are covered along with extensive usage examples. Such information is essential for unlocking the full potential and understanding the various applications of the ocramius/proxy-manager.