Verzeichnisstruktur phpBB-3.3.16


Veröffentlicht
27.04.2026

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

InterceptorGenerator.php

Zuletzt modifiziert: 01.05.2026, 11:29 - Dateigröße: 3.10 KiB


 01  <?php
 02   
 03  declare(strict_types=1);
 04   
 05  namespace ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\Util;
 06   
 07  use ProxyManager\Generator\MethodGenerator;
 08  use ProxyManager\Generator\Util\ProxiedMethodReturnExpression;
 09  use Zend\Code\Generator\PropertyGenerator;
 10   
 11  /**
 12   * Utility to create pre- and post- method interceptors around a given method body
 13   *
 14   * @author Marco Pivetta <ocramius@gmail.com>
 15   * @license MIT
 16   *
 17   * @private - this class is just here as a small utility for this component, don't use it in your own code
 18   */
 19  class InterceptorGenerator
 20  {
 21      /**
 22       * @param string                                  $methodBody         the body of the previously generated code.
 23       *                                                                    It MUST assign the return value to a variable
 24       *                                                                    `$returnValue` instead of directly returning
 25       * @param \ProxyManager\Generator\MethodGenerator $method
 26       * @param \Zend\Code\Generator\PropertyGenerator  $prefixInterceptors
 27       * @param \Zend\Code\Generator\PropertyGenerator  $suffixInterceptors
 28       * @param \ReflectionMethod|null                  $originalMethod
 29       */
 30      public static function createInterceptedMethodBody(
 31          string $methodBody,
 32          MethodGenerator $method,
 33          PropertyGenerator $prefixInterceptors,
 34          PropertyGenerator $suffixInterceptors,
 35          ?\ReflectionMethod $originalMethod
 36      ) : string {
 37          $name                   = var_export($method->getName(), true);
 38          $prefixInterceptorsName = $prefixInterceptors->getName();
 39          $suffixInterceptorsName = $suffixInterceptors->getName();
 40          $params                 = [];
 41   
 42          foreach ($method->getParameters() as $parameter) {
 43              $parameterName = $parameter->getName();
 44              $params[]      = var_export($parameterName, true) . ' => $' . $parameter->getName();
 45          }
 46   
 47          $paramsString = 'array(' . implode(', ', $params) . ')';
 48   
 49          return "if (isset(\$this->$prefixInterceptorsName" . "[$name])) {\n"
 50              . "    \$returnEarly       = false;\n"
 51              . "    \$prefixReturnValue = \$this->$prefixInterceptorsName" . "[$name]->__invoke("
 52              . "\$this, \$this, $name, $paramsString, \$returnEarly);\n\n"
 53              . "    if (\$returnEarly) {\n"
 54              . '        ' . ProxiedMethodReturnExpression::generate('$prefixReturnValue', $originalMethod) . "\n"
 55              . "    }\n"
 56              . "}\n\n"
 57              . $methodBody . "\n\n"
 58              . "if (isset(\$this->$suffixInterceptorsName" . "[$name])) {\n"
 59              . "    \$returnEarly       = false;\n"
 60              . "    \$suffixReturnValue = \$this->$suffixInterceptorsName" . "[$name]->__invoke("
 61              . "\$this, \$this, $name, $paramsString, \$returnValue, \$returnEarly);\n\n"
 62              . "    if (\$returnEarly) {\n"
 63              . '        ' . ProxiedMethodReturnExpression::generate('$suffixReturnValue', $originalMethod) . "\n"
 64              . "    }\n"
 65              . "}\n\n"
 66              . ProxiedMethodReturnExpression::generate('$returnValue', $originalMethod);
 67      }
 68  }
 69