[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/vendor/ocramius/proxy-manager/html-docs/ -> access-interceptor-scope-localizer-proxy.html (source)

   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&amp;repo=ProxyManager&amp;type=fork&amp;count=true&amp;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&amp;repo=ProxyManager&amp;type=watch&amp;count=true&amp;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 Scope Localizer Proxy</h3>
  71  
  72      <p>An access interceptor scope localizer is a smart reference proxy that allows you to dynamically define logic to be executed before or after any of the proxied object's methods' logic.</p>
  73      
  74      <p>It works exactly like the <a href="access-interceptor-value-holder-proxy.html">access interceptor value holder</a>, with some minor differences in behavior.</p>
  75  
  76      <p>The working concept of an access interceptor scope localizer is to localize scope of a proxied object:</p>
  77     
  78      <pre>
  79          <code class="php">
  80  class Example
  81  {
  82      protected $foo;
  83      protected $bar;
  84      protected $baz;
  85  
  86      public function doFoo()
  87      {
  88          // ...

  89      }
  90  }
  91  
  92  class ExampleProxy extends Example
  93  {
  94      public function __construct(Example $example)
  95      {
  96          $this->foo = &amp; $example->foo;
  97          $this->bar = &amp; $example->bar;
  98          $this->baz = &amp; $example->baz;
  99      }
 100  
 101      public function doFoo()
 102      {
 103          return parent::doFoo();
 104      }
 105  }
 106          </code>
 107      </pre>
 108  
 109      <p>This allows to create a mirror copy of the real instance, where any change in the proxy or in the real instance is reflected in both objects.</p>
 110  
 111      <p>The main advantage of this approach is that the proxy is now safe against fluent interfaces, which would break an <a href="access-interceptor-value-holder-proxy.html">access interceptor value holder</a> instead.</p>
 112  <hr />    
 113      <h3>Differences with <a href="access-interceptor-value-holder-proxy.html">access interceptor value holder</a>:</h3>
 114      
 115      <ul>
 116          <li>It does <strong>NOT</strong> implement the <code>ProxyManager\Proxy\ValueHolderInterface</code>, since the proxy itself does not keep a reference to the original object being proxied</li>
 117          <li>In all interceptor methods (see <a href="access-interceptor-value-holder-proxy.html">access interceptor value holder</a>), the $instance passed in is the proxy itself. There is no way to gather a reference to the original object right now, and that's mainly to protect from misuse.</li>
 118      </ul>
 119  <hr />
 120  
 121      <h3>Known limitations</h3>
 122  
 123      <ul>
 124          <li>It is <strong>NOT</strong> possible to intercept access to public properties</li>
 125          <li>It is <strong>NOT</strong> possible to proxy interfaces, since this proxy relies on <code>parent::method()</code> calls. Interfaces obviously don't provide a parent method implementation.</li>
 126          <li>calling unset on a property of an access interceptor scope localizer (or the real instance) will cause the two objects to be un-synchronized, with possible unexpected behaviour.</li>
 127          <li>serializing or un-serializing an access interceptor scope localizer (or the real instance) will not cause the real instance (or the proxy) to be serialized or un-serialized</li>
 128          <li>if a proxied object contains private properties, then an exception will be thrown if you use PHP <code>&lt; 5.4.0</code>.</li>
 129      </ul>
 130  <hr />
 131      <h3>Example</h3>
 132  
 133      <p>Here's an example of how you can create and use an access interceptor scope localizer :</p>
 134  
 135      <pre>
 136          <code class="php">
 137  &lt;?php
 138  
 139  use ProxyManager\Factory\AccessInterceptorScopeLocalizerFactory as Factory;
 140  
 141  require_once  __DIR__ . '/vendor/autoload.php';
 142  
 143  class Foo
 144  {
 145      public function doFoo()
 146      {
 147          echo "Foo!\n";
 148      }
 149  }
 150  
 151  $factory = new Factory();
 152  
 153  $proxy = $factory->createProxy(
 154      new Foo(),
 155      array('doFoo' => function () { echo "PreFoo!\n"; }),
 156      array('doFoo' => function () { echo "PostFoo!\n"; })
 157  );
 158  
 159  $proxy->doFoo();
 160          </code>
 161      </pre>
 162  
 163      <p>This send something like following to your output:</p>
 164  
 165      <pre>
 166          <code class="php">
 167  PreFoo!
 168  Foo!
 169  PostFoo!
 170          </code>
 171      </pre>
 172  
 173      <p>This is pretty much the same logic that you can find in <a href="access-interceptor-value-holder-proxy.html">access interceptor value holder</a>.</p>
 174      
 175  </main>
 176  
 177      <footer class="site-footer" role="contentinfo">
 178          <div class="container">
 179              <div class="footer-logos">
 180                  <ul>
 181                      <li><a href="index.html">Intro</a> | </li>
 182                      <li><a href="virtual-proxy.html">Virtual Proxy</a> | </li>
 183                      <li><a href="null-object.html">Null Objects</a> | </li>
 184                      <li><a href="ghost-object.html">Ghost Objects</a> | </li>
 185                      <li><a href="remote-object.html">Remote Object</a> | </li>
 186                      <li><a href="contributing.html">Contributing</a> | </li>
 187                      <li><a href="credits.html">Credits</a> | </li>
 188                      <li><a href="copyright.html">Copyright</a></li>
 189                  </ul>
 190              </div>
 191          </div>
 192  
 193          <div class="bcms-clearfix"></div>
 194      </footer>
 195      <div class="bcms-clearfix"></div>
 196      </body>
 197  </html>


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1