Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
29 / 29 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
ThemeCommand | |
100.00% |
29 / 29 |
|
100.00% |
3 / 3 |
6 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
configure | |
100.00% |
17 / 17 |
|
100.00% |
1 / 1 |
1 | |||
execute | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
4 |
1 | <?php |
2 | |
3 | /** |
4 | * Console command: Compile themes. |
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\Compile; |
31 | |
32 | use Symfony\Component\Console\Attribute\AsCommand; |
33 | use Symfony\Component\Console\Command\Command; |
34 | use Symfony\Component\Console\Input\InputArgument; |
35 | use Symfony\Component\Console\Input\InputInterface; |
36 | use Symfony\Component\Console\Input\InputOption; |
37 | use Symfony\Component\Console\Output\OutputInterface; |
38 | use VuFindTheme\ThemeCompiler; |
39 | |
40 | /** |
41 | * Console command: Compile themes. |
42 | * |
43 | * @category VuFind |
44 | * @package Console |
45 | * @author Demian Katz <demian.katz@villanova.edu> |
46 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
47 | * @link https://vufind.org/wiki/development Wiki |
48 | */ |
49 | #[AsCommand( |
50 | name: 'compile/theme', |
51 | description: 'Theme compiler' |
52 | )] |
53 | class ThemeCommand extends Command |
54 | { |
55 | /** |
56 | * Theme compiler |
57 | * |
58 | * @var ThemeCompiler |
59 | */ |
60 | protected $compiler; |
61 | |
62 | /** |
63 | * Constructor |
64 | * |
65 | * @param ThemeCompiler $compiler Theme compiler |
66 | * @param string|null $name The name of the command; passing null means it |
67 | * must be set in configure() |
68 | */ |
69 | public function __construct(ThemeCompiler $compiler, $name = null) |
70 | { |
71 | $this->compiler = $compiler; |
72 | parent::__construct($name); |
73 | } |
74 | |
75 | /** |
76 | * Configure the command. |
77 | * |
78 | * @return void |
79 | */ |
80 | protected function configure() |
81 | { |
82 | $this |
83 | ->setHelp('Flattens a theme hierarchy for improved performance.') |
84 | ->addArgument( |
85 | 'source', |
86 | InputArgument::REQUIRED, |
87 | 'the source theme to compile' |
88 | )->addArgument( |
89 | 'target', |
90 | InputArgument::OPTIONAL, |
91 | 'the target name for the compiled theme ' |
92 | . '(defaults to <source> with _compiled appended)' |
93 | )->addOption( |
94 | 'force', |
95 | 'f', |
96 | InputOption::VALUE_NONE, |
97 | 'If <target> exists, it will only be overwritten when this is set' |
98 | ); |
99 | } |
100 | |
101 | /** |
102 | * Run the command. |
103 | * |
104 | * @param InputInterface $input Input object |
105 | * @param OutputInterface $output Output object |
106 | * |
107 | * @return int 0 for success |
108 | */ |
109 | protected function execute(InputInterface $input, OutputInterface $output) |
110 | { |
111 | $source = $input->getArgument('source'); |
112 | $target = $input->getArgument('target'); |
113 | if (empty($target)) { |
114 | $target = "{$source}_compiled"; |
115 | } |
116 | $force = $input->getOption('force') ? true : false; |
117 | if (!$this->compiler->compile($source, $target, $force)) { |
118 | $output->writeln($this->compiler->getLastError()); |
119 | return 1; |
120 | } |
121 | $output->writeln('Success.'); |
122 | return 0; |
123 | } |
124 | } |