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

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


 001  # Access Interceptor Value Holder Proxy
 002   
 003  An access interceptor value holder is a smart reference proxy that allows you to dynamically
 004  define logic to be executed before or after any of the wrapped object's methods
 005  logic.
 006   
 007  It wraps around a real instance of the object to be proxied, and can be useful for things like:
 008   
 009   * caching execution of slow and heavy methods
 010   * log method calls
 011   * debugging
 012   * event triggering
 013   * handling of orthogonal logic, and [AOP](http://en.wikipedia.org/wiki/Aspect-oriented_programming) in general
 014   
 015  ## Example
 016   
 017  Here's an example of how you can create and use an access interceptor value holder:
 018   
 019  ```php
 020  <?php
 021   
 022  use ProxyManager\Factory\AccessInterceptorValueHolderFactory as Factory;
 023   
 024  require_once __DIR__ . '/vendor/autoload.php';
 025   
 026  class Foo
 027  {
 028      public function doFoo()
 029      {
 030          echo "Foo!\n";
 031      }
 032  }
 033   
 034  $factory = new Factory();
 035   
 036  $proxy = $factory->createProxy(
 037      new Foo(),
 038      array('doFoo' => function () { echo "PreFoo!\n"; }),
 039      array('doFoo' => function () { echo "PostFoo!\n"; })
 040  );
 041   
 042  $proxy->doFoo();
 043  ```
 044   
 045  This send something like following to your output:
 046   
 047  ```
 048  PreFoo!
 049  Foo!
 050  PostFoo!
 051  ```
 052   
 053  ## Implementing pre- and post- access interceptors
 054   
 055  A proxy produced by the
 056  [`ProxyManager\Factory\AccessInterceptorValueHolderFactory`](https://github.com/Ocramius/ProxyManager/blob/master/src/ProxyManager/Factory/AccessInterceptorValueHolderFactory.php)
 057  implements both the
 058  [`ProxyManager\Proxy\ValueHolderInterface`](https://github.com/Ocramius/ProxyManager/blob/master/src/ProxyManager/Proxy/ValueHolderInterface.php)
 059  and the
 060  [`ProxyManager\Proxy\AccessInterceptorInterface`](https://github.com/Ocramius/ProxyManager/blob/master/src/ProxyManager/Proxy/ValueHolderInterface.php).
 061   
 062  Therefore, you can set an access interceptor callback by calling:
 063   
 064  ```php
 065  $proxy->setMethodPrefixInterceptor('methodName', function () { echo 'pre'; });
 066  $proxy->setMethodSuffixInterceptor('methodName', function () { echo 'post'; });
 067  ```
 068   
 069  You can also listen to public properties access by attaching interceptors to `__get`, `__set`, `__isset` and `__unset`.
 070   
 071  A prefix interceptor (executed before method logic) should have following signature:
 072   
 073  ```php
 074  /**
 075   * @var object $proxy       the proxy that intercepted the method call
 076   * @var object $instance    the wrapped instance within the proxy
 077   * @var string $method      name of the called method
 078   * @var array  $params      sorted array of parameters passed to the intercepted
 079   *                          method, indexed by parameter name
 080   * @var bool   $returnEarly flag to tell the interceptor proxy to return early, returning
 081   *                          the interceptor's return value instead of executing the method logic
 082   *
 083   * @return mixed
 084   */
 085  $prefixInterceptor = function ($proxy, $instance, $method, $params, & $returnEarly) {};
 086  ```
 087   
 088  A suffix interceptor (executed after method logic) should have following signature:
 089   
 090  ```php
 091  /**
 092   * @var object $proxy       the proxy that intercepted the method call
 093   * @var object $instance    the wrapped instance within the proxy
 094   * @var string $method      name of the called method
 095   * @var array  $params      sorted array of parameters passed to the intercepted
 096   *                          method, indexed by parameter name
 097   * @var mixed  $returnValue the return value of the intercepted method
 098   * @var bool   $returnEarly flag to tell the proxy to return early, returning the interceptor's
 099   *                          return value instead of the value produced by the method
 100   *
 101   * @return mixed
 102   */
 103  $suffixInterceptor = function ($proxy, $instance, $method, $params, $returnValue, & $returnEarly) {};
 104  ```
 105   
 106  ## Tuning performance for production
 107   
 108  See [Tuning ProxyManager for Production](https://github.com/Ocramius/ProxyManager/blob/master/docs/tuning-for-production.md).