Verzeichnisstruktur phpBB-3.3.16


Veröffentlicht
27.04.2026

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

FileLoader.php

Zuletzt modifiziert: 01.05.2026, 11:27 - Dateigröße: 6.88 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\DependencyInjection\Loader;
 013   
 014  use Symfony\Component\Config\FileLocatorInterface;
 015  use Symfony\Component\Config\Loader\FileLoader as BaseFileLoader;
 016  use Symfony\Component\Config\Resource\GlobResource;
 017  use Symfony\Component\DependencyInjection\ChildDefinition;
 018  use Symfony\Component\DependencyInjection\ContainerBuilder;
 019  use Symfony\Component\DependencyInjection\Definition;
 020  use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
 021   
 022  /**
 023   * FileLoader is the abstract class used by all built-in loaders that are file based.
 024   *
 025   * @author Fabien Potencier <fabien@symfony.com>
 026   */
 027  abstract class FileLoader extends BaseFileLoader
 028  {
 029      protected $container;
 030      protected $isLoadingInstanceof = false;
 031      protected $instanceof = [];
 032   
 033      public function __construct(ContainerBuilder $container, FileLocatorInterface $locator)
 034      {
 035          $this->container = $container;
 036   
 037          parent::__construct($locator);
 038      }
 039   
 040      /**
 041       * Registers a set of classes as services using PSR-4 for discovery.
 042       *
 043       * @param Definition $prototype A definition to use as template
 044       * @param string     $namespace The namespace prefix of classes in the scanned directory
 045       * @param string     $resource  The directory to look for classes, glob-patterns allowed
 046       * @param string     $exclude   A globed path of files to exclude
 047       */
 048      public function registerClasses(Definition $prototype, $namespace, $resource, $exclude = null)
 049      {
 050          if ('\\' !== substr($namespace, -1)) {
 051              throw new InvalidArgumentException(sprintf('Namespace prefix must end with a "\\": "%s".', $namespace));
 052          }
 053          if (!preg_match('/^(?:[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+\\\\)++$/', $namespace)) {
 054              throw new InvalidArgumentException(sprintf('Namespace is not a valid PSR-4 prefix: "%s".', $namespace));
 055          }
 056   
 057          $classes = $this->findClasses($namespace, $resource, $exclude);
 058          // prepare for deep cloning
 059          $serializedPrototype = serialize($prototype);
 060          $interfaces = [];
 061          $singlyImplemented = [];
 062   
 063          foreach ($classes as $class => $errorMessage) {
 064              if (interface_exists($class, false)) {
 065                  $interfaces[] = $class;
 066              } else {
 067                  $this->setDefinition($class, $definition = unserialize($serializedPrototype));
 068                  if (null !== $errorMessage) {
 069                      $definition->addError($errorMessage);
 070   
 071                      continue;
 072                  }
 073                  foreach (class_implements($class, false) as $interface) {
 074                      $singlyImplemented[$interface] = isset($singlyImplemented[$interface]) ? false : $class;
 075                  }
 076              }
 077          }
 078          foreach ($interfaces as $interface) {
 079              if (!empty($singlyImplemented[$interface])) {
 080                  $this->container->setAlias($interface, $singlyImplemented[$interface])
 081                      ->setPublic(false);
 082              }
 083          }
 084      }
 085   
 086      /**
 087       * Registers a definition in the container with its instanceof-conditionals.
 088       *
 089       * @param string $id
 090       */
 091      protected function setDefinition($id, Definition $definition)
 092      {
 093          $this->container->removeBindings($id);
 094   
 095          if ($this->isLoadingInstanceof) {
 096              if (!$definition instanceof ChildDefinition) {
 097                  throw new InvalidArgumentException(sprintf('Invalid type definition "%s": ChildDefinition expected, "%s" given.', $id, \get_class($definition)));
 098              }
 099              $this->instanceof[$id] = $definition;
 100          } else {
 101              $this->container->setDefinition($id, $definition instanceof ChildDefinition ? $definition : $definition->setInstanceofConditionals($this->instanceof));
 102          }
 103      }
 104   
 105      private function findClasses($namespace, $pattern, $excludePattern)
 106      {
 107          $parameterBag = $this->container->getParameterBag();
 108   
 109          $excludePaths = [];
 110          $excludePrefix = null;
 111          if ($excludePattern) {
 112              $excludePattern = $parameterBag->unescapeValue($parameterBag->resolveValue($excludePattern));
 113              foreach ($this->glob($excludePattern, true, $resource, true) as $path => $info) {
 114                  if (null === $excludePrefix) {
 115                      $excludePrefix = $resource->getPrefix();
 116                  }
 117   
 118                  // normalize Windows slashes
 119                  $excludePaths[str_replace('\\', '/', $path)] = true;
 120              }
 121          }
 122   
 123          $pattern = $parameterBag->unescapeValue($parameterBag->resolveValue($pattern));
 124          $classes = [];
 125          $extRegexp = \defined('HHVM_VERSION') ? '/\\.(?:php|hh)$/' : '/\\.php$/';
 126          $prefixLen = null;
 127          foreach ($this->glob($pattern, true, $resource) as $path => $info) {
 128              if (null === $prefixLen) {
 129                  $prefixLen = \strlen($resource->getPrefix());
 130   
 131                  if ($excludePrefix && 0 !== strpos($excludePrefix, $resource->getPrefix())) {
 132                      throw new InvalidArgumentException(sprintf('Invalid "exclude" pattern when importing classes for "%s": make sure your "exclude" pattern (%s) is a subset of the "resource" pattern (%s).', $namespace, $excludePattern, $pattern));
 133                  }
 134              }
 135   
 136              if (isset($excludePaths[str_replace('\\', '/', $path)])) {
 137                  continue;
 138              }
 139   
 140              if (!preg_match($extRegexp, $path, $m) || !$info->isReadable()) {
 141                  continue;
 142              }
 143              $class = $namespace.ltrim(str_replace('/', '\\', substr($path, $prefixLen, -\strlen($m[0]))), '\\');
 144   
 145              if (!preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+(?:\\\\[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+)*+$/', $class)) {
 146                  continue;
 147              }
 148   
 149              try {
 150                  $r = $this->container->getReflectionClass($class);
 151              } catch (\ReflectionException $e) {
 152                  $classes[$class] = $e->getMessage();
 153                  continue;
 154              }
 155              // check to make sure the expected class exists
 156              if (!$r) {
 157                  throw new InvalidArgumentException(sprintf('Expected to find class "%s" in file "%s" while importing services from resource "%s", but it was not found! Check the namespace prefix used with the resource.', $class, $path, $pattern));
 158              }
 159   
 160              if ($r->isInstantiable() || $r->isInterface()) {
 161                  $classes[$class] = null;
 162              }
 163          }
 164   
 165          // track only for new & removed files
 166          if ($resource instanceof GlobResource) {
 167              $this->container->addResource($resource);
 168          } else {
 169              foreach ($resource as $path) {
 170                  $this->container->fileExists($path, false);
 171              }
 172          }
 173   
 174          return $classes;
 175      }
 176  }
 177