[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/ -> LazyLoadingGhostGenerator.php (source)

   1  <?php
   2  /*
   3   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   4   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   5   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
   6   * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
   7   * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   8   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   9   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  10   * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  11   * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  12   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  13   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14   *
  15   * This software consists of voluntary contributions made by many individuals
  16   * and is licensed under the MIT license.
  17   */
  18  
  19  namespace ProxyManager\ProxyGenerator;
  20  
  21  use ProxyManager\Generator\Util\ClassGeneratorUtils;
  22  use ProxyManager\ProxyGenerator\Assertion\CanProxyAssertion;
  23  use ProxyManager\ProxyGenerator\LazyLoading\MethodGenerator\Constructor;
  24  use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\CallInitializer;
  25  use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\GetProxyInitializer;
  26  use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\InitializeProxy;
  27  use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\IsProxyInitialized;
  28  use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\LazyLoadingMethodInterceptor;
  29  use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicClone;
  30  use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicGet;
  31  use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicIsset;
  32  use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicSet;
  33  use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicSleep;
  34  use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicUnset;
  35  use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\SetProxyInitializer;
  36  use ProxyManager\ProxyGenerator\LazyLoadingGhost\PropertyGenerator\InitializationTracker;
  37  use ProxyManager\ProxyGenerator\LazyLoadingGhost\PropertyGenerator\InitializerProperty;
  38  use ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesDefaults;
  39  use ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap;
  40  use ProxyManager\ProxyGenerator\Util\ProxiedMethodsFilter;
  41  use ReflectionClass;
  42  use ReflectionMethod;
  43  use Zend\Code\Generator\ClassGenerator;
  44  use Zend\Code\Generator\MethodGenerator;
  45  use Zend\Code\Reflection\MethodReflection;
  46  
  47  /**
  48   * Generator for proxies implementing {@see \ProxyManager\Proxy\GhostObjectInterface}
  49   *
  50   * {@inheritDoc}
  51   *
  52   * @author Marco Pivetta <ocramius@gmail.com>
  53   * @license MIT
  54   */
  55  class LazyLoadingGhostGenerator implements ProxyGeneratorInterface
  56  {
  57      /**
  58       * {@inheritDoc}
  59       */
  60      public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator)
  61      {
  62          CanProxyAssertion::assertClassCanBeProxied($originalClass);
  63  
  64          $interfaces          = array('ProxyManager\\Proxy\\GhostObjectInterface');
  65          $publicProperties    = new PublicPropertiesMap($originalClass);
  66          $publicPropsDefaults = new PublicPropertiesDefaults($originalClass);
  67  
  68          if ($originalClass->isInterface()) {
  69              $interfaces[] = $originalClass->getName();
  70          } else {
  71              $classGenerator->setExtendedClass($originalClass->getName());
  72          }
  73  
  74          $classGenerator->setImplementedInterfaces($interfaces);
  75          $classGenerator->addPropertyFromGenerator($initializer = new InitializerProperty());
  76          $classGenerator->addPropertyFromGenerator($initializationTracker = new InitializationTracker());
  77          $classGenerator->addPropertyFromGenerator($publicProperties);
  78          $classGenerator->addPropertyFromGenerator($publicPropsDefaults);
  79  
  80          $init = new CallInitializer($initializer, $publicPropsDefaults, $initializationTracker);
  81  
  82          array_map(
  83              function (MethodGenerator $generatedMethod) use ($originalClass, $classGenerator) {
  84                  ClassGeneratorUtils::addMethodIfNotFinal($originalClass, $classGenerator, $generatedMethod);
  85              },
  86              array_merge(
  87                  array_map(
  88                      function (ReflectionMethod $method) use ($initializer, $init) {
  89                          return LazyLoadingMethodInterceptor::generateMethod(
  90                              new MethodReflection($method->getDeclaringClass()->getName(), $method->getName()),
  91                              $initializer,
  92                              $init
  93                          );
  94                      },
  95                      ProxiedMethodsFilter::getProxiedMethods($originalClass)
  96                  ),
  97                  array(
  98                      $init,
  99                      new Constructor($originalClass, $initializer),
 100                      new MagicGet($originalClass, $initializer, $init, $publicProperties),
 101                      new MagicSet($originalClass, $initializer, $init, $publicProperties),
 102                      new MagicIsset($originalClass, $initializer, $init, $publicProperties),
 103                      new MagicUnset($originalClass, $initializer, $init, $publicProperties),
 104                      new MagicClone($originalClass, $initializer, $init, $publicProperties),
 105                      new MagicSleep($originalClass, $initializer, $init, $publicProperties),
 106                      new SetProxyInitializer($initializer),
 107                      new GetProxyInitializer($initializer),
 108                      new InitializeProxy($initializer, $init),
 109                      new IsProxyInitialized($initializer),
 110                  )
 111              )
 112          );
 113      }
 114  }


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1