[ Index ]

PHP Cross Reference of phpBB-3.1.12-deutsch

title

Body

[close]

/vendor/symfony/config/Symfony/Component/Config/Loader/ -> FileLoader.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\Loader;
  13  
  14  use Symfony\Component\Config\FileLocatorInterface;
  15  use Symfony\Component\Config\Exception\FileLoaderLoadException;
  16  use Symfony\Component\Config\Exception\FileLoaderImportCircularReferenceException;
  17  
  18  /**
  19   * FileLoader is the abstract class used by all built-in loaders that are file based.
  20   *
  21   * @author Fabien Potencier <fabien@symfony.com>
  22   */
  23  abstract class FileLoader extends Loader
  24  {
  25      /**
  26       * @var array
  27       */
  28      protected static $loading = array();
  29  
  30      /**
  31       * @var FileLocatorInterface
  32       */
  33      protected $locator;
  34  
  35      private $currentDir;
  36  
  37      /**
  38       * Constructor.
  39       *
  40       * @param FileLocatorInterface $locator A FileLocatorInterface instance
  41       */
  42      public function __construct(FileLocatorInterface $locator)
  43      {
  44          $this->locator = $locator;
  45      }
  46  
  47      /**
  48       * Sets the current directory.
  49       *
  50       * @param string $dir
  51       */
  52      public function setCurrentDir($dir)
  53      {
  54          $this->currentDir = $dir;
  55      }
  56  
  57      /**
  58       * Returns the file locator used by this loader.
  59       *
  60       * @return FileLocatorInterface
  61       */
  62      public function getLocator()
  63      {
  64          return $this->locator;
  65      }
  66  
  67      /**
  68       * Imports a resource.
  69       *
  70       * @param mixed       $resource       A Resource
  71       * @param string|null $type           The resource type or null if unknown
  72       * @param bool        $ignoreErrors   Whether to ignore import errors or not
  73       * @param string|null $sourceResource The original resource importing the new resource
  74       *
  75       * @return mixed
  76       *
  77       * @throws FileLoaderLoadException
  78       * @throws FileLoaderImportCircularReferenceException
  79       */
  80      public function import($resource, $type = null, $ignoreErrors = false, $sourceResource = null)
  81      {
  82          try {
  83              $loader = $this->resolve($resource, $type);
  84  
  85              if ($loader instanceof self && null !== $this->currentDir) {
  86                  // we fallback to the current locator to keep BC
  87                  // as some some loaders do not call the parent __construct()
  88                  // @deprecated should be removed in 3.0
  89                  $locator = $loader->getLocator() ?: $this->locator;
  90                  $resource = $locator->locate($resource, $this->currentDir, false);
  91              }
  92  
  93              $resources = is_array($resource) ? $resource : array($resource);
  94              for ($i = 0; $i < $resourcesCount = count($resources); ++$i) {
  95                  if (isset(self::$loading[$resources[$i]])) {
  96                      if ($i == $resourcesCount - 1) {
  97                          throw new FileLoaderImportCircularReferenceException(array_keys(self::$loading));
  98                      }
  99                  } else {
 100                      $resource = $resources[$i];
 101                      break;
 102                  }
 103              }
 104              self::$loading[$resource] = true;
 105  
 106              try {
 107                  $ret = $loader->load($resource, $type);
 108              } catch (\Exception $e) {
 109                  unset(self::$loading[$resource]);
 110                  throw $e;
 111              } catch (\Throwable $e) {
 112                  unset(self::$loading[$resource]);
 113                  throw $e;
 114              }
 115  
 116              unset(self::$loading[$resource]);
 117  
 118              return $ret;
 119          } catch (FileLoaderImportCircularReferenceException $e) {
 120              throw $e;
 121          } catch (\Exception $e) {
 122              if (!$ignoreErrors) {
 123                  // prevent embedded imports from nesting multiple exceptions
 124                  if ($e instanceof FileLoaderLoadException) {
 125                      throw $e;
 126                  }
 127  
 128                  throw new FileLoaderLoadException($resource, $sourceResource, null, $e);
 129              }
 130          }
 131      }
 132  }


Generated: Thu Jan 11 00:25:41 2018 Cross-referenced by PHPXref 0.7.1