1: <?php
2: /**
3: * This file is part of the Autarky package.
4: *
5: * (c) Andreas Lutro <anlutro@gmail.com>
6: *
7: * For the full copyright and license information, please view the LICENSE
8: * file that was distributed with this source code.
9: */
10:
11: namespace Autarky\Config\Loaders;
12:
13: use Autarky\Config\LoadException;
14: use Autarky\Config\LoaderInterface;
15:
16: /**
17: * PHP file config loader.
18: *
19: * Works with PHP files which declare a file-wide "return" statement which
20: * returns an associative array.
21: */
22: class PhpFileLoader implements LoaderInterface
23: {
24: /**
25: * {@inheritdoc}
26: */
27: public function load($path)
28: {
29: $data = static::requireFile($path);
30:
31: if (!is_array($data)) {
32: throw new LoadException("Config file \"$path\" must return an array");
33: }
34:
35: return $data;
36: }
37:
38: /**
39: * Require a file and return the result.
40: *
41: * Static method to make it impossible to reference $this in the file.
42: *
43: * @param string $_path
44: *
45: * @return mixed
46: */
47: protected static function requireFile($_path)
48: {
49: return require $_path;
50: }
51: }
52: