[ Index ]

PHP Cross Reference of phpBB-3.3.2-deutsch

title

Body

[close]

/vendor/symfony/dependency-injection/Loader/ -> IniFileLoader.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\DependencyInjection\Loader;
  13  
  14  use Symfony\Component\Config\Util\XmlUtils;
  15  use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
  16  
  17  /**
  18   * IniFileLoader loads parameters from INI files.
  19   *
  20   * @author Fabien Potencier <fabien@symfony.com>
  21   */
  22  class IniFileLoader extends FileLoader
  23  {
  24      /**
  25       * {@inheritdoc}
  26       */
  27      public function load($resource, $type = null)
  28      {
  29          $path = $this->locator->locate($resource);
  30  
  31          $this->container->fileExists($path);
  32  
  33          // first pass to catch parsing errors
  34          $result = parse_ini_file($path, true);
  35          if (false === $result || [] === $result) {
  36              throw new InvalidArgumentException(sprintf('The "%s" file is not valid.', $resource));
  37          }
  38  
  39          // real raw parsing
  40          $result = parse_ini_file($path, true, \INI_SCANNER_RAW);
  41  
  42          if (isset($result['parameters']) && \is_array($result['parameters'])) {
  43              foreach ($result['parameters'] as $key => $value) {
  44                  $this->container->setParameter($key, $this->phpize($value));
  45              }
  46          }
  47      }
  48  
  49      /**
  50       * {@inheritdoc}
  51       */
  52      public function supports($resource, $type = null)
  53      {
  54          if (!\is_string($resource)) {
  55              return false;
  56          }
  57  
  58          if (null === $type && 'ini' === pathinfo($resource, \PATHINFO_EXTENSION)) {
  59              return true;
  60          }
  61  
  62          return 'ini' === $type;
  63      }
  64  
  65      /**
  66       * Note that the following features are not supported:
  67       *  * strings with escaped quotes are not supported "foo\"bar";
  68       *  * string concatenation ("foo" "bar").
  69       */
  70      private function phpize($value)
  71      {
  72          // trim on the right as comments removal keep whitespaces
  73          if ($value !== $v = rtrim($value)) {
  74              $value = '""' === substr_replace($v, '', 1, -1) ? substr($v, 1, -1) : $v;
  75          }
  76          $lowercaseValue = strtolower($value);
  77  
  78          switch (true) {
  79              case \defined($value):
  80                  return \constant($value);
  81              case 'yes' === $lowercaseValue || 'on' === $lowercaseValue:
  82                  return true;
  83              case 'no' === $lowercaseValue || 'off' === $lowercaseValue || 'none' === $lowercaseValue:
  84                  return false;
  85              case isset($value[1]) && (
  86                  ("'" === $value[0] && "'" === $value[\strlen($value) - 1]) ||
  87                  ('"' === $value[0] && '"' === $value[\strlen($value) - 1])
  88              ):
  89                  // quoted string
  90                  return substr($value, 1, -1);
  91              default:
  92                  return XmlUtils::phpize($value);
  93          }
  94      }
  95  }


Generated: Wed Nov 11 20:28:18 2020 Cross-referenced by PHPXref 0.7.1