[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/vendor/symfony/config/ -> FileLocator.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of the Symfony package.
   5   *
   6   * (c) Fabien Potencier <fabien@symfony.com>
   7   *
   8   * For the full copyright and license information, please view the LICENSE
   9   * file that was distributed with this source code.
  10   */
  11  
  12  namespace Symfony\Component\Config;
  13  
  14  /**
  15   * FileLocator uses an array of pre-defined paths to find files.
  16   *
  17   * @author Fabien Potencier <fabien@symfony.com>
  18   */
  19  class FileLocator implements FileLocatorInterface
  20  {
  21      protected $paths;
  22  
  23      /**
  24       * @param string|array $paths A path or an array of paths where to look for resources
  25       */
  26      public function __construct($paths = array())
  27      {
  28          $this->paths = (array) $paths;
  29      }
  30  
  31      /**
  32       * {@inheritdoc}
  33       */
  34      public function locate($name, $currentPath = null, $first = true)
  35      {
  36          if ('' == $name) {
  37              throw new \InvalidArgumentException('An empty file name is not valid to be located.');
  38          }
  39  
  40          if ($this->isAbsolutePath($name)) {
  41              if (!file_exists($name)) {
  42                  throw new \InvalidArgumentException(sprintf('The file "%s" does not exist.', $name));
  43              }
  44  
  45              return $name;
  46          }
  47  
  48          $paths = $this->paths;
  49  
  50          if (null !== $currentPath) {
  51              array_unshift($paths, $currentPath);
  52          }
  53  
  54          $paths = array_unique($paths);
  55          $filepaths = array();
  56  
  57          foreach ($paths as $path) {
  58              if (@file_exists($file = $path.\DIRECTORY_SEPARATOR.$name)) {
  59                  if (true === $first) {
  60                      return $file;
  61                  }
  62                  $filepaths[] = $file;
  63              }
  64          }
  65  
  66          if (!$filepaths) {
  67              throw new \InvalidArgumentException(sprintf('The file "%s" does not exist (in: %s).', $name, implode(', ', $paths)));
  68          }
  69  
  70          return $filepaths;
  71      }
  72  
  73      /**
  74       * Returns whether the file path is an absolute path.
  75       *
  76       * @param string $file A file path
  77       *
  78       * @return bool
  79       */
  80      private function isAbsolutePath($file)
  81      {
  82          if ('/' === $file[0] || '\\' === $file[0]
  83              || (\strlen($file) > 3 && ctype_alpha($file[0])
  84                  && ':' === $file[1]
  85                  && ('\\' === $file[2] || '/' === $file[2])
  86              )
  87              || null !== parse_url($file, PHP_URL_SCHEME)
  88          ) {
  89              return true;
  90          }
  91  
  92          return false;
  93      }
  94  }


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1