|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Static Analysis Results Baseliner (sarb). |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Dave Liddament |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and licence information please view the LICENSE file distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
declare(strict_types=1); |
|
12
|
|
|
|
|
13
|
|
|
namespace DaveLiddament\StaticAnalysisResultsBaseliner\Framework\Container; |
|
14
|
|
|
|
|
15
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\HistoryAnalyser\HistoryFactory; |
|
16
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\OutputFormatter\OutputFormatter; |
|
17
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\ResultsParser\ResultsParser; |
|
18
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Framework\Container\internal\AddCommandCompilerPass; |
|
19
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Framework\Container\internal\AddHistoryFactoryCompilerPass; |
|
20
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Framework\Container\internal\AddOutputFormatterFactoryCompilerPass; |
|
21
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Framework\Container\internal\AddStaticAnalysisResultsParserCompilerPass; |
|
22
|
|
|
use Symfony\Component\Config\FileLocator; |
|
23
|
|
|
use Symfony\Component\Console\Application; |
|
24
|
|
|
use Symfony\Component\Console\Command\Command; |
|
25
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
26
|
|
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
|
27
|
|
|
|
|
28
|
|
|
final class Container |
|
29
|
|
|
{ |
|
30
|
|
|
public const COMMAND_TAG = 'console.command'; |
|
31
|
|
|
public const RESULTS_PARSER_TAG = 'resultsParser'; |
|
32
|
|
|
public const HISTORY_FACTORY_TAG = 'historyFactory'; |
|
33
|
|
|
public const OUTPUT_FORMATTER_TAG = 'outputFormatter'; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var ContainerBuilder |
|
37
|
|
|
*/ |
|
38
|
|
|
private $containerBuilder; |
|
39
|
|
|
|
|
40
|
|
|
public function __construct() |
|
41
|
|
|
{ |
|
42
|
|
|
$containerBuilder = new ContainerBuilder(); |
|
43
|
|
|
$loader = new YamlFileLoader($containerBuilder, new FileLocator(__DIR__.'/../../../config/')); |
|
44
|
|
|
$loader->load('services.yml'); |
|
45
|
|
|
|
|
46
|
|
|
$containerBuilder->registerForAutoconfiguration(Command::class)->addTag(self::COMMAND_TAG); |
|
47
|
|
|
$containerBuilder->registerForAutoconfiguration(ResultsParser::class)->addTag(self::RESULTS_PARSER_TAG); |
|
48
|
|
|
$containerBuilder->registerForAutoconfiguration(HistoryFactory::class)->addTag(self::HISTORY_FACTORY_TAG); |
|
49
|
|
|
$containerBuilder->registerForAutoconfiguration(OutputFormatter::class)->addTag(self::OUTPUT_FORMATTER_TAG); |
|
50
|
|
|
$containerBuilder->addCompilerPass(new AddCommandCompilerPass()); |
|
51
|
|
|
$containerBuilder->addCompilerPass(new AddStaticAnalysisResultsParserCompilerPass()); |
|
52
|
|
|
$containerBuilder->addCompilerPass(new AddHistoryFactoryCompilerPass()); |
|
53
|
|
|
$containerBuilder->addCompilerPass(new AddOutputFormatterFactoryCompilerPass()); |
|
54
|
|
|
|
|
55
|
|
|
$containerBuilder->compile(); |
|
56
|
|
|
$this->containerBuilder = $containerBuilder; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function getApplication(): Application |
|
60
|
|
|
{ |
|
61
|
|
|
/** @var Application $application */ |
|
62
|
|
|
$application = $this->containerBuilder->get(Application::class); |
|
63
|
|
|
|
|
64
|
|
|
return $application; |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|