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

LazyLoadingValueHolderGenerator.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 5.62 KiB


 001  <?php
 002  /*
 003   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 004   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 005   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 006   * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 007   * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 008   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 009   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 010   * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 011   * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 012   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 013   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 014   *
 015   * This software consists of voluntary contributions made by many individuals
 016   * and is licensed under the MIT license.
 017   */
 018   
 019  namespace ProxyManager\ProxyGenerator;
 020   
 021  use ProxyManager\Generator\Util\ClassGeneratorUtils;
 022  use ProxyManager\ProxyGenerator\AccessInterceptor\MethodGenerator\MagicWakeup;
 023  use ProxyManager\ProxyGenerator\Assertion\CanProxyAssertion;
 024  use ProxyManager\ProxyGenerator\LazyLoading\MethodGenerator\Constructor;
 025  use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\GetProxyInitializer;
 026  use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\InitializeProxy;
 027  use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\IsProxyInitialized;
 028  use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\LazyLoadingMethodInterceptor;
 029  use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicClone;
 030  use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicGet;
 031  use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicIsset;
 032  use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicSet;
 033  use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicSleep;
 034  use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicUnset;
 035  use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\SetProxyInitializer;
 036  use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\PropertyGenerator\InitializerProperty;
 037  use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\PropertyGenerator\ValueHolderProperty;
 038  use ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap;
 039  use ProxyManager\ProxyGenerator\Util\ProxiedMethodsFilter;
 040  use ProxyManager\ProxyGenerator\ValueHolder\MethodGenerator\GetWrappedValueHolderValue;
 041  use ReflectionClass;
 042  use ReflectionMethod;
 043  use Zend\Code\Generator\ClassGenerator;
 044  use Zend\Code\Generator\MethodGenerator;
 045  use Zend\Code\Reflection\MethodReflection;
 046   
 047  /**
 048   * Generator for proxies implementing {@see \ProxyManager\Proxy\VirtualProxyInterface}
 049   *
 050   * {@inheritDoc}
 051   *
 052   * @author Marco Pivetta <ocramius@gmail.com>
 053   * @license MIT
 054   */
 055  class LazyLoadingValueHolderGenerator implements ProxyGeneratorInterface
 056  {
 057      /**
 058       * {@inheritDoc}
 059       */
 060      public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator)
 061      {
 062          CanProxyAssertion::assertClassCanBeProxied($originalClass);
 063   
 064          $interfaces          = array('ProxyManager\\Proxy\\VirtualProxyInterface');
 065          $publicProperties    = new PublicPropertiesMap($originalClass);
 066   
 067          if ($originalClass->isInterface()) {
 068              $interfaces[] = $originalClass->getName();
 069          } else {
 070              $classGenerator->setExtendedClass($originalClass->getName());
 071          }
 072   
 073          $classGenerator->setImplementedInterfaces($interfaces);
 074          $classGenerator->addPropertyFromGenerator($valueHolder = new ValueHolderProperty());
 075          $classGenerator->addPropertyFromGenerator($initializer = new InitializerProperty());
 076          $classGenerator->addPropertyFromGenerator($publicProperties);
 077   
 078          array_map(
 079              function (MethodGenerator $generatedMethod) use ($originalClass, $classGenerator) {
 080                  ClassGeneratorUtils::addMethodIfNotFinal($originalClass, $classGenerator, $generatedMethod);
 081              },
 082              array_merge(
 083                  array_map(
 084                      function (ReflectionMethod $method) use ($initializer, $valueHolder) {
 085                          return LazyLoadingMethodInterceptor::generateMethod(
 086                              new MethodReflection($method->getDeclaringClass()->getName(), $method->getName()),
 087                              $initializer,
 088                              $valueHolder
 089                          );
 090                      },
 091                      ProxiedMethodsFilter::getProxiedMethods($originalClass)
 092                  ),
 093                  array(
 094                      new Constructor($originalClass, $initializer),
 095                      new MagicGet($originalClass, $initializer, $valueHolder, $publicProperties),
 096                      new MagicSet($originalClass, $initializer, $valueHolder, $publicProperties),
 097                      new MagicIsset($originalClass, $initializer, $valueHolder, $publicProperties),
 098                      new MagicUnset($originalClass, $initializer, $valueHolder, $publicProperties),
 099                      new MagicClone($originalClass, $initializer, $valueHolder),
 100                      new MagicSleep($originalClass, $initializer, $valueHolder),
 101                      new MagicWakeup($originalClass),
 102                      new SetProxyInitializer($initializer),
 103                      new GetProxyInitializer($initializer),
 104                      new InitializeProxy($initializer, $valueHolder),
 105                      new IsProxyInitialized($valueHolder),
 106                      new GetWrappedValueHolderValue($valueHolder),
 107                  )
 108              )
 109          );
 110      }
 111  }
 112