[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolder/MethodGenerator/ -> Constructor.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  namespace ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator;
  20  
  21  use ProxyManager\Generator\MethodGenerator;
  22  use ProxyManager\Generator\ParameterGenerator;
  23  use ReflectionClass;
  24  use ReflectionProperty;
  25  use Zend\Code\Generator\PropertyGenerator;
  26  
  27  /**
  28   * The `__construct` implementation for lazy loading proxies
  29   *
  30   * @author Marco Pivetta <ocramius@gmail.com>
  31   * @license MIT
  32   */
  33  class Constructor extends MethodGenerator
  34  {
  35      /**
  36       * Constructor
  37       */
  38      public function __construct(
  39          ReflectionClass $originalClass,
  40          PropertyGenerator $valueHolder,
  41          PropertyGenerator $prefixInterceptors,
  42          PropertyGenerator $suffixInterceptors
  43      ) {
  44          parent::__construct('__construct');
  45  
  46          $prefix = new ParameterGenerator('prefixInterceptors');
  47          $suffix = new ParameterGenerator('suffixInterceptors');
  48  
  49          $prefix->setDefaultValue(array());
  50          $suffix->setDefaultValue(array());
  51          $prefix->setType('array');
  52          $suffix->setType('array');
  53  
  54          $this->setParameter(new ParameterGenerator('wrappedObject'));
  55          $this->setParameter($prefix);
  56          $this->setParameter($suffix);
  57  
  58          /* @var $publicProperties \ReflectionProperty[] */
  59          $publicProperties = $originalClass->getProperties(ReflectionProperty::IS_PUBLIC);
  60          $unsetProperties  = array();
  61  
  62          foreach ($publicProperties as $publicProperty) {
  63              $unsetProperties[] = '$this->' . $publicProperty->getName();
  64          }
  65  
  66          $this->setDocblock(
  67              "@override constructor to setup interceptors\n\n"
  68              . "@param \\" . $originalClass->getName() . " \$wrappedObject\n"
  69              . "@param \\Closure[] \$prefixInterceptors method interceptors to be used before method logic\n"
  70              . "@param \\Closure[] \$suffixInterceptors method interceptors to be used before method logic"
  71          );
  72          $this->setBody(
  73              ($unsetProperties ? 'unset(' . implode(', ', $unsetProperties) . ");\n\n" : '')
  74              . '$this->' . $valueHolder->getName() . " = \$wrappedObject;\n"
  75              . '$this->' . $prefixInterceptors->getName() . " = \$prefixInterceptors;\n"
  76              . '$this->' . $suffixInterceptors->getName() . " = \$suffixInterceptors;"
  77          );
  78      }
  79  }


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1