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

RemoteObjectGenerator.php

Zuletzt modifiziert: 02.04.2025, 15:03 - Dateigröße: 3.27 KiB


01  <?php
02   
03  declare(strict_types=1);
04   
05  namespace ProxyManager\ProxyGenerator;
06   
07  use ProxyManager\Exception\InvalidProxiedClassException;
08  use ProxyManager\Generator\Util\ClassGeneratorUtils;
09  use ProxyManager\Proxy\RemoteObjectInterface;
10  use ProxyManager\ProxyGenerator\Assertion\CanProxyAssertion;
11  use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\MagicGet;
12  use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\MagicIsset;
13  use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\MagicSet;
14  use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\MagicUnset;
15  use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\RemoteObjectMethod;
16  use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\StaticProxyConstructor;
17  use ProxyManager\ProxyGenerator\RemoteObject\PropertyGenerator\AdapterProperty;
18  use ProxyManager\ProxyGenerator\Util\ProxiedMethodsFilter;
19  use ReflectionClass;
20  use ReflectionMethod;
21  use Zend\Code\Generator\ClassGenerator;
22  use Zend\Code\Generator\MethodGenerator;
23  use Zend\Code\Reflection\MethodReflection;
24   
25  /**
26   * Generator for proxies implementing {@see \ProxyManager\Proxy\RemoteObjectInterface}
27   *
28   * {@inheritDoc}
29   *
30   * @author Vincent Blanchon <blanchon.vincent@gmail.com>
31   * @license MIT
32   */
33  class RemoteObjectGenerator implements ProxyGeneratorInterface
34  {
35      /**
36       * {@inheritDoc}
37       *
38       * @throws InvalidProxiedClassException
39       * @throws \Zend\Code\Generator\Exception\InvalidArgumentException
40       */
41      public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator)
42      {
43          CanProxyAssertion::assertClassCanBeProxied($originalClass);
44   
45          $interfaces = [RemoteObjectInterface::class];
46   
47          if ($originalClass->isInterface()) {
48              $interfaces[] = $originalClass->getName();
49          } else {
50              $classGenerator->setExtendedClass($originalClass->getName());
51          }
52   
53          $classGenerator->setImplementedInterfaces($interfaces);
54          $classGenerator->addPropertyFromGenerator($adapter = new AdapterProperty());
55   
56          array_map(
57              function (MethodGenerator $generatedMethod) use ($originalClass, $classGenerator) {
58                  ClassGeneratorUtils::addMethodIfNotFinal($originalClass, $classGenerator, $generatedMethod);
59              },
60              array_merge(
61                  array_map(
62                      function (ReflectionMethod $method) use ($adapter, $originalClass) : RemoteObjectMethod {
63                          return RemoteObjectMethod::generateMethod(
64                              new MethodReflection($method->getDeclaringClass()->getName(), $method->getName()),
65                              $adapter,
66                              $originalClass
67                          );
68                      },
69                      ProxiedMethodsFilter::getProxiedMethods(
70                          $originalClass,
71                          ['__get', '__set', '__isset', '__unset']
72                      )
73                  ),
74                  [
75                      new StaticProxyConstructor($originalClass, $adapter),
76                      new MagicGet($originalClass, $adapter),
77                      new MagicSet($originalClass, $adapter),
78                      new MagicIsset($originalClass, $adapter),
79                      new MagicUnset($originalClass, $adapter),
80                  ]
81              )
82          );
83      }
84  }
85