[ Index ]

PHP Cross Reference of phpBB-3.3.14-deutsch

title

Body

[close]

/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/ -> MagicUnset.php (source)

   1  <?php
   2  
   3  declare(strict_types=1);
   4  
   5  namespace ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator;
   6  
   7  use ProxyManager\Generator\MagicMethodGenerator;
   8  use Zend\Code\Generator\ParameterGenerator;
   9  use ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap;
  10  use ProxyManager\ProxyGenerator\Util\PublicScopeSimulator;
  11  use ReflectionClass;
  12  use Zend\Code\Generator\PropertyGenerator;
  13  
  14  /**
  15   * Magic `__unset` method for lazy loading value holder objects
  16   *
  17   * @author Marco Pivetta <ocramius@gmail.com>
  18   * @license MIT
  19   */
  20  class MagicUnset extends MagicMethodGenerator
  21  {
  22      /**
  23       * Constructor
  24       *
  25       * @param ReflectionClass     $originalClass
  26       * @param PropertyGenerator   $initializerProperty
  27       * @param PropertyGenerator   $valueHolderProperty
  28       * @param PublicPropertiesMap $publicProperties
  29       *
  30       * @throws \Zend\Code\Generator\Exception\InvalidArgumentException
  31       * @throws \InvalidArgumentException
  32       */
  33      public function __construct(
  34          ReflectionClass $originalClass,
  35          PropertyGenerator $initializerProperty,
  36          PropertyGenerator $valueHolderProperty,
  37          PublicPropertiesMap $publicProperties
  38      ) {
  39          parent::__construct($originalClass, '__unset', [new ParameterGenerator('name')]);
  40  
  41          $hasParent   = $originalClass->hasMethod('__unset');
  42          $initializer = $initializerProperty->getName();
  43          $valueHolder = $valueHolderProperty->getName();
  44          $callParent  = '';
  45  
  46          if (! $publicProperties->isEmpty()) {
  47              $callParent = 'if (isset(self::$' . $publicProperties->getName() . "[\$name])) {\n"
  48                  . '    unset($this->' . $valueHolder . '->$name);' . "\n\n    return;"
  49                  . "\n}\n\n";
  50          }
  51  
  52          $callParent .= $hasParent
  53              ? 'return $this->' . $valueHolder . '->__unset($name);'
  54              : PublicScopeSimulator::getPublicAccessSimulationCode(
  55                  PublicScopeSimulator::OPERATION_UNSET,
  56                  'name',
  57                  null,
  58                  $valueHolderProperty
  59              );
  60  
  61          $this->setBody(
  62              '$this->' . $initializer . ' && $this->' . $initializer
  63              . '->__invoke($this->' . $valueHolder . ', $this, \'__unset\', array(\'name\' => $name), $this->'
  64              . $initializer . ');' . "\n\n" . $callParent
  65          );
  66      }
  67  }


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