Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
31 / 31 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
DynamicRouteCommand | |
100.00% |
31 / 31 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
configure | |
100.00% |
19 / 19 |
|
100.00% |
1 / 1 |
1 | |||
execute | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | /** |
4 | * Console command: Generate dynamic 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 dynamic 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/dynamicroute', |
48 | description: 'Dynamic route generator' |
49 | )] |
50 | class DynamicRouteCommand extends AbstractRouteCommand |
51 | { |
52 | /** |
53 | * Configure the command. |
54 | * |
55 | * @return void |
56 | */ |
57 | protected function configure() |
58 | { |
59 | $this |
60 | ->setHelp('Adds a dynamic route.') |
61 | ->addArgument( |
62 | 'route', |
63 | InputArgument::REQUIRED, |
64 | 'the route name (used by router), e.g. customList' |
65 | )->addArgument( |
66 | 'controller', |
67 | InputArgument::REQUIRED, |
68 | 'the controller name (used in URL), e.g. MyResearch' |
69 | )->addArgument( |
70 | 'action', |
71 | InputArgument::REQUIRED, |
72 | 'the action and segment params, e.g. CustomList/[:id]' |
73 | )->addArgument( |
74 | 'target_module', |
75 | InputArgument::REQUIRED, |
76 | 'the module where the new route will be generated' |
77 | ); |
78 | } |
79 | |
80 | /** |
81 | * Run the command. |
82 | * |
83 | * @param InputInterface $input Input object |
84 | * @param OutputInterface $output Output object |
85 | * |
86 | * @return int 0 for success |
87 | */ |
88 | protected function execute(InputInterface $input, OutputInterface $output) |
89 | { |
90 | $route = $input->getArgument('route'); |
91 | $controller = $input->getArgument('controller'); |
92 | $action = $input->getArgument('action'); |
93 | $module = $input->getArgument('target_module'); |
94 | |
95 | $this->generatorTools->setOutputInterface($output); |
96 | |
97 | // Create backup of configuration |
98 | $configPath = $this->generatorTools->getModuleConfigPath($module); |
99 | $this->generatorTools->backUpFile($configPath); |
100 | |
101 | // Append the route |
102 | $config = include $configPath; |
103 | $this->routeGenerator |
104 | ->addDynamicRoute($config, $route, $controller, $action); |
105 | |
106 | // Write updated configuration |
107 | $this->generatorTools->writeModuleConfig($configPath, $config); |
108 | return 0; |
109 | } |
110 | } |