CachedConfigLoader   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 46
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A load() 0 11 2
1
<?php
2
/**
3
 * Phossa Project
4
 *
5
 * PHP version 5.4
6
 *
7
 * @category  Library
8
 * @package   Phossa2\Config
9
 * @copyright Copyright (c) 2016 phossa.com
10
 * @license   http://mit-license.org/ MIT License
11
 * @link      http://www.phossa.com/
12
 */
13
/*# declare(strict_types=1); */
14
15
namespace Phossa2\Config\Loader;
16
17
use Phossa2\Shared\Reader\Reader;
18
use Phossa2\Shared\Base\ObjectAbstract;
19
20
/**
21
 * CachedConfigLoader
22
 *
23
 * Load config from one cache file (serialized)
24
 *
25
 * @package Phossa2\Config
26
 * @author  Hong Zhang <[email protected]>
27
 * @version 2.0.8
28
 * @since   2.0.8 added
29
 */
30
class CachedConfigLoader extends ObjectAbstract implements ConfigLoaderInterface
31
{
32
    /**
33
     * the full path of cache file
34
     *
35
     * @var    string
36
     * @access protected
37
     */
38
    protected $cache_file;
39
40
    /**
41
     * loaded flag
42
     *
43
     * @var    bool
44
     * @access protected
45
     */
46
    protected $loaded = false;
47
48
    /**
49
     * Constructor
50
     *
51
     * @param  string $cacheFile
52
     * @throws NotFoundException if cache file not found
53
     * @access public
54
     * @api
55
     */
56
    public function __construct(/*# string */ $cacheFile)
57
    {
58
        $this->cache_file = $cacheFile;
59
    }
60
61
    /**
62
     * {@inheritDoc}
63
     */
64
    public function load(
65
        /*# string */ $group,
66
        /*# string */ $environment = ''
67
    )/*# : array */ {
68
        $data = [];
69
        if (!$this->loaded) {
70
            $this->loaded = true;
71
            $data = (array) Reader::readFile($this->cache_file, 'serialized');
72
        }
73
        return $data;
74
    }
75
}
76