Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

access-interceptor-value-holder-proxy.html

Zuletzt modifiziert: 09.10.2024, 12:56 - Dateigröße: 8.29 KiB


 001  <!DOCTYPE html>
 002  <html class="no-js" id="top">
 003  <head>
 004      <title>ProxyManager - Tuning the ProxyManager for production</title>
 005   
 006      <meta name="description" content="A proxyManager write in php" />
 007      <meta name="keywords" content="ProxyManager, proxy, manager, ocramius, Marco Pivetta, php, production" />
 008      <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
 009      <link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:200,300,400,600' rel='stylesheet' type='text/css'>
 010      <link href="css/styles.css" rel="stylesheet" />
 011      <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/styles/default.min.css">
 012      <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/highlight.min.js"></script>
 013      <script>hljs.initHighlightingOnLoad();</script>
 014      <link rel="shortcut icon" href="favicon.ico">
 015  </head>
 016  <body>
 017   
 018  <header class="site-header">
 019  <div class="container">
 020  <h1><a href="index.html"><img alt="ProxyManager" src="img/block.png" /></a></h1>
 021   
 022  <nav class="main-nav" role="navigation">
 023  <ul>
 024      <li><a href="https://github.com/Ocramius/ProxyManager" target="_blank">Github</a>
 025      <div class="bcms-clearfix"></div>
 026  </li>
 027  </ul>
 028  </nav>
 029  </div>
 030  </header>
 031  <main role="main">
 032  <section class="component-content">
 033   
 034  <div class="component-demo" id="live-demo">
 035      <div class="container">
 036              <div class="main-wrapper" style="text-align: right">
 037                  <iframe src="http://ghbtns.com/github-btn.html?user=ocramius&amp;repo=ProxyManager&amp;type=fork&amp;count=true&amp;size=large"
 038    allowtransparency="true" frameborder="0" scrolling="0" width="310" height="40"></iframe>
 039   
 040                  <iframe src="http://ghbtns.com/github-btn.html?user=ocramius&amp;repo=ProxyManager&amp;type=watch&amp;count=true&amp;size=large"
 041    allowtransparency="true" frameborder="0" scrolling="0" width="200" height="40"></iframe>
 042   
 043              </div>
 044          <div class="bcms-clearfix bcms-clearfix"></div>
 045      </div>
 046  </div>
 047  <div class="component-info">
 048  <div class="container">
 049  <aside class="sidebar">
 050      <nav class="spy-nav">
 051          <ul>
 052              <li><a href="index.html">Intro</a></li>
 053              <li><a href="virtual-proxy.html">Virtual Proxy</a></li>
 054              <li><a href="null-object.html">Null Objects</a></li>
 055              <li><a href="ghost-object.html">Ghost Objects</a></li>
 056              <li><a href="remote-object.html">Remote Object</a></li>
 057              <li><a href="contributing.html">Contributing</a></li>
 058              <li><a href="credits.html">Credits</a></li>
 059              <li><a href="copyright.html">Copyright</a></li>
 060          </ul>
 061      </nav>
 062  <div class="bcms-clearfix bcms-clearfix"></div>
 063  <a class="btn btn-action btn-full download-component"
 064      href="download.html">Download</a>
 065      <div class="bcms-clearfix"></div>
 066  </aside>
 067   
 068  <div class="content">
 069      <div class="bcms-clearfix"></div>
 070      <h3 class="section-title">Access Interceptor Value Holder Proxy</h3>
 071   
 072      <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>
 073      
 074      <p>It wraps around a real instance of the object to be proxied, and can be useful for things like:</p>
 075   
 076      <ul>
 077          <li>caching execution of slow and heavy methods</li>
 078          <li>log method calls</li>
 079          <li>debugging</li>
 080          <li>event triggering</li>
 081          <li>handling of orthogonal logic, and <a href="http://en.wikipedia.org/wiki/Aspect-oriented_programming" target="_blank">AOP</a> in general</li>
 082      </ul>
 083  <hr />    
 084      <h3>Example</h3>
 085   
 086      <p>Here's an example of how you can create and use an access interceptor value holder:</p>
 087   
 088      <pre>
 089          <code class="php">
 090  &lt;?php
 091   
 092  use ProxyManager\Factory\AccessInterceptorValueHolderFactory as Factory;
 093   
 094  require_once __DIR__ . '/vendor/autoload.php';
 095   
 096  class Foo
 097  {
 098      public function doFoo()
 099      {
 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, &amp; $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>
 209