[ Index ]

PHP Cross Reference of phpBB-3.3.14-deutsch

title

Body

[close]

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

   1  <?php
   2  
   3  declare(strict_types=1);
   4  
   5  namespace ProxyManager\ProxyGenerator;
   6  
   7  use ProxyManager\Exception\InvalidProxiedClassException;
   8  use ProxyManager\Generator\Util\ClassGeneratorUtils;
   9  use ProxyManager\Proxy\NullObjectInterface;
  10  use ProxyManager\ProxyGenerator\Assertion\CanProxyAssertion;
  11  use ProxyManager\ProxyGenerator\NullObject\MethodGenerator\NullObjectMethodInterceptor;
  12  use ProxyManager\ProxyGenerator\NullObject\MethodGenerator\StaticProxyConstructor;
  13  use ProxyManager\ProxyGenerator\Util\ProxiedMethodsFilter;
  14  use ReflectionClass;
  15  use Zend\Code\Generator\ClassGenerator;
  16  use Zend\Code\Reflection\MethodReflection;
  17  
  18  /**
  19   * Generator for proxies implementing {@see \ProxyManager\Proxy\NullObjectInterface}
  20   *
  21   * {@inheritDoc}
  22   *
  23   * @author Vincent Blanchon <blanchon.vincent@gmail.com>
  24   * @license MIT
  25   */
  26  class NullObjectGenerator implements ProxyGeneratorInterface
  27  {
  28      /**
  29       * {@inheritDoc}
  30       *
  31       * @throws InvalidProxiedClassException
  32       * @throws \Zend\Code\Generator\Exception\InvalidArgumentException
  33       */
  34      public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator)
  35      {
  36          CanProxyAssertion::assertClassCanBeProxied($originalClass);
  37  
  38          $interfaces = [NullObjectInterface::class];
  39  
  40          if ($originalClass->isInterface()) {
  41              $interfaces[] = $originalClass->getName();
  42          } else {
  43              $classGenerator->setExtendedClass($originalClass->getName());
  44          }
  45  
  46          $classGenerator->setImplementedInterfaces($interfaces);
  47  
  48          foreach (ProxiedMethodsFilter::getProxiedMethods($originalClass, []) as $method) {
  49              $classGenerator->addMethodFromGenerator(
  50                  NullObjectMethodInterceptor::generateMethod(
  51                      new MethodReflection($method->getDeclaringClass()->getName(), $method->getName())
  52                  )
  53              );
  54          }
  55  
  56          ClassGeneratorUtils::addMethodIfNotFinal(
  57              $originalClass,
  58              $classGenerator,
  59              new StaticProxyConstructor($originalClass)
  60          );
  61      }
  62  }


Generated: Mon Nov 25 19:05:08 2024 Cross-referenced by PHPXref 0.7.1