Completed
Push — master ( fda05d...111d7d )
by wen
03:17
created

ConfigFactory::getConfigs()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
namespace Sco\Admin\Config;
4
5
use Illuminate\Config\Repository as ConfigRepository;
6
use Illuminate\Foundation\Application;
7
use Illuminate\Support\Collection;
8
use Sco\Admin\Contracts\ConfigFactoryInterface;
9
10
class ConfigFactory implements ConfigFactoryInterface
11
{
12
    protected $app;
13
    protected $configManagers;
14
    protected $configRepository;
15
16
17
    public function __construct(Application $app)
18
    {
19
        $this->app = $app;
20
        $this->configManagers = new Collection();
21
    }
22
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function make($name)
27
    {
28
        if ($this->configManagers->get($name)) {
29
            return $this->configManagers->get($name);
30
        }
31
32
        $this->configRepository = new ConfigRepository(
33
            $this->app['files']->getRequire($this->getConfigFile($name))
34
        );
35
36
        $this->configManagers->put(
37
            $name,
38
            new ConfigManager($name, $this->app, $this->configRepository)
39
        );
40
        return $this->configManagers->get($name);
41
    }
42
43
    private function getConfigFile($name)
44
    {
45
        return $this->app['path.config']
46
            . DIRECTORY_SEPARATOR . 'admin'
47
            . DIRECTORY_SEPARATOR . $name . '.php';
48
    }
49
50
    public function getConfigRepository()
51
    {
52
        return $this->configRepository;
53
    }
54
}
55