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\Input\InputInterface; |
14
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
15
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Command to create a report. |
19
|
|
|
*/ |
20
|
|
|
class ReportCommand extends Command { |
21
|
|
|
/** |
22
|
|
|
* @inheritdoc |
23
|
|
|
*/ |
24
|
|
|
public function configure() { |
25
|
|
|
$this |
26
|
|
|
->setName("report") |
27
|
|
|
->setDescription |
28
|
|
|
("Create a report." |
29
|
|
|
) |
30
|
|
|
->setHelp |
31
|
|
|
("This command will create a named report from the given configs." |
32
|
|
|
) |
33
|
|
|
->addArgument |
34
|
|
|
( "name" |
35
|
|
|
, InputArgument::REQUIRED |
36
|
|
|
, "Give the name of the report you want to create." |
37
|
|
|
) |
38
|
|
|
->addArgument |
39
|
|
|
( "configs" |
40
|
|
|
, InputArgument::IS_ARRAY |
41
|
|
|
, "Give paths to config files, separated by spaces." |
42
|
|
|
); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @inheritdoc |
47
|
|
|
*/ |
48
|
|
|
public function execute(InputInterface $input, OutputInterface $output) { |
49
|
|
|
$config_paths = $input->getArgument("configs"); |
50
|
|
|
if (count($config_paths) == 0) { |
51
|
|
|
$output->writeLn("<error>You need to give the path to at least one config.</error>"); |
52
|
|
|
return; |
53
|
|
|
} |
54
|
|
|
$config = $this->load_config($config_paths); |
55
|
|
|
$dic = $this->build_dic($config); |
56
|
|
|
$this->configure_runtime($config); |
57
|
|
|
|
58
|
|
|
$generator = $dic["report_generator"]; |
59
|
|
|
$name = $input->getArgument("name"); |
60
|
|
|
foreach ($config->reports() as $report) { |
61
|
|
|
if ($report->name() == $name) { |
62
|
|
|
$report = $report->with_target("php://stdout"); |
63
|
|
|
$generator->generate($report); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|