[ Index ]

PHP Cross Reference of phpBB-3.3.5-deutsch

title

Body

[close]

/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/ -> MagicIsset.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\LazyLoadingValueHolder\MethodGenerator;
  22  
  23  use ProxyManager\Generator\MagicMethodGenerator;
  24  use Zend\Code\Generator\ParameterGenerator;
  25  use ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap;
  26  use ProxyManager\ProxyGenerator\Util\PublicScopeSimulator;
  27  use ReflectionClass;
  28  use Zend\Code\Generator\PropertyGenerator;
  29  
  30  /**
  31   * Magic `__isset` method for lazy loading value holder objects
  32   *
  33   * @author Marco Pivetta <ocramius@gmail.com>
  34   * @license MIT
  35   */
  36  class MagicIsset extends MagicMethodGenerator
  37  {
  38      /**
  39       * Constructor
  40       *
  41       * @param ReflectionClass     $originalClass
  42       * @param PropertyGenerator   $initializerProperty
  43       * @param PropertyGenerator   $valueHolderProperty
  44       * @param PublicPropertiesMap $publicProperties
  45       *
  46       * @throws \Zend\Code\Generator\Exception\InvalidArgumentException
  47       * @throws \InvalidArgumentException
  48       */
  49      public function __construct(
  50          ReflectionClass $originalClass,
  51          PropertyGenerator $initializerProperty,
  52          PropertyGenerator $valueHolderProperty,
  53          PublicPropertiesMap $publicProperties
  54      ) {
  55          parent::__construct($originalClass, '__isset', [new ParameterGenerator('name')]);
  56  
  57          $initializer = $initializerProperty->getName();
  58          $valueHolder = $valueHolderProperty->getName();
  59          $callParent  = '';
  60  
  61          $this->setDocBlock(($originalClass->hasMethod('__isset') ? "{@inheritDoc}\n" : '') . '@param string $name');
  62  
  63          if (! $publicProperties->isEmpty()) {
  64              $callParent = 'if (isset(self::$' . $publicProperties->getName() . "[\$name])) {\n"
  65                  . '    return isset($this->' . $valueHolder . '->$name);'
  66                  . "\n}\n\n";
  67          }
  68  
  69          $callParent .= PublicScopeSimulator::getPublicAccessSimulationCode(
  70              PublicScopeSimulator::OPERATION_ISSET,
  71              'name',
  72              null,
  73              $valueHolderProperty
  74          );
  75  
  76          $this->setBody(
  77              '$this->' . $initializer . ' && $this->' . $initializer
  78              . '->__invoke($this->' . $valueHolder . ', $this, \'__isset\', array(\'name\' => $name), $this->'
  79              . $initializer . ');' . "\n\n" . $callParent
  80          );
  81      }
  82  }


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