|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of byrokrat\giroapp. |
|
4
|
|
|
* |
|
5
|
|
|
* byrokrat\giroapp is free software: you can redistribute it and/or |
|
6
|
|
|
* modify it under the terms of the GNU General Public License as published |
|
7
|
|
|
* by the Free Software Foundation, either version 3 of the License, or |
|
8
|
|
|
* (at your option) any later version. |
|
9
|
|
|
* |
|
10
|
|
|
* byrokrat\giroapp is distributed in the hope that it will be useful, |
|
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13
|
|
|
* GNU General Public License for more details. |
|
14
|
|
|
* |
|
15
|
|
|
* You should have received a copy of the GNU General Public License |
|
16
|
|
|
* along with byrokrat\giroapp. If not, see <http://www.gnu.org/licenses/>. |
|
17
|
|
|
* |
|
18
|
|
|
* Copyright 2016-18 Hannes Forsgård |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
declare(strict_types = 1); |
|
22
|
|
|
|
|
23
|
|
|
namespace byrokrat\giroapp\Plugin; |
|
24
|
|
|
|
|
25
|
|
|
use byrokrat\giroapp\Console\Adapter; |
|
26
|
|
|
use byrokrat\giroapp\Console\CommandInterface; |
|
27
|
|
|
use byrokrat\giroapp\Filter\FilterContainer; |
|
28
|
|
|
use byrokrat\giroapp\Filter\FilterInterface; |
|
29
|
|
|
use byrokrat\giroapp\Formatter\FormatterContainer; |
|
30
|
|
|
use byrokrat\giroapp\Formatter\FormatterInterface; |
|
31
|
|
|
use byrokrat\giroapp\Mapper\SettingsMapper; |
|
32
|
|
|
use byrokrat\giroapp\Xml\XmlFormInterface; |
|
33
|
|
|
use byrokrat\giroapp\Xml\XmlFormTranslator; |
|
34
|
|
|
use Symfony\Component\Console\Application; |
|
35
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
|
36
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
|
37
|
|
|
|
|
38
|
|
|
final class Environment implements EnvironmentInterface |
|
39
|
|
|
{ |
|
40
|
|
|
/** |
|
41
|
|
|
* @var Application |
|
42
|
|
|
*/ |
|
43
|
|
|
private $application; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var EventDispatcherInterface |
|
47
|
|
|
*/ |
|
48
|
|
|
private $dispatcher; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @var FilterContainer |
|
52
|
|
|
*/ |
|
53
|
|
|
private $filterContainer; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @var FormatterContainer |
|
57
|
|
|
*/ |
|
58
|
|
|
private $formatterContainer; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @var SettingsMapper |
|
62
|
|
|
*/ |
|
63
|
|
|
private $settingsMapper; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @var XmlFormTranslator |
|
67
|
|
|
*/ |
|
68
|
|
|
private $xmlFormTranslator; |
|
69
|
|
|
|
|
70
|
|
|
public function __construct( |
|
71
|
|
|
Application $application, |
|
72
|
|
|
EventDispatcherInterface $dispatcher, |
|
73
|
|
|
FilterContainer $filterContainer, |
|
74
|
|
|
FormatterContainer $formatterContainer, |
|
75
|
|
|
SettingsMapper $settingsMapper, |
|
76
|
|
|
XmlFormTranslator $xmlFormTranslator |
|
77
|
|
|
) { |
|
78
|
|
|
$this->application = $application; |
|
79
|
|
|
$this->dispatcher = $dispatcher; |
|
80
|
|
|
$this->filterContainer = $filterContainer; |
|
81
|
|
|
$this->formatterContainer = $formatterContainer; |
|
82
|
|
|
$this->settingsMapper = $settingsMapper; |
|
83
|
|
|
$this->xmlFormTranslator = $xmlFormTranslator; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function readSetting(string $key): string |
|
87
|
|
|
{ |
|
88
|
|
|
return $this->settingsMapper->findByKey($key); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function registerCommand(CommandInterface $command): void |
|
92
|
|
|
{ |
|
93
|
|
|
$this->application->add(new Adapter($command, $this->dispatcher)); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function registerSubscriber(EventSubscriberInterface $subscriber): void |
|
97
|
|
|
{ |
|
98
|
|
|
$this->dispatcher->addSubscriber($subscriber); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
public function registerDonorFilter(FilterInterface $donorFilter): void |
|
102
|
|
|
{ |
|
103
|
|
|
$this->filterContainer->addFilter($donorFilter); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function registerDonorFormatter(FormatterInterface $donorFormatter): void |
|
107
|
|
|
{ |
|
108
|
|
|
$this->formatterContainer->addFormatter($donorFormatter); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
public function registerXmlForm(XmlFormInterface $xmlForm): void |
|
112
|
|
|
{ |
|
113
|
|
|
$this->xmlFormTranslator->addXmlForm($xmlForm); |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|