2010-01-04 14:26:20 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Symfony\Components\DependencyInjection\Loader;
|
|
|
|
|
2010-07-15 14:11:33 +01:00
|
|
|
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
|
|
|
|
|
|
|
/*
|
2010-04-07 01:51:29 +01: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.
|
|
|
|
*
|
2010-04-07 01:51:29 +01:00
|
|
|
* @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
|
|
|
|
{
|
2010-05-06 12:25:53 +01:00
|
|
|
/**
|
|
|
|
* Loads a resource.
|
|
|
|
*
|
2010-07-15 14:11:33 +01:00
|
|
|
* @param mixed $resource The resource
|
2010-05-06 12:25:53 +01:00
|
|
|
*
|
|
|
|
* @throws \InvalidArgumentException When ini file is not valid
|
|
|
|
*/
|
2010-07-16 08:12:58 +01:00
|
|
|
public function load($file)
|
2010-01-17 10:15:14 +00:00
|
|
|
{
|
2010-05-06 12:25:53 +01:00
|
|
|
$path = $this->findFile($file);
|
2010-01-04 14:26:20 +00:00
|
|
|
|
2010-07-16 08:12:58 +01:00
|
|
|
$this->container->addResource(new FileResource($path));
|
2010-01-04 14:26:20 +00:00
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
$result = parse_ini_file($path, true);
|
2010-05-07 15:09:11 +01:00
|
|
|
if (false === $result || array() === $result) {
|
2010-05-06 12:25:53 +01:00
|
|
|
throw new \InvalidArgumentException(sprintf('The %s file is not valid.', $file));
|
|
|
|
}
|
|
|
|
|
2010-05-07 15:09:11 +01:00
|
|
|
if (isset($result['parameters']) && is_array($result['parameters'])) {
|
2010-05-08 14:32:30 +01:00
|
|
|
foreach ($result['parameters'] as $key => $value) {
|
2010-07-16 08:12:58 +01:00
|
|
|
$this->container->setParameter($key, $value);
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-01-04 14:26:20 +00:00
|
|
|
}
|