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

59 lines
1.4 KiB
PHP
Raw Normal View History

2010-01-04 14:26:20 +00:00
<?php
namespace Symfony\Components\DependencyInjection\Loader;
use Symfony\Components\DependencyInjection\BuilderConfiguration;
/*
* This file is part of the symfony framework.
*
* (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 dependency_injection
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
class IniFileLoader extends FileLoader
{
2010-01-15 13:07:23 +00:00
/**
* Loads a resource.
*
* @param string $file An INI file path
2010-01-15 13:07:23 +00:00
*
* @return BuilderConfiguration A BuilderConfiguration instance
*/
public function load($file)
2010-01-04 14:26:20 +00:00
{
$configuration = new BuilderConfiguration();
$path = $this->getAbsolutePath($file);
if (!file_exists($path))
2010-01-04 14:26:20 +00:00
{
throw new \InvalidArgumentException(sprintf('The %s file does not exist.', $file));
}
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));
}
2010-01-04 14:26:20 +00:00
if (isset($result['parameters']) && is_array($result['parameters']))
{
foreach ($result['parameters'] as $key => $value)
2010-01-04 14:26:20 +00:00
{
$configuration->setParameter(strtolower($key), $value);
2010-01-04 14:26:20 +00:00
}
}
return $configuration;
}
}