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

StaticProxyConstructor.php

Zuletzt modifiziert: 02.04.2025, 15:04 - Dateigröße: 2.75 KiB


01  <?php
02   
03  declare(strict_types=1);
04   
05  namespace ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator;
06   
07  use ProxyManager\Generator\MethodGenerator;
08  use ProxyManager\ProxyGenerator\Util\Properties;
09  use ProxyManager\ProxyGenerator\Util\UnsetPropertiesGenerator;
10  use ReflectionClass;
11  use Zend\Code\Generator\ParameterGenerator;
12  use Zend\Code\Generator\PropertyGenerator;
13   
14  /**
15   * The `staticProxyConstructor` implementation for access interceptor value holders
16   *
17   * @author Marco Pivetta <ocramius@gmail.com>
18   * @license MIT
19   */
20  class StaticProxyConstructor extends MethodGenerator
21  {
22      /**
23       * Constructor
24       *
25       * @param ReflectionClass   $originalClass
26       * @param PropertyGenerator $valueHolder
27       * @param PropertyGenerator $prefixInterceptors
28       * @param PropertyGenerator $suffixInterceptors
29       *
30       * @throws \Zend\Code\Generator\Exception\InvalidArgumentException
31       */
32      public function __construct(
33          ReflectionClass $originalClass,
34          PropertyGenerator $valueHolder,
35          PropertyGenerator $prefixInterceptors,
36          PropertyGenerator $suffixInterceptors
37      ) {
38          parent::__construct('staticProxyConstructor', [], static::FLAG_PUBLIC | static::FLAG_STATIC);
39   
40          $prefix = new ParameterGenerator('prefixInterceptors');
41          $suffix = new ParameterGenerator('suffixInterceptors');
42   
43          $prefix->setDefaultValue([]);
44          $suffix->setDefaultValue([]);
45          $prefix->setType('array');
46          $suffix->setType('array');
47   
48          $this->setParameter(new ParameterGenerator('wrappedObject'));
49          $this->setParameter($prefix);
50          $this->setParameter($suffix);
51          $this->setReturnType($originalClass->getName());
52   
53          $this->setDocBlock(
54              "Constructor to setup interceptors\n\n"
55              . "@param \\" . $originalClass->getName() . " \$wrappedObject\n"
56              . "@param \\Closure[] \$prefixInterceptors method interceptors to be used before method logic\n"
57              . "@param \\Closure[] \$suffixInterceptors method interceptors to be used before method logic\n\n"
58              . '@return self'
59          );
60   
61          $this->setBody(
62              'static $reflection;' . "\n\n"
63              . '$reflection = $reflection ?? $reflection = new \ReflectionClass(__CLASS__);' . "\n"
64              . '$instance = $reflection->newInstanceWithoutConstructor();' . "\n\n"
65              . UnsetPropertiesGenerator::generateSnippet(Properties::fromReflectionClass($originalClass), 'instance')
66              . '$instance->' . $valueHolder->getName() . " = \$wrappedObject;\n"
67              . '$instance->' . $prefixInterceptors->getName() . " = \$prefixInterceptors;\n"
68              . '$instance->' . $suffixInterceptors->getName() . " = \$suffixInterceptors;\n\n"
69              . 'return $instance;'
70          );
71      }
72  }
73