Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
20 / 20 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
ExtendServiceCommand | |
100.00% |
20 / 20 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
configure | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
1 | |||
execute | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * Console command: extend service. |
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: extend service. |
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/extendservice', |
48 | description: 'Service generator' |
49 | )] |
50 | class ExtendServiceCommand extends AbstractCommand |
51 | { |
52 | /** |
53 | * Configure the command. |
54 | * |
55 | * @return void |
56 | */ |
57 | protected function configure() |
58 | { |
59 | $this |
60 | ->setHelp('Override a service with a new child class.') |
61 | ->addArgument( |
62 | 'config_path', |
63 | InputArgument::REQUIRED, |
64 | "the path to the service in the framework config\ne.g." |
65 | . ' controllers/factories/VuFind\\\\Controller\\\\AjaxController' |
66 | )->addArgument( |
67 | 'target_module', |
68 | InputArgument::REQUIRED, |
69 | 'the module where the new class will be generated' |
70 | ); |
71 | } |
72 | |
73 | /** |
74 | * Run the command. |
75 | * |
76 | * @param InputInterface $input Input object |
77 | * @param OutputInterface $output Output object |
78 | * |
79 | * @return int 0 for success |
80 | */ |
81 | protected function execute(InputInterface $input, OutputInterface $output) |
82 | { |
83 | $source = $input->getArgument('config_path'); |
84 | $target = $input->getArgument('target_module'); |
85 | |
86 | try { |
87 | $this->generatorTools->setOutputInterface($output); |
88 | $this->generatorTools->extendService($source, $target); |
89 | } catch (\Exception $e) { |
90 | $output->writeln($e->getMessage()); |
91 | return 1; |
92 | } |
93 | |
94 | return 0; |
95 | } |
96 | } |