1 | <?php |
||
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() |
||
74 | |||
75 | /** |
||
76 | * @return string |
||
77 | */ |
||
78 | public function getNamespace() |
||
82 | |||
83 | /** |
||
84 | * @return string |
||
85 | */ |
||
86 | public function getAdapter() |
||
90 | |||
91 | /** |
||
92 | * @return bool |
||
93 | */ |
||
94 | public function isShowLog() |
||
98 | } |
||
99 |