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/Components/DependencyInjection/Loader/IniFileLoader.php

60 lines
1.7 KiB
PHP
Raw Normal View History

2010-01-04 14:26:20 +00:00
<?php
namespace Symfony\Components\DependencyInjection\Loader;
use Symfony\Components\DependencyInjection\ContainerBuilder;
2010-06-27 17:28:29 +01:00
use Symfony\Components\DependencyInjection\Resource\FileResource;
2010-01-04 14:26:20 +00:00
/*
* This file is part of the Symfony framework.
2010-01-04 14:26:20 +00:00
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
/**
* IniFileLoader loads parameters from INI files.
*
* @package Symfony
* @subpackage Components_DependencyInjection
2010-01-04 14:26:20 +00:00
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
class IniFileLoader extends FileLoader
{
/**
* Loads a resource.
*
* @param mixed $resource The resource
* @param ContainerBuilder $container A ContainerBuilder instance to use for the configuration
*
* @return ContainerBuilder A ContainerBuilder instance
*
* @throws \InvalidArgumentException When ini file is not valid
*/
public function load($file, ContainerBuilder $container = null)
{
$path = $this->findFile($file);
2010-01-04 14:26:20 +00:00
if (null === $container) {
$container = new ContainerBuilder();
}
$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) {
$container->setParameter($key, $value);
}
}
return $container;
}
2010-01-04 14:26:20 +00:00
}