[ Index ]

PHP Cross Reference of phpBB-3.3.5-deutsch

title

Body

[close]

/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/RemoteObject/MethodGenerator/ -> StaticProxyConstructor.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  declare(strict_types=1);
  20  
  21  namespace ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator;
  22  
  23  use ProxyManager\Factory\RemoteObject\AdapterInterface;
  24  use ProxyManager\Generator\MethodGenerator;
  25  use ProxyManager\ProxyGenerator\Util\Properties;
  26  use ProxyManager\ProxyGenerator\Util\UnsetPropertiesGenerator;
  27  use ReflectionClass;
  28  use Zend\Code\Generator\ParameterGenerator;
  29  use Zend\Code\Generator\PropertyGenerator;
  30  
  31  /**
  32   * The `staticProxyConstructor` implementation for remote object proxies
  33   *
  34   * @author Vincent Blanchon <blanchon.vincent@gmail.com>
  35   * @author Marco Pivetta <ocramius@gmail.com>
  36   * @license MIT
  37   */
  38  class StaticProxyConstructor extends MethodGenerator
  39  {
  40      /**
  41       * Constructor
  42       *
  43       * @param ReflectionClass   $originalClass Reflection of the class to proxy
  44       * @param PropertyGenerator $adapter       Adapter property
  45       */
  46      public function __construct(ReflectionClass $originalClass, PropertyGenerator $adapter)
  47      {
  48          $adapterName = $adapter->getName();
  49  
  50          parent::__construct(
  51              'staticProxyConstructor',
  52              [new ParameterGenerator($adapterName, AdapterInterface::class)],
  53              MethodGenerator::FLAG_PUBLIC | MethodGenerator::FLAG_STATIC,
  54              null,
  55              'Constructor for remote object control\n\n'
  56              . '@param \\ProxyManager\\Factory\\RemoteObject\\AdapterInterface \$adapter'
  57          );
  58  
  59          $body = 'static $reflection;' . "\n\n"
  60              . '$reflection = $reflection ?: $reflection = new \ReflectionClass(__CLASS__);' . "\n"
  61              . '$instance = (new \ReflectionClass(get_class()))->newInstanceWithoutConstructor();' . "\n\n"
  62              . '$instance->' . $adapterName . ' = $' . $adapterName . ";\n\n"
  63              . UnsetPropertiesGenerator::generateSnippet(Properties::fromReflectionClass($originalClass), 'instance');
  64  
  65          $this->setBody($body . "\n\nreturn \$instance;");
  66      }
  67  }


Generated: Mon Oct 4 17:42:11 2021 Cross-referenced by PHPXref 0.7.1