Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
26 / 26
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
PluginCommand
100.00% covered (success)
100.00%
26 / 26
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 configure
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
1 / 1
1
 execute
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3/**
4 * Console command: Generate plugin.
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
30namespace VuFindConsole\Command\Generate;
31
32use Symfony\Component\Console\Attribute\AsCommand;
33use Symfony\Component\Console\Input\InputArgument;
34use Symfony\Component\Console\Input\InputInterface;
35use Symfony\Component\Console\Input\InputOption;
36use Symfony\Component\Console\Output\OutputInterface;
37
38/**
39 * Console command: Generate plugin.
40 *
41 * @category VuFind
42 * @package  Console
43 * @author   Demian Katz <demian.katz@villanova.edu>
44 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
45 * @link     https://vufind.org/wiki/development Wiki
46 */
47#[AsCommand(
48    name: 'generate/plugin',
49    description: 'Plugin generator'
50)]
51class PluginCommand extends AbstractContainerAwareCommand
52{
53    /**
54     * Configure the command.
55     *
56     * @return void
57     */
58    protected function configure()
59    {
60        $this
61            ->setHelp('Creates a new plugin class.')
62            ->addArgument(
63                'class_name',
64                InputArgument::REQUIRED,
65                'the name of the class you wish to create'
66            )->addArgument(
67                'factory',
68                InputArgument::OPTIONAL,
69                'an existing factory to use (omit to generate a new one)'
70            )->addOption(
71                'top-level',
72                null,
73                InputOption::VALUE_NONE,
74                'when set, create the plugin as a top-level service instead of'
75                . ' inside a plugin manager'
76            );
77    }
78
79    /**
80     * Run the command.
81     *
82     * @param InputInterface  $input  Input object
83     * @param OutputInterface $output Output object
84     *
85     * @return int 0 for success
86     */
87    protected function execute(InputInterface $input, OutputInterface $output)
88    {
89        $class = $input->getArgument('class_name');
90        $factory = $input->getArgument('factory');
91        $topLevel = $input->getOption('top-level');
92        try {
93            $this->generatorTools->setOutputInterface($output)
94                ->createPlugin($this->container, $class, $factory, $topLevel);
95        } catch (\Exception $e) {
96            $output->writeln($e->getMessage());
97            return 1;
98        }
99        return 0;
100    }
101}