Completed
Push — master ( 5ea837...9dec3c )
by Paul
9s
created

PhpFileLoader::load()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 14
rs 9.4285
cc 2
eloc 7
nc 2
nop 2
1
<?php
2
/**
3
 * This file is part of the PPI Framework.
4
 *
5
 * @copyright  Copyright (c) 2012 Paul Dragoonis <[email protected]>
6
 * @license    http://opensource.org/licenses/mit-license.php MIT
7
 *
8
 * @link       http://www.ppi.io
9
 */
10
11
namespace PPI\Framework\Config\Loader;
12
13
use Symfony\Component\Config\Loader\FileLoader;
14
15
/**
16
 * PhpFileLoader loads app configuration from a PHP file.
17
 *
18
 * @author     Vítor Brandão <[email protected]>
19
 */
20
class PhpFileLoader extends FileLoader
21
{
22
    /**
23
     * Loads a PHP file.
24
     *
25
     * @param mixed  $file The resource
26
     * @param string $type The resource type
27
     *
28
     * @throws \InvalidArgumentException
29
     *
30
     * @return array Array with configuration
31
     */
32
    public function load($file, $type = null)
33
    {
34
        $path = $this->locator->locate($file);
35
        $this->setCurrentDir(dirname($path));
36
37
        $config = require $path;
38
39
        // not an array
40
        if (!is_array($config)) {
41
            throw new \InvalidArgumentException(sprintf('The file "%s" must contain a PHP array.', $path));
42
        }
43
44
        return $config;
45
    }
46
47
    /**
48
     * Returns true if this class supports the given resource.
49
     *
50
     * @param mixed  $resource A resource
51
     * @param string $type     The resource type
52
     *
53
     * @return bool true if this class supports the given resource, false otherwise
54
     */
55
    public function supports($resource, $type = null)
56
    {
57
        return is_string($resource) && 'php' === pathinfo($resource, PATHINFO_EXTENSION);
58
    }
59
}
60