Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

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: 02.04.2025, 15:04 - Dateigröße: 3.29 KiB


01  <?php
02   
03  declare(strict_types=1);
04   
05  namespace ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\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  $valueHolder
27       * @param \Zend\Code\Generator\PropertyGenerator  $prefixInterceptors
28       * @param \Zend\Code\Generator\PropertyGenerator  $suffixInterceptors
29       * @param \ReflectionMethod|null                  $originalMethod
30       */
31      public static function createInterceptedMethodBody(
32          string $methodBody,
33          MethodGenerator $method,
34          PropertyGenerator $valueHolder,
35          PropertyGenerator $prefixInterceptors,
36          PropertyGenerator $suffixInterceptors,
37          ?\ReflectionMethod $originalMethod
38      ) : string {
39          $name                   = var_export($method->getName(), true);
40          $valueHolderName        = $valueHolder->getName();
41          $prefixInterceptorsName = $prefixInterceptors->getName();
42          $suffixInterceptorsName = $suffixInterceptors->getName();
43          $params                 = [];
44   
45          foreach ($method->getParameters() as $parameter) {
46              $parameterName = $parameter->getName();
47              $params[]      = var_export($parameterName, true) . ' => $' . $parameter->getName();
48          }
49   
50          $paramsString = 'array(' . implode(', ', $params) . ')';
51   
52          return "if (isset(\$this->$prefixInterceptorsName" . "[$name])) {\n"
53              . "    \$returnEarly       = false;\n"
54              . "    \$prefixReturnValue = \$this->$prefixInterceptorsName" . "[$name]->__invoke("
55              . "\$this, \$this->$valueHolderName$name$paramsString, \$returnEarly);\n\n"
56              . "    if (\$returnEarly) {\n"
57              . '        ' . ProxiedMethodReturnExpression::generate('$prefixReturnValue', $originalMethod) . "\n"
58              . "    }\n"
59              . "}\n\n"
60              . $methodBody . "\n\n"
61              . "if (isset(\$this->$suffixInterceptorsName" . "[$name])) {\n"
62              . "    \$returnEarly       = false;\n"
63              . "    \$suffixReturnValue = \$this->$suffixInterceptorsName" . "[$name]->__invoke("
64              . "\$this, \$this->$valueHolderName$name$paramsString, \$returnValue, \$returnEarly);\n\n"
65              . "    if (\$returnEarly) {\n"
66              . '        ' . ProxiedMethodReturnExpression::generate('$suffixReturnValue', $originalMethod) . "\n"
67              . "    }\n"
68              . "}\n\n"
69              . ProxiedMethodReturnExpression::generate('$returnValue', $originalMethod);
70      }
71  }
72