Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

ParameterGenerator.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 4.41 KiB


 001  <?php
 002  /*
 003   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 004   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 005   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 006   * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 007   * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 008   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 009   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 010   * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 011   * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 012   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 013   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 014   *
 015   * This software consists of voluntary contributions made by many individuals
 016   * and is licensed under the MIT license.
 017   */
 018   
 019  namespace ProxyManager\Generator;
 020   
 021  use ReflectionException;
 022  use Zend\Code\Generator\ParameterGenerator as ZendParameterGenerator;
 023  use Zend\Code\Generator\ValueGenerator;
 024  use Zend\Code\Reflection\ParameterReflection;
 025   
 026  /**
 027   * Parameter generator that ensures that the parameter type is a FQCN when it is a class
 028   *
 029   * @author Marco Pivetta <ocramius@gmail.com>
 030   * @license MIT
 031   */
 032  class ParameterGenerator extends ZendParameterGenerator
 033  {
 034      /**
 035       * @override - uses `static` to instantiate the parameter
 036       *
 037       * {@inheritDoc}
 038       */
 039      public static function fromReflection(ParameterReflection $reflectionParameter)
 040      {
 041          /* @var $param self */
 042          $param = new static();
 043   
 044          $param->setName($reflectionParameter->getName());
 045          $param->setPosition($reflectionParameter->getPosition());
 046   
 047          $type = self::extractParameterType($reflectionParameter);
 048   
 049          if (null !== $type) {
 050              $param->setType($type);
 051          }
 052   
 053          self::setOptionalParameter($param, $reflectionParameter);
 054   
 055          $param->setPassedByReference($reflectionParameter->isPassedByReference());
 056   
 057          return $param;
 058      }
 059   
 060      /**
 061       * Retrieves the type of a reflection parameter (null if none is found)
 062       *
 063       * @param ParameterReflection $reflectionParameter
 064       *
 065       * @return string|null
 066       */
 067      private static function extractParameterType(ParameterReflection $reflectionParameter)
 068      {
 069          if ($reflectionParameter->isArray()) {
 070              return 'array';
 071          }
 072   
 073          if (method_exists($reflectionParameter, 'isCallable') && $reflectionParameter->isCallable()) {
 074              return 'callable';
 075          }
 076   
 077          if ($typeClass = $reflectionParameter->getClass()) {
 078              return $typeClass->getName();
 079          }
 080   
 081          return null;
 082      }
 083   
 084      /**
 085       * @return string
 086       */
 087      public function generate()
 088      {
 089          return $this->getGeneratedType()
 090              . (true === $this->passedByReference ? '&' : '')
 091              . '$' . $this->name
 092              . $this->generateDefaultValue();
 093      }
 094   
 095      /**
 096       * @return string
 097       */
 098      private function generateDefaultValue()
 099      {
 100          if (null === $this->defaultValue) {
 101              return '';
 102          }
 103   
 104          $defaultValue = $this->defaultValue instanceof ValueGenerator
 105              ? $this->defaultValue
 106              : new ValueGenerator($this->defaultValue);
 107   
 108          $defaultValue->setOutputMode(ValueGenerator::OUTPUT_SINGLE_LINE);
 109   
 110          return ' = ' . $defaultValue;
 111      }
 112   
 113      /**
 114       * Retrieves the generated parameter type
 115       *
 116       * @return string
 117       */
 118      private function getGeneratedType()
 119      {
 120          if (! $this->type || in_array($this->type, static::$simple)) {
 121              return '';
 122          }
 123   
 124          if ('array' === $this->type || 'callable' === $this->type) {
 125              return $this->type . ' ';
 126          }
 127   
 128          return '\\' . trim($this->type, '\\') . ' ';
 129      }
 130   
 131      /**
 132       * Set the default value for a parameter (if it is optional)
 133       *
 134       * @param ZendParameterGenerator $parameterGenerator
 135       * @param ParameterReflection    $reflectionParameter
 136       */
 137      private static function setOptionalParameter(
 138          ZendParameterGenerator $parameterGenerator,
 139          ParameterReflection $reflectionParameter
 140      ) {
 141          if ($reflectionParameter->isOptional()) {
 142              try {
 143                  $parameterGenerator->setDefaultValue($reflectionParameter->getDefaultValue());
 144              } catch (ReflectionException $e) {
 145                  $parameterGenerator->setDefaultValue(null);
 146              }
 147          }
 148      }
 149  }
 150