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-scope-localizer.md

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


001  # Access Interceptor Scope Localizer Proxy
002   
003  An access interceptor scope localizer is a smart reference proxy that allows you to dynamically
004  define logic to be executed before or after any of the proxied object's methods' logic.
005   
006  It works exactly like the [access interceptor value holder](access-interceptor-value-holder.md),
007  with some minor differences in behavior.
008   
009  The working concept of an access interceptor scope localizer is to localize scope of a proxied object:
010   
011  ```php
012  class Example
013  {
014      protected $foo;
015      protected $bar;
016      protected $baz;
017   
018      public function doFoo()
019      {
020          // ...
021      }
022  }
023   
024  class ExampleProxy extends Example
025  {
026      public function __construct(Example $example)
027      {
028          $this->foo = & $example->foo;
029          $this->bar = & $example->bar;
030          $this->baz = & $example->baz;
031      }
032   
033      public function doFoo()
034      {
035          return parent::doFoo();
036      }
037  }
038  ```
039   
040  This allows to create a mirror copy of the real instance, where any change in the proxy or in the real
041  instance is reflected in both objects.
042   
043  The main advantage of this approach is that the proxy is now safe against fluent interfaces, which
044  would break an [access interceptor value holder](access-interceptor-value-holder.md) instead.
045   
046  ## Differences with [access interceptor value holder](access-interceptor-value-holder.md):
047   
048   * It does **NOT** implement the `ProxyManager\Proxy\ValueHolderInterface`, since the proxy itself
049     does not keep a reference to the original object being proxied
050   * In all interceptor methods (see [access interceptor value holder](access-interceptor-value-holder.md)),
051     the `$instance` passed in is the proxy itself. There is no way  to gather a reference to the
052     original object right now, and that's mainly to protect from misuse.
053   
054  ## Known limitations
055   
056   * It is **NOT** possible to intercept access to public properties
057   * It is **NOT** possible to proxy interfaces, since this proxy relies on `parent::method()` calls.
058     Interfaces obviously don't provide a parent method implementation.
059   * calling `unset` on a property of an access interceptor scope localizer (or the real instance)
060     will cause the two objects to be un-synchronized, with possible unexpected behaviour.
061   * serializing or un-serializing an access interceptor scope localizer (or the real instance)
062     will not cause the real instance (or the proxy) to be serialized or un-serialized
063   * if a proxied object contains private properties, then an exception will be thrown if you use
064     PHP `< 5.4.0`.
065   
066  ## Example
067   
068  Here's an example of how you can create and use an access interceptor scope localizer :
069   
070  ```php
071  <?php
072   
073  use ProxyManager\Factory\AccessInterceptorScopeLocalizerFactory as Factory;
074   
075  require_once __DIR__ . '/vendor/autoload.php';
076   
077  class Foo
078  {
079      public function doFoo()
080      {
081          echo "Foo!\n";
082      }
083  }
084   
085  $factory = new Factory();
086   
087  $proxy = $factory->createProxy(
088      new Foo(),
089      array('doFoo' => function () { echo "PreFoo!\n"; }),
090      array('doFoo' => function () { echo "PostFoo!\n"; })
091  );
092   
093  $proxy->doFoo();
094  ```
095   
096  This send something like following to your output:
097   
098  ```
099  PreFoo!
100  Foo!
101  PostFoo!
102  ```
103   
104  This is pretty much the same logic that you can find
105  in [access interceptor value holder](access-interceptor-value-holder.md).
106