|
0
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
/* |
|
|
4 |
* This file is part of the Symfony package. |
|
|
5 |
* |
|
|
6 |
* (c) Fabien Potencier <fabien@symfony.com> |
|
|
7 |
* |
|
|
8 |
* For the full copyright and license information, please view the LICENSE |
|
|
9 |
* file that was distributed with this source code. |
|
|
10 |
*/ |
|
|
11 |
|
|
|
12 |
namespace Symfony\Component\DependencyInjection\Loader; |
|
|
13 |
|
|
|
14 |
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
|
15 |
use Symfony\Component\Config\Resource\FileResource; |
|
|
16 |
|
|
|
17 |
/** |
|
|
18 |
* IniFileLoader loads parameters from INI files. |
|
|
19 |
* |
|
|
20 |
* @author Fabien Potencier <fabien@symfony.com> |
|
|
21 |
*/ |
|
|
22 |
class IniFileLoader extends FileLoader |
|
|
23 |
{ |
|
|
24 |
/** |
|
|
25 |
* Loads a resource. |
|
|
26 |
* |
|
|
27 |
* @param mixed $file The resource |
|
|
28 |
* @param string $type The resource type |
|
|
29 |
* |
|
|
30 |
* @throws \InvalidArgumentException When ini file is not valid |
|
|
31 |
*/ |
|
|
32 |
public function load($file, $type = null) |
|
|
33 |
{ |
|
|
34 |
$path = $this->locator->locate($file); |
|
|
35 |
|
|
|
36 |
$this->container->addResource(new FileResource($path)); |
|
|
37 |
|
|
|
38 |
$result = parse_ini_file($path, true); |
|
|
39 |
if (false === $result || array() === $result) { |
|
|
40 |
throw new \InvalidArgumentException(sprintf('The "%s" file is not valid.', $file)); |
|
|
41 |
} |
|
|
42 |
|
|
|
43 |
if (isset($result['parameters']) && is_array($result['parameters'])) { |
|
|
44 |
foreach ($result['parameters'] as $key => $value) { |
|
|
45 |
$this->container->setParameter($key, $value); |
|
|
46 |
} |
|
|
47 |
} |
|
|
48 |
} |
|
|
49 |
|
|
|
50 |
/** |
|
|
51 |
* Returns true if this class supports the given resource. |
|
|
52 |
* |
|
|
53 |
* @param mixed $resource A resource |
|
|
54 |
* @param string $type The resource type |
|
|
55 |
* |
|
|
56 |
* @return Boolean true if this class supports the given resource, false otherwise |
|
|
57 |
*/ |
|
|
58 |
public function supports($resource, $type = null) |
|
|
59 |
{ |
|
|
60 |
return is_string($resource) && 'ini' === pathinfo($resource, PATHINFO_EXTENSION); |
|
|
61 |
} |
|
|
62 |
} |