Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
20 / 20 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
StaticRouteCommand | |
100.00% |
20 / 20 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
configure | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
1 | |||
execute | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | /** |
4 | * Console command: Generate static 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 static 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/staticroute', |
48 | description: 'Static route generator' |
49 | )] |
50 | class StaticRouteCommand extends AbstractRouteCommand |
51 | { |
52 | /** |
53 | * Configure the command. |
54 | * |
55 | * @return void |
56 | */ |
57 | protected function configure() |
58 | { |
59 | $this |
60 | ->setHelp('Adds a static route.') |
61 | ->addArgument( |
62 | 'route_definition', |
63 | InputArgument::REQUIRED, |
64 | 'a Controller/Action string, e.g. Search/Home' |
65 | )->addArgument( |
66 | 'target_module', |
67 | InputArgument::REQUIRED, |
68 | 'the module where the new route will be generated' |
69 | ); |
70 | } |
71 | |
72 | /** |
73 | * Run the command. |
74 | * |
75 | * @param InputInterface $input Input object |
76 | * @param OutputInterface $output Output object |
77 | * |
78 | * @return int 0 for success |
79 | */ |
80 | protected function execute(InputInterface $input, OutputInterface $output) |
81 | { |
82 | $route = $input->getArgument('route_definition'); |
83 | $module = $input->getArgument('target_module'); |
84 | |
85 | $this->generatorTools->setOutputInterface($output); |
86 | |
87 | // Create backup of configuration |
88 | $configPath = $this->generatorTools->getModuleConfigPath($module); |
89 | $this->generatorTools->backUpFile($configPath); |
90 | |
91 | // Append the route |
92 | $config = include $configPath; |
93 | $this->routeGenerator->addStaticRoute($config, $route); |
94 | |
95 | // Write updated configuration |
96 | $this->generatorTools->writeModuleConfig($configPath, $config); |
97 | return 0; |
98 | } |
99 | } |