|
1
|
|
|
<?php |
|
2
|
|
|
/****************************************************************************** |
|
3
|
|
|
* An implementation of dicto (scg.unibe.ch/dicto) in and for PHP. |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright (c) 2016 Richard Klees <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* This software is licensed under The MIT License. You should have received |
|
8
|
|
|
* a copy of the license along with the code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Lechimp\Dicto\App; |
|
12
|
|
|
|
|
13
|
|
|
use Symfony\Component\Console\Command\Command as SCommand; |
|
14
|
|
|
use Symfony\Component\Yaml\Yaml; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Base class for Commands. |
|
18
|
|
|
*/ |
|
19
|
|
|
abstract class Command extends SCommand { |
|
20
|
|
|
/** |
|
21
|
|
|
* Configure php runtime. |
|
22
|
|
|
* |
|
23
|
|
|
* @param Config $config |
|
24
|
|
|
* @return null |
|
25
|
|
|
*/ |
|
26
|
|
|
protected function configure_runtime(Config $config) { |
|
27
|
|
|
if ($config->runtime_check_assertions()) { |
|
28
|
|
|
assert_options(ASSERT_ACTIVE, true); |
|
29
|
|
|
assert_options(ASSERT_WARNING, true); |
|
30
|
|
|
assert_options(ASSERT_BAIL, false); |
|
31
|
|
|
} |
|
32
|
|
|
else { |
|
33
|
|
|
assert_options(ASSERT_ACTIVE, false); |
|
34
|
|
|
assert_options(ASSERT_WARNING, false); |
|
35
|
|
|
assert_options(ASSERT_BAIL, false); |
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Load extra configs from yaml files. |
|
41
|
|
|
* |
|
42
|
|
|
* @param array $config_file_paths |
|
43
|
|
|
* @return array |
|
44
|
|
|
*/ |
|
45
|
|
|
protected function load_config(array $config_file_paths) { |
|
46
|
|
|
$configs_array = array(); |
|
47
|
|
|
$config_file_path = null; |
|
48
|
|
|
|
|
49
|
|
|
foreach ($config_file_paths as $config_file) { |
|
50
|
|
|
if (!file_exists($config_file)) { |
|
51
|
|
|
throw new \RuntimeException("Unknown config-file '$config_file'"); |
|
52
|
|
|
} |
|
53
|
|
|
if ($config_file_path === null) { |
|
54
|
|
|
$config_file_path = $config_file; |
|
55
|
|
|
} |
|
56
|
|
|
$configs_array[] = Yaml::parse(file_get_contents($config_file)); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
$t = explode("/", $config_file_path); |
|
60
|
|
|
array_pop($t); |
|
61
|
|
|
$config_file_path = implode("/", $t); |
|
62
|
|
|
|
|
63
|
|
|
return new Config($config_file_path, $configs_array); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Build the dependency injection container. |
|
68
|
|
|
* |
|
69
|
|
|
* @return DIC |
|
70
|
|
|
*/ |
|
71
|
|
|
protected function build_dic(Config $config) { |
|
72
|
|
|
return new DIC($config); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|