|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Contains trait ConfigFileTrait. |
|
4
|
|
|
* |
|
5
|
|
|
* PHP version 5.5 |
|
6
|
|
|
* |
|
7
|
|
|
* LICENSE: |
|
8
|
|
|
* This file is part of Yet Another Php Eve Api Library also know as Yapeal |
|
9
|
|
|
* which can be used to access the Eve Online API data and place it into a |
|
10
|
|
|
* database. |
|
11
|
|
|
* Copyright (C) 2016 Michael Cummings |
|
12
|
|
|
* |
|
13
|
|
|
* This program is free software: you can redistribute it and/or modify it |
|
14
|
|
|
* under the terms of the GNU Lesser General Public License as published by the |
|
15
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your |
|
16
|
|
|
* option) any later version. |
|
17
|
|
|
* |
|
18
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT |
|
19
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
20
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License |
|
21
|
|
|
* for more details. |
|
22
|
|
|
* |
|
23
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
|
24
|
|
|
* along with this program. If not, see |
|
25
|
|
|
* <http://www.gnu.org/licenses/>. |
|
26
|
|
|
* |
|
27
|
|
|
* You should be able to find a copy of this license in the LICENSE.md file. A |
|
28
|
|
|
* copy of the GNU GPL should also be available in the GNU-GPL.md file. |
|
29
|
|
|
* |
|
30
|
|
|
* @copyright 2016 Michael Cummings |
|
31
|
|
|
* @license LGPL-3.0+ |
|
32
|
|
|
* @author Michael Cummings <[email protected]> |
|
33
|
|
|
*/ |
|
34
|
|
|
namespace Yapeal\Console\Command; |
|
35
|
|
|
|
|
36
|
|
|
use FilePathNormalizer\FilePathNormalizerInterface; |
|
37
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
38
|
|
|
use Yapeal\Configuration\Wiring; |
|
39
|
|
|
use Yapeal\Container\ContainerInterface; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Trait ConfigFileTrait. |
|
43
|
|
|
* |
|
44
|
|
|
* @method FilePathNormalizerInterface getFpn() |
|
45
|
|
|
* @method $this addOption($name, $shortcut = null, $mode = null, $description = '', $default = null) |
|
46
|
|
|
*/ |
|
47
|
|
|
trait ConfigFileTrait |
|
48
|
|
|
{ |
|
49
|
|
|
/** |
|
50
|
|
|
* |
|
51
|
|
|
*/ |
|
52
|
|
|
protected function addConfigFileOption() |
|
53
|
|
|
{ |
|
54
|
|
|
$mess = 'Configuration file to get settings from.' |
|
55
|
|
|
. ' <comment>NOTE: A (missing, unreadable, empty, etc) file will be silently ignored.</comment>'; |
|
56
|
|
|
$this->addOption('configFile', 'c', InputOption::VALUE_REQUIRED, $mess); |
|
57
|
|
|
} |
|
58
|
|
|
/** |
|
59
|
|
|
* @param string $fileName |
|
60
|
|
|
* @param ContainerInterface $dic |
|
61
|
|
|
* |
|
62
|
|
|
* @throws \DomainException |
|
63
|
|
|
* @throws \Yapeal\Exception\YapealException |
|
64
|
|
|
*/ |
|
65
|
|
|
protected function processConfigFile($fileName, ContainerInterface $dic) |
|
66
|
|
|
{ |
|
67
|
|
|
$fpn = $this->getFpn(); |
|
68
|
|
|
$fileName = $fpn->normalizeFile($fileName, $fpn::ABSOLUTE_ALLOWED | $fpn::VFS_ALLOWED | $fpn::WRAPPER_ALLOWED); |
|
69
|
|
|
if (!is_file($fileName) || !is_readable($fileName)) { |
|
70
|
|
|
return; |
|
71
|
|
|
} |
|
72
|
|
|
$wiring = new Wiring($dic); |
|
73
|
|
|
$settings = $wiring->parserConfigFile($fileName); |
|
74
|
|
|
if (0 !== count($settings)) { |
|
75
|
|
|
foreach ($settings as $key => $setting) { |
|
76
|
|
|
$dic[$key] = $setting; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|