[ Index ]

PHP Cross Reference of phpBB-3.3.5-deutsch

title

Body

[close]

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


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