Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

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

ReflectionClassResource.php

Zuletzt modifiziert: 02.04.2025, 15:03 - Dateigröße: 8.49 KiB


001  <?php
002   
003  /*
004   * This file is part of the Symfony package.
005   *
006   * (c) Fabien Potencier <fabien@symfony.com>
007   *
008   * For the full copyright and license information, please view the LICENSE
009   * file that was distributed with this source code.
010   */
011   
012  namespace Symfony\Component\Config\Resource;
013   
014  use Symfony\Component\DependencyInjection\ServiceSubscriberInterface;
015  use Symfony\Component\EventDispatcher\EventSubscriberInterface;
016   
017  /**
018   * @author Nicolas Grekas <p@tchwork.com>
019   */
020  class ReflectionClassResource implements SelfCheckingResourceInterface, \Serializable
021  {
022      private $files = [];
023      private $className;
024      private $classReflector;
025      private $excludedVendors = [];
026      private $hash;
027   
028      public function __construct(\ReflectionClass $classReflector, $excludedVendors = [])
029      {
030          $this->className = $classReflector->name;
031          $this->classReflector = $classReflector;
032          $this->excludedVendors = $excludedVendors;
033      }
034   
035      public function isFresh($timestamp)
036      {
037          if (null === $this->hash) {
038              $this->hash = $this->computeHash();
039              $this->loadFiles($this->classReflector);
040          }
041   
042          foreach ($this->files as $file => $v) {
043              if (false === $filemtime = @filemtime($file)) {
044                  return false;
045              }
046   
047              if ($filemtime > $timestamp) {
048                  return $this->hash === $this->computeHash();
049              }
050          }
051   
052          return true;
053      }
054   
055      public function __toString()
056      {
057          return 'reflection.'.$this->className;
058      }
059   
060      /**
061       * @internal
062       */
063      public function serialize()
064      {
065          if (null === $this->hash) {
066              $this->hash = $this->computeHash();
067              $this->loadFiles($this->classReflector);
068          }
069   
070          return serialize([$this->files, $this->className, $this->hash]);
071      }
072   
073      /**
074       * @internal
075       */
076      public function unserialize($serialized)
077      {
078          list($this->files, $this->className, $this->hash) = unserialize($serialized);
079      }
080   
081      private function loadFiles(\ReflectionClass $class)
082      {
083          foreach ($class->getInterfaces() as $v) {
084              $this->loadFiles($v);
085          }
086          do {
087              $file = $class->getFileName();
088              if (false !== $file && file_exists($file)) {
089                  foreach ($this->excludedVendors as $vendor) {
090                      if (0 === strpos($file, $vendor) && false !== strpbrk(substr($file, \strlen($vendor), 1), '/'.\DIRECTORY_SEPARATOR)) {
091                          $file = false;
092                          break;
093                      }
094                  }
095                  if ($file) {
096                      $this->files[$file] = null;
097                  }
098              }
099              foreach ($class->getTraits() as $v) {
100                  $this->loadFiles($v);
101              }
102          } while ($class = $class->getParentClass());
103      }
104   
105      private function computeHash()
106      {
107          if (null === $this->classReflector) {
108              try {
109                  $this->classReflector = new \ReflectionClass($this->className);
110              } catch (\ReflectionException $e) {
111                  // the class does not exist anymore
112                  return false;
113              }
114          }
115          $hash = hash_init('md5');
116   
117          foreach ($this->generateSignature($this->classReflector) as $info) {
118              hash_update($hash, $info);
119          }
120   
121          return hash_final($hash);
122      }
123   
124      private function generateSignature(\ReflectionClass $class)
125      {
126          yield $class->getDocComment();
127          yield (int) $class->isFinal();
128          yield (int) $class->isAbstract();
129   
130          if ($class->isTrait()) {
131              yield print_r(class_uses($class->name), true);
132          } else {
133              yield print_r(class_parents($class->name), true);
134              yield print_r(class_implements($class->name), true);
135              yield print_r($class->getConstants(), true);
136          }
137   
138          if (!$class->isInterface()) {
139              $defaults = $class->getDefaultProperties();
140   
141              foreach ($class->getProperties(\ReflectionProperty::IS_PUBLIC | \ReflectionProperty::IS_PROTECTED) as $p) {
142                  yield $p->getDocComment();
143                  yield $p->isDefault() ? '<default>' : '';
144                  yield $p->isPublic() ? 'public' : 'protected';
145                  yield $p->isStatic() ? 'static' : '';
146                  yield '$'.$p->name;
147                  yield print_r(isset($defaults[$p->name]) && !\is_object($defaults[$p->name]) ? $defaults[$p->name] : null, true);
148              }
149          }
150   
151          if (\defined('HHVM_VERSION')) {
152              foreach ($class->getMethods(\ReflectionMethod::IS_PUBLIC | \ReflectionMethod::IS_PROTECTED) as $m) {
153                  // workaround HHVM bug with variadics, see https://github.com/facebook/hhvm/issues/5762
154                  yield preg_replace('/^  @@.*/m', '', new ReflectionMethodHhvmWrapper($m->class, $m->name));
155              }
156          } else {
157              foreach ($class->getMethods(\ReflectionMethod::IS_PUBLIC | \ReflectionMethod::IS_PROTECTED) as $m) {
158                  $defaults = [];
159                  $parametersWithUndefinedConstants = [];
160                  foreach ($m->getParameters() as $p) {
161                      if (!$p->isDefaultValueAvailable()) {
162                          $defaults[$p->name] = null;
163   
164                          continue;
165                      }
166   
167                      if (!$p->isDefaultValueConstant() || \defined($p->getDefaultValueConstantName())) {
168                          $defaults[$p->name] = $p->getDefaultValue();
169   
170                          continue;
171                      }
172   
173                      $defaults[$p->name] = $p->getDefaultValueConstantName();
174                      $parametersWithUndefinedConstants[$p->name] = true;
175                  }
176   
177                  if (!$parametersWithUndefinedConstants) {
178                      yield preg_replace('/^  @@.*/m', '', $m);
179                  } else {
180                      $t = \PHP_VERSION_ID >= 70000 ? $m->getReturnType() : '';
181                      $stack = [
182                          $m->getDocComment(),
183                          $m->getName(),
184                          $m->isAbstract(),
185                          $m->isFinal(),
186                          $m->isStatic(),
187                          $m->isPublic(),
188                          $m->isPrivate(),
189                          $m->isProtected(),
190                          $m->returnsReference(),
191                          $t instanceof \ReflectionNamedType ? ((string) $t->allowsNull()).$t->getName() : (string) $t,
192                      ];
193   
194                      foreach ($m->getParameters() as $p) {
195                          if (!isset($parametersWithUndefinedConstants[$p->name])) {
196                              $stack[] = (string) $p;
197                          } else {
198                              $t = \PHP_VERSION_ID >= 70000 ? $p->getType() : '';
199                              $stack[] = $p->isOptional();
200                              $stack[] = $t instanceof \ReflectionNamedType ? ((string) $t->allowsNull()).$t->getName() : (string) $t;
201                              $stack[] = $p->isPassedByReference();
202                              $stack[] = \PHP_VERSION_ID >= 50600 ? $p->isVariadic() : '';
203                              $stack[] = $p->getName();
204                          }
205                      }
206   
207                      yield implode(',', $stack);
208                  }
209   
210                  yield print_r($defaults, true);
211              }
212          }
213   
214          if ($class->isAbstract() || $class->isInterface() || $class->isTrait()) {
215              return;
216          }
217   
218          if (interface_exists(EventSubscriberInterface::class, false) && $class->isSubclassOf(EventSubscriberInterface::class)) {
219              yield EventSubscriberInterface::class;
220              yield print_r(\call_user_func([$class->name, 'getSubscribedEvents']), true);
221          }
222   
223          if (interface_exists(ServiceSubscriberInterface::class, false) && $class->isSubclassOf(ServiceSubscriberInterface::class)) {
224              yield ServiceSubscriberInterface::class;
225              yield print_r(\call_user_func([$class->name, 'getSubscribedServices']), true);
226          }
227      }
228  }
229   
230  /**
231   * @internal
232   */
233  class ReflectionMethodHhvmWrapper extends \ReflectionMethod
234  {
235      public function getParameters()
236      {
237          $params = [];
238   
239          foreach (parent::getParameters() as $i => $p) {
240              $params[] = new ReflectionParameterHhvmWrapper([$this->class, $this->name], $i);
241          }
242   
243          return $params;
244      }
245  }
246   
247  /**
248   * @internal
249   */
250  class ReflectionParameterHhvmWrapper extends \ReflectionParameter
251  {
252      public function getDefaultValue()
253      {
254          return [$this->isVariadic(), $this->isDefaultValueAvailable() ? parent::getDefaultValue() : null];
255      }
256  }
257