2010-01-04 14:26:20 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2011-01-15 13:29:43 +00:00
|
|
|
* This file is part of the Symfony package.
|
2010-01-04 14:26:20 +00:00
|
|
|
*
|
|
|
|
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
|
|
*
|
2011-01-15 13:29:43 +00:00
|
|
|
* 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
|
|
|
*/
|
|
|
|
|
2011-01-15 13:29:43 +00:00
|
|
|
namespace Symfony\Component\DependencyInjection\Loader;
|
|
|
|
|
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|
|
|
use Symfony\Component\DependencyInjection\Resource\FileResource;
|
|
|
|
|
2010-01-04 14:26:20 +00:00
|
|
|
/**
|
|
|
|
* IniFileLoader loads parameters from INI files.
|
|
|
|
*
|
2010-10-17 12:45:15 +01:00
|
|
|
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
2010-01-04 14:26:20 +00:00
|
|
|
*/
|
|
|
|
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
|
|
|
{
|
2011-02-09 23:44:02 +00:00
|
|
|
$path = $this->locator->locate($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-07-18 10:26:47 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if this class supports the given resource.
|
|
|
|
*
|
|
|
|
* @param mixed $resource A resource
|
|
|
|
*
|
|
|
|
* @return Boolean true if this class supports the given resource, false otherwise
|
|
|
|
*/
|
|
|
|
public function supports($resource)
|
|
|
|
{
|
|
|
|
return is_string($resource) && 'ini' === pathinfo($resource, PATHINFO_EXTENSION);
|
|
|
|
}
|
2010-01-04 14:26:20 +00:00
|
|
|
}
|