1 | <?php |
||
9 | class Config |
||
10 | { |
||
11 | /** |
||
12 | * @var string[] |
||
13 | */ |
||
14 | protected $paths; |
||
15 | |||
16 | /** |
||
17 | * @var LoggerInterface |
||
18 | */ |
||
19 | protected $logger; |
||
20 | |||
21 | /** |
||
22 | * @var array |
||
23 | */ |
||
24 | protected $config; |
||
25 | |||
26 | /** |
||
27 | * @param string[] $paths |
||
28 | * @param LoggerInterface|null $logger |
||
29 | */ |
||
30 | public function __construct($paths, LoggerInterface $logger = null) |
||
35 | |||
36 | /** |
||
37 | * @return array |
||
38 | */ |
||
39 | public function getAll() |
||
40 | { |
||
41 | if (is_null($this->config)) { |
||
42 | $this->load(); |
||
43 | } |
||
44 | |||
45 | return (array) $this->config; |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * @param string $event |
||
50 | * @param bool $supportedOnly |
||
51 | * |
||
52 | * @return ActionAbstract[] |
||
53 | */ |
||
54 | public function get($event, $supportedOnly = true) |
||
55 | { |
||
56 | if (is_null($this->config)) { |
||
57 | $this->load(); |
||
58 | } |
||
59 | |||
60 | $config = isset($this->config[$event]) |
||
61 | ? array_values($this->config[$event]) : []; |
||
62 | |||
63 | if ($supportedOnly) { |
||
64 | $config = array_filter( |
||
65 | $config, |
||
66 | function (ActionAbstract $action) { |
||
67 | try { |
||
68 | $action->checkSupport(); |
||
69 | |||
70 | return true; |
||
71 | } catch (\Exception $ex) { |
||
72 | $this->logger->warning( |
||
73 | sprintf( |
||
74 | '%s is not supported: %s.', |
||
75 | $action->getName(), |
||
76 | $ex->getMessage() |
||
77 | ) |
||
78 | ); |
||
79 | } |
||
80 | |||
81 | return false; |
||
82 | } |
||
83 | ); |
||
84 | } |
||
85 | |||
86 | return $config; |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * @return LoggerInterface |
||
91 | */ |
||
92 | public function getLog() |
||
96 | |||
97 | /** |
||
98 | * @return self |
||
99 | */ |
||
100 | protected function load() |
||
116 | |||
117 | /** |
||
118 | * @param string $path |
||
119 | */ |
||
120 | private function loadFile($path) |
||
141 | |||
142 | private function initActions() |
||
152 | } |
||
153 |