[ Index ] |
PHP Cross Reference of phpBB-3.2.11-deutsch |
[Summary view] [Print] [Text view]
1 <!DOCTYPE html> 2 <html class="no-js" id="top"> 3 <head> 4 <title>ProxyManager - Tuning the ProxyManager for production</title> 5 6 <meta name="description" content="A proxyManager write in php" /> 7 <meta name="keywords" content="ProxyManager, proxy, manager, ocramius, Marco Pivetta, php, production" /> 8 <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> 9 <link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:200,300,400,600' rel='stylesheet' type='text/css'> 10 <link href="css/styles.css" rel="stylesheet" /> 11 <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/styles/default.min.css"> 12 <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/highlight.min.js"></script> 13 <script>hljs.initHighlightingOnLoad();</script> 14 <link rel="shortcut icon" href="favicon.ico"> 15 </head> 16 <body> 17 18 <header class="site-header"> 19 <div class="container"> 20 <h1><a href="index.html"><img alt="ProxyManager" src="img/block.png" /></a></h1> 21 22 <nav class="main-nav" role="navigation"> 23 <ul> 24 <li><a href="https://github.com/Ocramius/ProxyManager" target="_blank">Github</a> 25 <div class="bcms-clearfix"></div> 26 </li> 27 </ul> 28 </nav> 29 </div> 30 </header> 31 <main role="main"> 32 <section class="component-content"> 33 34 <div class="component-demo" id="live-demo"> 35 <div class="container"> 36 <div class="main-wrapper" style="text-align: right"> 37 <iframe src="http://ghbtns.com/github-btn.html?user=ocramius&repo=ProxyManager&type=fork&count=true&size=large" 38 allowtransparency="true" frameborder="0" scrolling="0" width="310" height="40"></iframe> 39 40 <iframe src="http://ghbtns.com/github-btn.html?user=ocramius&repo=ProxyManager&type=watch&count=true&size=large" 41 allowtransparency="true" frameborder="0" scrolling="0" width="200" height="40"></iframe> 42 43 </div> 44 <div class="bcms-clearfix bcms-clearfix"></div> 45 </div> 46 </div> 47 <div class="component-info"> 48 <div class="container"> 49 <aside class="sidebar"> 50 <nav class="spy-nav"> 51 <ul> 52 <li><a href="index.html">Intro</a></li> 53 <li><a href="virtual-proxy.html">Virtual Proxy</a></li> 54 <li><a href="null-object.html">Null Objects</a></li> 55 <li><a href="ghost-object.html">Ghost Objects</a></li> 56 <li><a href="remote-object.html">Remote Object</a></li> 57 <li><a href="contributing.html">Contributing</a></li> 58 <li><a href="credits.html">Credits</a></li> 59 <li><a href="copyright.html">Copyright</a></li> 60 </ul> 61 </nav> 62 <div class="bcms-clearfix bcms-clearfix"></div> 63 <a class="btn btn-action btn-full download-component" 64 href="download.html">Download</a> 65 <div class="bcms-clearfix"></div> 66 </aside> 67 68 <div class="content"> 69 <div class="bcms-clearfix"></div> 70 <h3 class="section-title">Access Interceptor Value Holder Proxy</h3> 71 72 <p>An access interceptor value holder is a smart reference proxy that allows you to dynamically define logic to be executed before or after any of the wrapped object's methods logic.</p> 73 74 <p>It wraps around a real instance of the object to be proxied, and can be useful for things like:</p> 75 76 <ul> 77 <li>caching execution of slow and heavy methods</li> 78 <li>log method calls</li> 79 <li>debugging</li> 80 <li>event triggering</li> 81 <li>handling of orthogonal logic, and <a href="http://en.wikipedia.org/wiki/Aspect-oriented_programming" target="_blank">AOP</a> in general</li> 82 </ul> 83 <hr /> 84 <h3>Example</h3> 85 86 <p>Here's an example of how you can create and use an access interceptor value holder:</p> 87 88 <pre> 89 <code class="php"> 90 <?php 91 92 use ProxyManager\Factory\AccessInterceptorValueHolderFactory as Factory; 93 94 require_once __DIR__ . '/vendor/autoload.php'; 95 96 class Foo 97 { 98 public function doFoo() 99 { 100 echo "Foo!\n"; 101 } 102 } 103 104 $factory = new Factory(); 105 106 $proxy = $factory->createProxy( 107 new Foo(), 108 array('doFoo' => function () { echo "PreFoo!\n"; }), 109 array('doFoo' => function () { echo "PostFoo!\n"; }) 110 ); 111 112 $proxy->doFoo(); 113 </code> 114 </pre> 115 116 <p>This send something like following to your output:</p> 117 118 <pre> 119 <code class="php"> 120 PreFoo! 121 Foo! 122 PostFoo! 123 </code> 124 </pre> 125 126 <hr /> 127 <h3>Implementing pre- and post- access interceptors</h3> 128 129 <p>A proxy produced by the <code><a href="https://github.com/Ocramius/ProxyManager/blob/master/src/ProxyManager/Factory/AccessInterceptorValueHolderFactory.php" target="_blank">ProxyManager\Factory\AccessInterceptorValueHolderFactory</a></code> implements both the <code><a href="https://github.com/Ocramius/ProxyManager/blob/master/src/ProxyManager/Proxy/ValueHolderInterface.php" target="_blank">ProxyManager\Proxy\ValueHolderInterface</a></code> and the <code><a href="https://github.com/Ocramius/ProxyManager/blob/master/src/ProxyManager/Proxy/ValueHolderInterface.php" target="_blank">ProxyManager\Proxy\AccessInterceptorInterface</a></code>.</p> 130 131 132 <p>Therefore, you can set an access interceptor callback by calling:</p> 133 134 <pre> 135 <code class="php"> 136 $proxy->setMethodPrefixInterceptor('methodName', function () { echo 'pre'; }); 137 $proxy->setMethodSuffixInterceptor('methodName', function () { echo 'post'; }); 138 </code> 139 </pre> 140 141 <p>You can also listen to public properties access by attaching interceptors to <code>__get</code>, <code>__set</code>, <code>__isset</code> and <code>__unset</code>.</p> 142 143 <p>A prefix interceptor (executed before method logic) should have following signature:</p> 144 145 <pre> 146 <code class="php"> 147 /** 148 * @var object $proxy the proxy that intercepted the method call 149 * @var object $instance the wrapped instance within the proxy 150 * @var string $method name of the called method 151 * @var array $params sorted array of parameters passed to the intercepted 152 * method, indexed by parameter name 153 * @var bool $returnEarly flag to tell the interceptor proxy to return early, returning 154 * the interceptor's return value instead of executing the method logic 155 * 156 * @return mixed 157 */ 158 $prefixInterceptor = function ($proxy, $instance, $method, $params, & $returnEarly) {}; 159 </code> 160 </pre> 161 162 A suffix interceptor (executed after method logic) should have following signature: 163 164 <pre> 165 <code class="php"> 166 /** 167 * @var object $proxy the proxy that intercepted the method call 168 * @var object $instance the wrapped instance within the proxy 169 * @var string $method name of the called method 170 * @var array $params sorted array of parameters passed to the intercepted 171 * method, indexed by parameter name 172 * @var mixed $returnValue the return value of the intercepted method 173 * @var bool $returnEarly flag to tell the proxy to return early, returning the interceptor's 174 * return value instead of the value produced by the method 175 * 176 * @return mixed 177 */ 178 $suffixInterceptor = function ($proxy, $instance, $method, $params, $returnValue, & $returnEarly) {}; 179 </code> 180 </pre> 181 182 <hr /> 183 <h3>Tuning performance for production</h3> 184 185 <p>See <a href="production.html">Tuning ProxyManager for Production</a>.</p> 186 </main> 187 188 <footer class="site-footer" role="contentinfo"> 189 <div class="container"> 190 <div class="footer-logos"> 191 <ul> 192 <li><a href="index.html">Intro</a> | </li> 193 <li><a href="virtual-proxy.html">Virtual Proxy</a> | </li> 194 <li><a href="null-object.html">Null Objects</a> | </li> 195 <li><a href="ghost-object.html">Ghost Objects</a> | </li> 196 <li><a href="remote-object.html">Remote Object</a> | </li> 197 <li><a href="contributing.html">Contributing</a> | </li> 198 <li><a href="credits.html">Credits</a> | </li> 199 <li><a href="copyright.html">Copyright</a></li> 200 </ul> 201 </div> 202 </div> 203 204 <div class="bcms-clearfix"></div> 205 </footer> 206 <div class="bcms-clearfix"></div> 207 </body> 208 </html>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |