[ Index ]

PHP Cross Reference of phpBB-3.3.7-deutsch

title

Body

[close]

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


Generated: Thu Mar 24 21:31:15 2022 Cross-referenced by PHPXref 0.7.1