forked from SugiPHP/Config
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIniLoader.php
More file actions
46 lines (38 loc) · 1.12 KB
/
IniLoader.php
File metadata and controls
46 lines (38 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
/**
* @package SugiPHP
* @subpackage Config
* @author Plamen Popov <tzappa@gmail.com>
* @license http://opensource.org/licenses/mit-license.php (MIT License)
*/
namespace SugiPHP\Config;
class IniLoader implements LoaderInterface
{
protected $locator;
public function __construct(LocatorInterface $locator = null)
{
$this->locator = $locator;
}
public function load($resource)
{
// check the extension. If it's not provided we'll add .ini
if (pathinfo($resource, PATHINFO_EXTENSION) === "") {
$resource .= ".ini";
}
$file = false;
if ($this->locator) {
// pass it to the locator (if set) and than include the file
$file = $this->locator->locate($resource);
} elseif (is_file($resource) && is_readable($resource)) {
// check if the $resource is a real file and include it
$file = $resource;
}
if ($file) {
// By setting the process_sections parameter (second param) to TRUE, you get a
// multidimensional array, with the section names and settings included.
// The default for process_sections is FALSE
return parse_ini_file($file, true);
}
return null;
}
}