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

FunctionReflection.php

Zuletzt modifiziert: 09.10.2024, 12:57 - Dateigröße: 7.89 KiB


 001  <?php
 002  /**
 003   * Zend Framework (http://framework.zend.com/)
 004   *
 005   * @link      http://github.com/zendframework/zf2 for the canonical source repository
 006   * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
 007   * @license   http://framework.zend.com/license/new-bsd New BSD License
 008   */
 009   
 010  namespace Zend\Code\Reflection;
 011   
 012  use ReflectionFunction;
 013   
 014  class FunctionReflection extends ReflectionFunction implements ReflectionInterface
 015  {
 016      /**
 017       * Constant use in @MethodReflection to display prototype as an array
 018       */
 019      const PROTOTYPE_AS_ARRAY = 'prototype_as_array';
 020   
 021      /**
 022       * Constant use in @MethodReflection to display prototype as a string
 023       */
 024      const PROTOTYPE_AS_STRING = 'prototype_as_string';
 025   
 026      /**
 027       * Get function DocBlock
 028       *
 029       * @throws Exception\InvalidArgumentException
 030       * @return DocBlockReflection
 031       */
 032      public function getDocBlock()
 033      {
 034          if ('' == ($comment = $this->getDocComment())) {
 035              throw new Exception\InvalidArgumentException(sprintf(
 036                  '%s does not have a DocBlock',
 037                  $this->getName()
 038              ));
 039          }
 040   
 041          $instance = new DocBlockReflection($comment);
 042   
 043          return $instance;
 044      }
 045   
 046      /**
 047       * Get start line (position) of function
 048       *
 049       * @param  bool $includeDocComment
 050       * @return int
 051       */
 052      public function getStartLine($includeDocComment = false)
 053      {
 054          if ($includeDocComment) {
 055              if ($this->getDocComment() != '') {
 056                  return $this->getDocBlock()->getStartLine();
 057              }
 058          }
 059   
 060          return parent::getStartLine();
 061      }
 062   
 063      /**
 064       * Get contents of function
 065       *
 066       * @param  bool   $includeDocBlock
 067       * @return string
 068       */
 069      public function getContents($includeDocBlock = true)
 070      {
 071          $fileName = $this->getFileName();
 072          if (false === $fileName) {
 073              return '';
 074          }
 075   
 076          $startLine = $this->getStartLine();
 077          $endLine = $this->getEndLine();
 078   
 079          // eval'd protect
 080          if (preg_match('#\((\d+)\) : eval\(\)\'d code$#', $fileName, $matches)) {
 081              $fileName = preg_replace('#\(\d+\) : eval\(\)\'d code$#', '', $fileName);
 082              $startLine = $endLine = $matches[1];
 083          }
 084   
 085          $lines = array_slice(
 086              file($fileName, FILE_IGNORE_NEW_LINES),
 087              $startLine - 1,
 088              ($endLine - ($startLine - 1)),
 089              true
 090          );
 091   
 092          $functionLine = implode("\n", $lines);
 093   
 094          $content = '';
 095          if ($this->isClosure()) {
 096              preg_match('#function\s*\([^\)]*\)\s*(use\s*\([^\)]+\))?\s*\{(.*\;)?\s*\}#s', $functionLine, $matches);
 097              if (isset($matches[0])) {
 098                  $content = $matches[0];
 099              }
 100          } else {
 101              $name = substr($this->getName(), strrpos($this->getName(), '\\')+1);
 102              preg_match('#function\s+' . preg_quote($name) . '\s*\([^\)]*\)\s*{([^{}]+({[^}]+})*[^}]+)?}#', $functionLine, $matches);
 103              if (isset($matches[0])) {
 104                  $content = $matches[0];
 105              }
 106          }
 107   
 108          $docComment = $this->getDocComment();
 109   
 110          return $includeDocBlock && $docComment ? $docComment . "\n" . $content : $content;
 111      }
 112   
 113      /**
 114       * Get method prototype
 115       *
 116       * @return array
 117       */
 118      public function getPrototype($format = FunctionReflection::PROTOTYPE_AS_ARRAY)
 119      {
 120          $returnType = 'mixed';
 121          $docBlock = $this->getDocBlock();
 122          if ($docBlock) {
 123              $return = $docBlock->getTag('return');
 124              $returnTypes = $return->getTypes();
 125              $returnType = count($returnTypes) > 1 ? implode('|', $returnTypes) : $returnTypes[0];
 126          }
 127   
 128          $prototype = array(
 129              'namespace' => $this->getNamespaceName(),
 130              'name'      => substr($this->getName(), strlen($this->getNamespaceName()) + 1),
 131              'return'    => $returnType,
 132              'arguments' => array(),
 133          );
 134   
 135          $parameters = $this->getParameters();
 136          foreach ($parameters as $parameter) {
 137              $prototype['arguments'][$parameter->getName()] = array(
 138                  'type'     => $parameter->getType(),
 139                  'required' => !$parameter->isOptional(),
 140                  'by_ref'   => $parameter->isPassedByReference(),
 141                  'default'  => $parameter->isDefaultValueAvailable() ? $parameter->getDefaultValue() : null,
 142              );
 143          }
 144   
 145          if ($format == FunctionReflection::PROTOTYPE_AS_STRING) {
 146              $line = $prototype['return'] . ' ' . $prototype['name'] . '(';
 147              $args = array();
 148              foreach ($prototype['arguments'] as $name => $argument) {
 149                  $argsLine = ($argument['type'] ? $argument['type'] . ' ' : '') . ($argument['by_ref'] ? '&' : '') . '$' . $name;
 150                  if (!$argument['required']) {
 151                      $argsLine .= ' = ' . var_export($argument['default'], true);
 152                  }
 153                  $args[] = $argsLine;
 154              }
 155              $line .= implode(', ', $args);
 156              $line .= ')';
 157   
 158              return $line;
 159          }
 160   
 161          return $prototype;
 162      }
 163   
 164      /**
 165       * Get function parameters
 166       *
 167       * @return ParameterReflection[]
 168       */
 169      public function getParameters()
 170      {
 171          $phpReflections  = parent::getParameters();
 172          $zendReflections = array();
 173          while ($phpReflections && ($phpReflection = array_shift($phpReflections))) {
 174              $instance          = new ParameterReflection($this->getName(), $phpReflection->getName());
 175              $zendReflections[] = $instance;
 176              unset($phpReflection);
 177          }
 178          unset($phpReflections);
 179   
 180          return $zendReflections;
 181      }
 182   
 183      /**
 184       * Get return type tag
 185       *
 186       * @throws Exception\InvalidArgumentException
 187       * @return DocBlockReflection
 188       */
 189      public function getReturn()
 190      {
 191          $docBlock = $this->getDocBlock();
 192          if (!$docBlock->hasTag('return')) {
 193              throw new Exception\InvalidArgumentException(
 194                  'Function does not specify an @return annotation tag; cannot determine return type'
 195              );
 196          }
 197   
 198          $tag    = $docBlock->getTag('return');
 199   
 200          return new DocBlockReflection('@return ' . $tag->getDescription());
 201      }
 202   
 203      /**
 204       * Get method body
 205       *
 206       * @return string|false
 207       */
 208      public function getBody()
 209      {
 210          $fileName = $this->getFileName();
 211          if (false === $fileName) {
 212              throw new Exception\InvalidArgumentException(
 213                  'Cannot determine internals functions body'
 214              );
 215          }
 216   
 217          $startLine = $this->getStartLine();
 218          $endLine = $this->getEndLine();
 219   
 220          // eval'd protect
 221          if (preg_match('#\((\d+)\) : eval\(\)\'d code$#', $fileName, $matches)) {
 222              $fileName = preg_replace('#\(\d+\) : eval\(\)\'d code$#', '', $fileName);
 223              $startLine = $endLine = $matches[1];
 224          }
 225   
 226          $lines = array_slice(
 227              file($fileName, FILE_IGNORE_NEW_LINES),
 228              $startLine - 1,
 229              ($endLine - ($startLine - 1)),
 230              true
 231          );
 232   
 233          $functionLine = implode("\n", $lines);
 234   
 235          $body = false;
 236          if ($this->isClosure()) {
 237              preg_match('#function\s*\([^\)]*\)\s*(use\s*\([^\)]+\))?\s*\{(.*\;)\s*\}#s', $functionLine, $matches);
 238              if (isset($matches[2])) {
 239                  $body = $matches[2];
 240              }
 241          } else {
 242              $name = substr($this->getName(), strrpos($this->getName(), '\\')+1);
 243              preg_match('#function\s+' . $name . '\s*\([^\)]*\)\s*{([^{}]+({[^}]+})*[^}]+)}#', $functionLine, $matches);
 244              if (isset($matches[1])) {
 245                  $body = $matches[1];
 246              }
 247          }
 248   
 249          return $body;
 250      }
 251   
 252      /**
 253       * @return string
 254       */
 255      public function toString()
 256      {
 257          return $this->__toString();
 258      }
 259   
 260      /**
 261       * Required due to bug in php
 262       *
 263       * @return string
 264       */
 265      public function __toString()
 266      {
 267          return parent::__toString();
 268      }
 269  }
 270