Drupal investigation

IniFileLoader.php 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\DependencyInjection\Loader;
  11. use Symfony\Component\Config\Resource\FileResource;
  12. use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
  13. /**
  14. * IniFileLoader loads parameters from INI files.
  15. *
  16. * @author Fabien Potencier <fabien@symfony.com>
  17. */
  18. class IniFileLoader extends FileLoader
  19. {
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public function load($resource, $type = null)
  24. {
  25. $path = $this->locator->locate($resource);
  26. $this->container->addResource(new FileResource($path));
  27. $result = parse_ini_file($path, true);
  28. if (false === $result || array() === $result) {
  29. throw new InvalidArgumentException(sprintf('The "%s" file is not valid.', $resource));
  30. }
  31. if (isset($result['parameters']) && is_array($result['parameters'])) {
  32. foreach ($result['parameters'] as $key => $value) {
  33. $this->container->setParameter($key, $value);
  34. }
  35. }
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function supports($resource, $type = null)
  41. {
  42. return is_string($resource) && 'ini' === pathinfo($resource, PATHINFO_EXTENSION);
  43. }
  44. }