Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

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

FileLocator.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 2.75 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;
013   
014  /**
015   * FileLocator uses an array of pre-defined paths to find files.
016   *
017   * @author Fabien Potencier <fabien@symfony.com>
018   */
019  class FileLocator implements FileLocatorInterface
020  {
021      protected $paths;
022   
023      /**
024       * Constructor.
025       *
026       * @param string|array $paths A path or an array of paths where to look for resources
027       */
028      public function __construct($paths = array())
029      {
030          $this->paths = (array) $paths;
031      }
032   
033      /**
034       * Returns a full path for a given file name.
035       *
036       * @param mixed   $name        The file name to locate
037       * @param string  $currentPath The current path
038       * @param bool    $first       Whether to return the first occurrence or an array of filenames
039       *
040       * @return string|array The full path to the file|An array of file paths
041       *
042       * @throws \InvalidArgumentException When file is not found
043       */
044      public function locate($name, $currentPath = null, $first = true)
045      {
046          if ($this->isAbsolutePath($name)) {
047              if (!file_exists($name)) {
048                  throw new \InvalidArgumentException(sprintf('The file "%s" does not exist.', $name));
049              }
050   
051              return $name;
052          }
053   
054          $filepaths = array();
055          if (null !== $currentPath && file_exists($file = $currentPath.DIRECTORY_SEPARATOR.$name)) {
056              if (true === $first) {
057                  return $file;
058              }
059              $filepaths[] = $file;
060          }
061   
062          foreach ($this->paths as $path) {
063              if (file_exists($file = $path.DIRECTORY_SEPARATOR.$name)) {
064                  if (true === $first) {
065                      return $file;
066                  }
067                  $filepaths[] = $file;
068              }
069          }
070   
071          if (!$filepaths) {
072              throw new \InvalidArgumentException(sprintf('The file "%s" does not exist (in: %s%s).', $name, null !== $currentPath ? $currentPath.', ' : '', implode(', ', $this->paths)));
073          }
074   
075          return array_values(array_unique($filepaths));
076      }
077   
078      /**
079       * Returns whether the file path is an absolute path.
080       *
081       * @param string $file A file path
082       *
083       * @return bool
084       */
085      private function isAbsolutePath($file)
086      {
087          if ($file[0] == '/' || $file[0] == '\\'
088              || (strlen($file) > 3 && ctype_alpha($file[0])
089                  && $file[1] == ':'
090                  && ($file[2] == '\\' || $file[2] == '/')
091              )
092              || null !== parse_url($file, PHP_URL_SCHEME)
093          ) {
094              return true;
095          }
096   
097          return false;
098      }
099  }
100