Config::getNamespace()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace T4web\Migrations;
4
5
use T4web\Filesystem\Filesystem;
6
use T4web\Migrations\Exception\RuntimeException;
7
8
class Config
9
{
10
    /**
11
     * @var string
12
     */
13
    private $dir;
14
15
    /**
16
     * @var string
17
     */
18
    private $namespace;
19
20
    /**
21
     * @var string
22
     */
23
    private $adapter;
24
25
    /**
26
     * @var bool
27
     */
28
    private $showLog;
29
30
    public function __construct($appConfig, Filesystem $filesystem)
31
    {
32
        if (!isset($appConfig['migrations'])) {
33
            throw new RuntimeException("Missing migrations configuration");
34
        }
35
36
        $options = $appConfig['migrations'];
37
38
        if (!isset($options['dir'])) {
39
            throw new RuntimeException("`dir` has not be specified in migrations configuration");
40
        }
41
42
        $this->dir = $options['dir'];
43
44
        if (!isset($options['namespace'])) {
45
            throw new RuntimeException("`namespace` has not be specified in migrations configuration");
46
        }
47
48
        $this->namespace = $options['namespace'];
49
50
        if (!$filesystem->isDir($this->dir)) {
51
            $filesystem->mkdir($this->dir, 0775);
52
        } elseif (!$filesystem->isWritable($this->dir)) {
53
            throw new RuntimeException(sprintf('Migrations directory is not writable %s', $this->dir));
54
        }
55
56
        if (!isset($options['adapter'])) {
57
            $options['adapter'] = 'Zend\Db\Adapter\Adapter';
58
        }
59
60
        $this->adapter = $options['adapter'];
61
62
        if (isset($options['show_log'])) {
63
            $this->showLog = $options['show_log'];
64
        }
65
    }
66
67
    /**
68
     * @return string
69
     */
70
    public function getDir()
71
    {
72
        return $this->dir;
73
    }
74
75
    /**
76
     * @return string
77
     */
78
    public function getNamespace()
79
    {
80
        return $this->namespace;
81
    }
82
83
    /**
84
     * @return string
85
     */
86
    public function getAdapter()
87
    {
88
        return $this->adapter;
89
    }
90
91
    /**
92
     * @return bool
93
     */
94
    public function isShowLog()
95
    {
96
        return $this->showLog;
97
    }
98
}
99