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

FileLoader.php

Zuletzt modifiziert: 02.04.2025, 15:03 - Dateigröße: 5.43 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\Loader;
013   
014  use Symfony\Component\Config\Exception\FileLoaderImportCircularReferenceException;
015  use Symfony\Component\Config\Exception\FileLoaderLoadException;
016  use Symfony\Component\Config\Exception\FileLocatorFileNotFoundException;
017  use Symfony\Component\Config\FileLocatorInterface;
018  use Symfony\Component\Config\Resource\FileExistenceResource;
019  use Symfony\Component\Config\Resource\GlobResource;
020   
021  /**
022   * FileLoader is the abstract class used by all built-in loaders that are file based.
023   *
024   * @author Fabien Potencier <fabien@symfony.com>
025   */
026  abstract class FileLoader extends Loader
027  {
028      protected static $loading = [];
029   
030      protected $locator;
031   
032      private $currentDir;
033   
034      public function __construct(FileLocatorInterface $locator)
035      {
036          $this->locator = $locator;
037      }
038   
039      /**
040       * Sets the current directory.
041       *
042       * @param string $dir
043       */
044      public function setCurrentDir($dir)
045      {
046          $this->currentDir = $dir;
047      }
048   
049      /**
050       * Returns the file locator used by this loader.
051       *
052       * @return FileLocatorInterface
053       */
054      public function getLocator()
055      {
056          return $this->locator;
057      }
058   
059      /**
060       * Imports a resource.
061       *
062       * @param mixed       $resource       A Resource
063       * @param string|null $type           The resource type or null if unknown
064       * @param bool        $ignoreErrors   Whether to ignore import errors or not
065       * @param string|null $sourceResource The original resource importing the new resource
066       *
067       * @return mixed
068       *
069       * @throws FileLoaderLoadException
070       * @throws FileLoaderImportCircularReferenceException
071       * @throws FileLocatorFileNotFoundException
072       */
073      public function import($resource, $type = null, $ignoreErrors = false, $sourceResource = null)
074      {
075          if (\is_string($resource) && \strlen($resource) !== $i = strcspn($resource, '*?{[')) {
076              $ret = [];
077              $isSubpath = 0 !== $i && false !== strpos(substr($resource, 0, $i), '/');
078              foreach ($this->glob($resource, false, $_, $ignoreErrors || !$isSubpath) as $path => $info) {
079                  if (null !== $res = $this->doImport($path, 'glob' === $type ? null : $type, $ignoreErrors, $sourceResource)) {
080                      $ret[] = $res;
081                  }
082                  $isSubpath = true;
083              }
084   
085              if ($isSubpath) {
086                  return isset($ret[1]) ? $ret : (isset($ret[0]) ? $ret[0] : null);
087              }
088          }
089   
090          return $this->doImport($resource, $type, $ignoreErrors, $sourceResource);
091      }
092   
093      /**
094       * @internal
095       */
096      protected function glob($pattern, $recursive, &$resource = null, $ignoreErrors = false)
097      {
098          if (\strlen($pattern) === $i = strcspn($pattern, '*?{[')) {
099              $prefix = $pattern;
100              $pattern = '';
101          } elseif (0 === $i || false === strpos(substr($pattern, 0, $i), '/')) {
102              $prefix = '.';
103              $pattern = '/'.$pattern;
104          } else {
105              $prefix = \dirname(substr($pattern, 0, 1 + $i));
106              $pattern = substr($pattern, \strlen($prefix));
107          }
108   
109          try {
110              $prefix = $this->locator->locate($prefix, $this->currentDir, true);
111          } catch (FileLocatorFileNotFoundException $e) {
112              if (!$ignoreErrors) {
113                  throw $e;
114              }
115   
116              $resource = [];
117              foreach ($e->getPaths() as $path) {
118                  $resource[] = new FileExistenceResource($path);
119              }
120   
121              return;
122          }
123          $resource = new GlobResource($prefix, $pattern, $recursive);
124   
125          foreach ($resource as $path => $info) {
126              yield $path => $info;
127          }
128      }
129   
130      private function doImport($resource, $type = null, $ignoreErrors = false, $sourceResource = null)
131      {
132          try {
133              $loader = $this->resolve($resource, $type);
134   
135              if ($loader instanceof self && null !== $this->currentDir) {
136                  $resource = $loader->getLocator()->locate($resource, $this->currentDir, false);
137              }
138   
139              $resources = \is_array($resource) ? $resource : [$resource];
140              for ($i = 0; $i < $resourcesCount = \count($resources); ++$i) {
141                  if (isset(self::$loading[$resources[$i]])) {
142                      if ($i == $resourcesCount - 1) {
143                          throw new FileLoaderImportCircularReferenceException(array_keys(self::$loading));
144                      }
145                  } else {
146                      $resource = $resources[$i];
147                      break;
148                  }
149              }
150              self::$loading[$resource] = true;
151   
152              try {
153                  $ret = $loader->load($resource, $type);
154              } finally {
155                  unset(self::$loading[$resource]);
156              }
157   
158              return $ret;
159          } catch (FileLoaderImportCircularReferenceException $e) {
160              throw $e;
161          } catch (\Exception $e) {
162              if (!$ignoreErrors) {
163                  // prevent embedded imports from nesting multiple exceptions
164                  if ($e instanceof FileLoaderLoadException) {
165                      throw $e;
166                  }
167   
168                  throw new FileLoaderLoadException($resource, $sourceResource, null, $e, $type);
169              }
170          }
171   
172          return null;
173      }
174  }
175