Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
25 / 25 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
RecordRouteCommand | |
100.00% |
25 / 25 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
configure | |
100.00% |
15 / 15 |
|
100.00% |
1 / 1 |
1 | |||
execute | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | /** |
4 | * Console command: Generate record route. |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) Villanova University 2020. |
9 | * |
10 | * This program is free software; you can redistribute it and/or modify |
11 | * it under the terms of the GNU General Public License version 2, |
12 | * as published by the Free Software Foundation. |
13 | * |
14 | * This program is distributed in the hope that it will be useful, |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | * GNU General Public License for more details. |
18 | * |
19 | * You should have received a copy of the GNU General Public License |
20 | * along with this program; if not, write to the Free Software |
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 | * |
23 | * @category VuFind |
24 | * @package Console |
25 | * @author Demian Katz <demian.katz@villanova.edu> |
26 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
27 | * @link https://vufind.org/wiki/development Wiki |
28 | */ |
29 | |
30 | namespace VuFindConsole\Command\Generate; |
31 | |
32 | use Symfony\Component\Console\Attribute\AsCommand; |
33 | use Symfony\Component\Console\Input\InputArgument; |
34 | use Symfony\Component\Console\Input\InputInterface; |
35 | use Symfony\Component\Console\Output\OutputInterface; |
36 | |
37 | /** |
38 | * Console command: Generate record route. |
39 | * |
40 | * @category VuFind |
41 | * @package Console |
42 | * @author Demian Katz <demian.katz@villanova.edu> |
43 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
44 | * @link https://vufind.org/wiki/development Wiki |
45 | */ |
46 | #[AsCommand( |
47 | name: 'generate/recordroute', |
48 | description: 'Record route generator' |
49 | )] |
50 | class RecordRouteCommand extends AbstractRouteCommand |
51 | { |
52 | /** |
53 | * Configure the command. |
54 | * |
55 | * @return void |
56 | */ |
57 | protected function configure() |
58 | { |
59 | $this |
60 | ->setHelp('Adds a record route.') |
61 | ->addArgument( |
62 | 'base', |
63 | InputArgument::REQUIRED, |
64 | 'the base route name (used by router), e.g. record' |
65 | )->addArgument( |
66 | 'controller', |
67 | InputArgument::REQUIRED, |
68 | 'the controller name (used in URL), e.g. MyResearch' |
69 | )->addArgument( |
70 | 'target_module', |
71 | InputArgument::REQUIRED, |
72 | 'the module where the new route will be generated' |
73 | ); |
74 | } |
75 | |
76 | /** |
77 | * Run the command. |
78 | * |
79 | * @param InputInterface $input Input object |
80 | * @param OutputInterface $output Output object |
81 | * |
82 | * @return int 0 for success |
83 | */ |
84 | protected function execute(InputInterface $input, OutputInterface $output) |
85 | { |
86 | $base = $input->getArgument('base'); |
87 | $controller = $input->getArgument('controller'); |
88 | $module = $input->getArgument('target_module'); |
89 | |
90 | $this->generatorTools->setOutputInterface($output); |
91 | |
92 | // Create backup of configuration |
93 | $configPath = $this->generatorTools->getModuleConfigPath($module); |
94 | $this->generatorTools->backUpFile($configPath); |
95 | |
96 | // Append the route |
97 | $config = include $configPath; |
98 | $this->routeGenerator->addRecordRoute($config, $base, $controller); |
99 | |
100 | // Write updated configuration |
101 | $this->generatorTools->writeModuleConfig($configPath, $config); |
102 | return 0; |
103 | } |
104 | } |