2010-01-04 14:26:20 +00:00
|
|
|
<?php
|
|
|
|
|
2010-08-20 22:09:55 +01:00
|
|
|
namespace Symfony\Component\DependencyInjection\Loader;
|
2010-01-04 14:26:20 +00:00
|
|
|
|
2010-08-20 22:09:55 +01:00
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|
|
|
use Symfony\Component\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-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
|
|
|
{
|
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-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
|
|
|
}
|