296 lines
11 KiB
HTML
296 lines
11 KiB
HTML
<!DOCTYPE html>
|
|
<html class="no-js" id="top">
|
|
<head>
|
|
<title>ProxyManager</title>
|
|
|
|
<meta name="description" content="A proxyManager write in php" />
|
|
<meta name="keywords" content="ProxyManager, proxy, manager, ocramius, Marco Pivetta, php" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
|
|
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:200,300,400,600' rel='stylesheet' type='text/css'>
|
|
<link href="css/styles.css" rel="stylesheet" />
|
|
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/styles/default.min.css">
|
|
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/highlight.min.js"></script>
|
|
<script>hljs.initHighlightingOnLoad();</script>
|
|
<link rel="shortcut icon" href="favicon.ico">
|
|
</head>
|
|
<body>
|
|
|
|
<header class="site-header">
|
|
<div class="container">
|
|
<h1><a href="index.html"><img alt="ProxyManager" src="img/block.png" /></a></h1>
|
|
|
|
<nav class="main-nav" role="navigation">
|
|
<ul>
|
|
<li><a href="https://github.com/Ocramius/ProxyManager" target="_blank">Github</a>
|
|
<div class="bcms-clearfix"></div>
|
|
</li>
|
|
</ul>
|
|
</nav>
|
|
</div>
|
|
</header>
|
|
<main role="main">
|
|
<section class="component-content"><div class="page-title-wrapper">
|
|
<div class="container">
|
|
<img src="https://github.com/Ocramius/ProxyManager/raw/master/proxy-manager.png">
|
|
<h2 class="page-title">Proxy Manager</h2>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="component-demo" id="live-demo">
|
|
<div class="container">
|
|
<div class="main-wrapper" style="text-align: right">
|
|
<iframe src="http://ghbtns.com/github-btn.html?user=ocramius&repo=ProxyManager&type=fork&count=true&size=large"
|
|
allowtransparency="true" frameborder="0" scrolling="0" width="310" height="40"></iframe>
|
|
|
|
<iframe src="http://ghbtns.com/github-btn.html?user=ocramius&repo=ProxyManager&type=watch&count=true&size=large"
|
|
allowtransparency="true" frameborder="0" scrolling="0" width="200" height="40"></iframe>
|
|
|
|
</div>
|
|
<div class="bcms-clearfix bcms-clearfix"></div>
|
|
</div>
|
|
</div>
|
|
<div class="component-info">
|
|
<div class="container">
|
|
|
|
<aside class="sidebar">
|
|
<nav class="spy-nav">
|
|
<ul>
|
|
<li><a href="index.html">Intro</a></li>
|
|
<li><a href="virtual-proxy.html">Virtual Proxy</a></li>
|
|
<li><a href="null-object.html">Null Objects</a></li>
|
|
<li><a href="ghost-object.html">Ghost Objects</a></li>
|
|
<li><a href="remote-object.html">Remote Object</a></li>
|
|
<li><a href="contributing.html">Contributing</a></li>
|
|
<li><a href="credits.html">Credits</a></li>
|
|
<li><a href="copyright.html">Copyright</a></li>
|
|
</ul>
|
|
</nav>
|
|
<div class="bcms-clearfix bcms-clearfix"></div>
|
|
<a class="btn btn-action btn-full download-component"
|
|
href="download.html">Download</a>
|
|
<div class="bcms-clearfix"></div>
|
|
</aside>
|
|
|
|
<div class="content">
|
|
<h3>Proxy Manager</h3>
|
|
<p>This library aims at providing abstraction for generating various kinds of <a href="http://ocramius.github.io/presentations/proxy-pattern-in-php/" target="_blank">proxy classes</a>.</p>
|
|
<p>If you want to learn more about proxy pattern watch this video:</p>
|
|
|
|
<iframe width="640" height="390" src="//www.youtube.com/embed/Ka8wlV8M6Vg" frameborder="0" allowfullscreen></iframe>
|
|
<hr />
|
|
<div class="bcms-clearfix"></div>
|
|
<h3 class="section-title">Installation</h3>
|
|
<p>The suggested installation method is via <a href="https://getcomposer.org/" target="_blank">composer</a>.</p>
|
|
<pre><code class="sh">php composer.phar require ocramius/proxy-manager:1.0.*</code></pre>
|
|
<hr />
|
|
|
|
<h3 class="section-title" id="virtualproxy">Lazy Loading Value Holders (Virtual Proxy)</h3>
|
|
|
|
<p>ProxyManager can generate
|
|
<a href="http://www.martinfowler.com/eaaCatalog/lazyLoad.html" target="_blank">lazy loading value holders</a>,
|
|
which are virtual proxies capable of saving performance and memory for objects that
|
|
require a lot of dependencies or CPU cycles to be loaded:
|
|
particularly useful when you may not always need the object,
|
|
but are constructing it anyways.</p>
|
|
|
|
<pre>
|
|
<code class="php">
|
|
$factory = new \ProxyManager\Factory\LazyLoadingValueHolderFactory();
|
|
|
|
$proxy = $factory->createProxy(
|
|
'MyApp\HeavyComplexObject',
|
|
function (& $wrappedObject, $proxy, $method, $parameters, & $initializer) {
|
|
$wrappedObject = new HeavyComplexObject(); // instantiation logic here
|
|
$initializer = null; // turning off further lazy initialization
|
|
|
|
return true;
|
|
}
|
|
);
|
|
|
|
$proxy->doFoo();
|
|
</code>
|
|
</pre>
|
|
|
|
<p>See the <a href="virtual-proxy.html">complete documentation about lazy loading value holders</a>.</p>
|
|
<hr />
|
|
|
|
<h3 class="section-title">Access Interceptor Value Holder</h3>
|
|
|
|
<p>An access interceptor value holder is a smart reference that allows you to execute
|
|
logic before and after a particular method is executed or a particular property is
|
|
accessed, and it allows to manipulate parameters and return values depending on
|
|
your needs.</p>
|
|
|
|
<pre>
|
|
<code class="php">
|
|
$factory = new \ProxyManager\Factory\AccessInterceptorValueHolderFactory();
|
|
|
|
$proxy = $factory->createProxy(
|
|
new \My\Db\Connection(),
|
|
array('query' => function () { echo "Query being executed!\n"; }),
|
|
array('query' => function () { echo "Query completed!\n"; })
|
|
);
|
|
|
|
$proxy->query(); // produces "Query being executed!\nQuery completed!\n"
|
|
</code>
|
|
</pre>
|
|
|
|
<p>See the <a href="access-interceptor-value-holder-proxy.html">complete documentation about access interceptor value holders</a>.</p>
|
|
<hr />
|
|
|
|
<h3 class="section-title">Access Interceptor Scope Localizer</h3>
|
|
|
|
<p>An access interceptor scope localizer works exactly like an access interceptor
|
|
value holder, but it is safe to use to proxy fluent interfaces.</p>
|
|
|
|
<p>See the <a href="access-interceptor-scope-localizer-proxy.html">complete documentation about access interceptor scope localizer</a>.</p>
|
|
<hr />
|
|
|
|
|
|
<h3 class="section-title">Null Objects</h3>
|
|
|
|
<p>A Null Object proxy implements the null object pattern.</p>
|
|
|
|
<p>This kind of proxy allows you to have fallback logic in case loading of the wrapped value failed.</p>
|
|
<pre>
|
|
<code class="php">
|
|
$factory = new \ProxyManager\Factory\NullObjectFactory();
|
|
|
|
$proxy = $factory->createProxy('My\EntityObject');
|
|
|
|
$proxy->getName(); // empty return
|
|
</code>
|
|
</pre>
|
|
|
|
<p>A Null Object Proxy can be created from an object, a class name or an interface name:</p>
|
|
<pre>
|
|
<code class="php">
|
|
$factory = new \ProxyManager\Factory\NullObjectFactory();
|
|
|
|
$proxy = $factory->createProxy('My\EntityObjectInterface');
|
|
$proxy->getName(); // empty return
|
|
|
|
$proxy = $factory->createProxy($entity); // created from object
|
|
$proxy->getName(); // empty return
|
|
</code>
|
|
</pre>
|
|
|
|
<p>See the <a href="null-object.html">complete documentation about null object proxy</a>.</p>
|
|
|
|
<hr />
|
|
|
|
<h3 class="section-title">Ghost Objects</h3>
|
|
|
|
<p>Similar to value holder, a ghost object is usually created to handle lazy loading.</p>
|
|
|
|
<p>The difference between a value holder and a ghost object is that the ghost
|
|
object does not contain a real instance of the required object, but handles
|
|
lazy loading by initializing its own inherited properties.</p>
|
|
|
|
<p>ProxyManager can generate
|
|
<a href="http://www.martinfowler.com/eaaCatalog/lazyLoad.html" target="_blank">lazy loading ghost objects</a>,
|
|
which are proxies used to save performance and memory for large datasets and
|
|
graphs representing relational data. Ghost objects are particularly useful
|
|
when building data-mappers.</p>
|
|
|
|
<p>Additionally, the overhead introduced by ghost objects is very low when
|
|
compared to the memory and performance overhead caused by virtual proxies.</p>
|
|
|
|
<pre>
|
|
<code class="php">
|
|
$factory = new \ProxyManager\Factory\LazyLoadingGhostFactory();
|
|
|
|
$proxy = $factory->createProxy(
|
|
'MyApp\HeavyComplexObject',
|
|
function ($proxy, $method, $parameters, & $initializer) {
|
|
$initializer = null; // turning off further lazy initialization
|
|
|
|
// modify the proxy instance
|
|
$proxy->setFoo('foo');
|
|
$proxy->setBar('bar');
|
|
|
|
return true;
|
|
}
|
|
);
|
|
|
|
$proxy->doFoo();
|
|
</code>
|
|
</pre>
|
|
|
|
<p>See the <a href="ghost-object.html">complete documentation about lazy loading ghost objects</a>.</p>
|
|
|
|
<hr />
|
|
|
|
<h3 class="section-title">Remote Object</h3>
|
|
|
|
<p>A remote object proxy is an object that is located on a different system,
|
|
but is used as if it was available locally. There's various possible
|
|
remote proxy implementations, which could be based on xmlrpc/jsonrpc/soap/dnode/etc.</p>
|
|
|
|
<p>This example uses the XML-RPC client of Zend Framework 2:</p>
|
|
|
|
<pre>
|
|
<code class="php">
|
|
interface FooServiceInterface
|
|
{
|
|
public function foo();
|
|
}
|
|
|
|
$factory = new \ProxyManager\Factory\RemoteObjectFactory(
|
|
new \ProxyManager\Factory\RemoteObject\Adapter\XmlRpc(
|
|
new \Zend\XmlRpc\Client('https://example.com/rpc-endpoint')
|
|
)
|
|
);
|
|
|
|
// proxy is your remote implementation
|
|
$proxy = $factory->createProxy('FooServiceInterface');
|
|
|
|
var_dump($proxy->foo());
|
|
</code>
|
|
</pre>
|
|
|
|
<p>See the <a href="remote-object.html">complete documentation about remote objects</a>.</p>
|
|
<hr />
|
|
|
|
|
|
<h3 class="section-title">Contributing</h3>
|
|
<p>Please read the <a href="contributing.html">CONTRIBUTING</a> contents if you wish to help out!</p>
|
|
|
|
<hr />
|
|
|
|
<h3 class="section-title">Credits</h3>
|
|
|
|
<p>The idea was originated by a <a href="http://marco-pivetta.com/proxy-pattern-in-php/" target="_blank">talk about Proxies in PHP OOP</a> that I gave at the <a href="https://twitter.com/phpugffm" target="_blank">@phpugffm</a> in January 2013.</p>
|
|
|
|
|
|
<div class="bcms-clearfix"></div>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
</main>
|
|
|
|
<footer class="site-footer" role="contentinfo">
|
|
<div class="container">
|
|
<div class="footer-logos">
|
|
<ul>
|
|
<li><a href="index.html">Intro</a> | </li>
|
|
<li><a href="virtual-proxy.html">Virtual Proxy</a> | </li>
|
|
<li><a href="null-object.html">Null Objects</a> | </li>
|
|
<li><a href="ghost-object.html">Ghost Objects</a> | </li>
|
|
<li><a href="remote-object.html">Remote Object</a> | </li>
|
|
<li><a href="contributing.html">Contributing</a> | </li>
|
|
<li><a href="credits.html">Credits</a> | </li>
|
|
<li><a href="copyright.html">Copyright</a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="bcms-clearfix"></div>
|
|
</footer>
|
|
<div class="bcms-clearfix"></div>
|
|
</body>
|
|
</html>
|