This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/DependencyInjection/Loader/IniFileLoader.php

63 lines
1.8 KiB
PHP
Raw Normal View History

2010-01-04 14:26:20 +00:00
<?php
/*
* This file is part of the Symfony package.
2010-01-04 14:26:20 +00:00
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
2010-01-04 14:26:20 +00:00
*/
namespace Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\Resource\FileResource;
2010-01-04 14:26:20 +00:00
/**
* IniFileLoader loads parameters from INI files.
*
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
2010-01-04 14:26:20 +00:00
*/
class IniFileLoader extends FileLoader
{
/**
* Loads a resource.
*
* @param mixed $resource The resource
* @param string $type The resource type
*
* @throws \InvalidArgumentException When ini file is not valid
*/
public function load($file, $type = null)
{
$path = $this->locator->locate($file);
2010-01-04 14:26:20 +00:00
$this->container->addResource(new FileResource($path));
2010-01-04 14:26:20 +00:00
$result = parse_ini_file($path, true);
if (false === $result || array() === $result) {
throw new \InvalidArgumentException(sprintf('The %s file is not valid.', $file));
}
if (isset($result['parameters']) && is_array($result['parameters'])) {
foreach ($result['parameters'] as $key => $value) {
$this->container->setParameter($key, $value);
}
}
}
/**
* Returns true if this class supports the given resource.
*
* @param mixed $resource A resource
* @param string $type The resource type
*
* @return Boolean true if this class supports the given resource, false otherwise
*/
public function supports($resource, $type = null)
{
return is_string($resource) && 'ini' === pathinfo($resource, PATHINFO_EXTENSION);
}
2010-01-04 14:26:20 +00:00
}