1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright 2017 Vladimir Jimenez |
5
|
|
|
* @license https://github.com/allejo/stakx/blob/master/LICENSE.md MIT |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace allejo\stakx\Command; |
9
|
|
|
|
10
|
|
|
use allejo\stakx\Configuration; |
11
|
|
|
use allejo\stakx\Service; |
12
|
|
|
use allejo\stakx\System\Filesystem; |
13
|
|
|
use allejo\stakx\Website; |
14
|
|
|
use Symfony\Component\Console\Command\Command; |
15
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
16
|
|
|
use Symfony\Component\Console\Input\InputOption; |
17
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class BuildableCommand. |
21
|
|
|
* |
22
|
|
|
* This abstract class handles configuring the website object |
23
|
|
|
*/ |
24
|
|
|
abstract class BuildableCommand extends Command |
|
|
|
|
25
|
|
|
{ |
26
|
|
|
const NO_CONF = 'no-conf'; |
27
|
|
|
const NO_CLEAN = 'no-clean'; |
28
|
|
|
const USE_DRAFTS = 'use-drafts'; |
29
|
|
|
|
30
|
|
|
/** @var Configuration */ |
31
|
|
|
protected $configuration; |
32
|
|
|
|
33
|
|
|
/** @var Website */ |
34
|
|
|
protected $website; |
35
|
|
|
|
36
|
|
|
/** @var Filesystem */ |
37
|
|
|
protected $fs; |
|
|
|
|
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* {@inheritdoc} |
41
|
|
|
*/ |
42
|
|
|
protected function configure() |
43
|
|
|
{ |
44
|
|
|
$this->fs = new Filesystem(); |
45
|
|
|
|
46
|
|
|
$this->addOption('conf', 'c', InputOption::VALUE_REQUIRED, 'The configuration file to be used', $this->fs->absolutePath(Configuration::DEFAULT_NAME)); |
47
|
|
|
$this->addOption('safe', 's', InputOption::VALUE_NONE, 'Disable file system access from Twig'); |
48
|
|
|
$this->addOption(self::NO_CONF, 'l', InputOption::VALUE_NONE, 'Build a Stakx website without a configuration file'); |
49
|
|
|
$this->addOption(self::NO_CLEAN, 'x', InputOption::VALUE_NONE, "Don't clean the _site before recompiling the website"); |
50
|
|
|
$this->addOption(self::USE_DRAFTS, 'd', InputOption::VALUE_NONE, 'Ignore `output: false` in ContentItems and always write a file'); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* {@inheritdoc} |
55
|
|
|
*/ |
56
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
57
|
|
|
{ |
58
|
|
|
$this->website = new Website($output); |
59
|
|
|
$this->website->setConfLess($input->getOption(self::NO_CONF)); |
60
|
|
|
$this->website->setNoClean($input->getOption(self::NO_CLEAN)); |
61
|
|
|
|
62
|
|
|
$this->setServiceParameter($input, self::NO_CONF); |
63
|
|
|
$this->setServiceParameter($input, self::NO_CLEAN); |
64
|
|
|
$this->setServiceParameter($input, self::USE_DRAFTS); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Configure the website builder. |
69
|
|
|
* |
70
|
|
|
* @param InputInterface $input |
71
|
|
|
*/ |
72
|
|
|
protected function configureBuild(InputInterface $input) |
73
|
|
|
{ |
74
|
|
|
$this->website->setConfiguration($input->getOption('conf')); |
75
|
|
|
$this->website->setSafeMode($input->getOption('safe')); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Set a parameter to the Service singleton |
80
|
|
|
* |
81
|
|
|
* @param InputInterface $input |
82
|
|
|
* @param string $param |
83
|
|
|
*/ |
84
|
|
|
private function setServiceParameter(InputInterface $input, $param) |
85
|
|
|
{ |
86
|
|
|
Service::setParameter($param, $input->getOption($param)); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.