Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
AbstractCssBuilderCommand
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
3 / 3
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 configure
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
 getCompiler
n/a
0 / 0
n/a
0 / 0
0
 execute
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * Abstract console command: build CSS with precompiler.
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\Util;
31
32use Symfony\Component\Console\Command\Command;
33use Symfony\Component\Console\Input\InputArgument;
34use Symfony\Component\Console\Input\InputInterface;
35use Symfony\Component\Console\Output\OutputInterface;
36
37/**
38 * Abstract console command: build CSS with precompiler.
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 */
46abstract class AbstractCssBuilderCommand extends Command
47{
48    /**
49     * Cache directory for compiler
50     *
51     * @var string
52     */
53    protected $cacheDir;
54
55    /**
56     * Name of precompiler format
57     *
58     * @var string
59     */
60    protected $format;
61
62    /**
63     * Constructor
64     *
65     * @param string      $cacheDir Cache directory for 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($cacheDir, $name = null)
70    {
71        $this->cacheDir = $cacheDir;
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('Compiles CSS files from ' . $this->format . '.')
84            ->addArgument(
85                'themes',
86                InputArgument::IS_ARRAY | InputArgument::OPTIONAL,
87                'Name of theme(s) to compile; omit to compile everything'
88            );
89    }
90
91    /**
92     * Build the compiler.
93     *
94     * @param OutputInterface $output Output object
95     *
96     * @return \VuFindTheme\AbstractCssPreCompiler
97     */
98    abstract protected function getCompiler(OutputInterface $output);
99
100    /**
101     * Run the command.
102     *
103     * @param InputInterface  $input  Input object
104     * @param OutputInterface $output Output object
105     *
106     * @return int 0 for success
107     */
108    protected function execute(InputInterface $input, OutputInterface $output)
109    {
110        $compiler = $this->getCompiler($output);
111        $compiler->setTempPath($this->cacheDir);
112        $compiler->compile(array_unique($input->getArgument('themes')));
113        return 0;
114    }
115}