1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is a part of Sculpin. |
5
|
|
|
* |
6
|
|
|
* (c) Dragonfly Development Inc. |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Symplify\PHP7_Sculpin\SculpinBundle\Command; |
13
|
|
|
|
14
|
|
|
use Symplify\PHP7_Sculpin\SculpinBundle\HttpServer\HttpServer; |
15
|
|
|
use Symplify\PHP7_Sculpin\Sculpin; |
16
|
|
|
use Symplify\PHP7_Sculpin\Source\CompositeDataSource; |
17
|
|
|
use Symfony\Component\Console\Command\Command; |
18
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
19
|
|
|
use Symfony\Component\Console\Input\InputOption; |
20
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
21
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
22
|
|
|
|
23
|
|
|
final class GenerateCommand extends Command |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
private $outputDirectory; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var Filesystem |
32
|
|
|
*/ |
33
|
|
|
private $filesystem; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var Sculpin |
37
|
|
|
*/ |
38
|
|
|
private $sculpin; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var CompositeDataSource |
42
|
|
|
*/ |
43
|
|
|
private $compositeDataSource; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var HttpServer |
47
|
|
|
*/ |
48
|
|
|
private $httpServer; |
49
|
|
|
|
50
|
|
|
public function __construct( |
51
|
|
|
string $outputDirectory, |
52
|
|
|
Filesystem $filesystem, |
53
|
|
|
Sculpin $sculpin, |
54
|
|
|
CompositeDataSource $compositeDataSource, |
55
|
|
|
HttpServer $httpServer |
56
|
|
|
) { |
57
|
|
|
$this->filesystem = $filesystem; |
58
|
|
|
$this->sculpin = $sculpin; |
59
|
|
|
$this->compositeDataSource = $compositeDataSource; |
60
|
|
|
$this->outputDirectory = $outputDirectory; |
61
|
|
|
$this->httpServer = $httpServer; |
62
|
|
|
|
63
|
|
|
parent::__construct(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* {@inheritdoc} |
68
|
|
|
*/ |
69
|
|
|
protected function configure() |
70
|
|
|
{ |
71
|
|
|
$this->setName('generate'); |
72
|
|
|
$this->setDescription('Generate a site from source.'); |
73
|
|
|
|
74
|
|
|
$this->addOption('server', null, InputOption::VALUE_NONE, 'Start an HTTP server to host your generated site'); |
75
|
|
|
$this->addOption('project-dir', null, InputOption::VALUE_REQUIRED, 'The project directory.', '.'); |
76
|
|
|
|
77
|
|
|
$this->setHelp('The <info>generate</info> command generates a site.'); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* {@inheritdoc} |
82
|
|
|
*/ |
83
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
84
|
|
|
{ |
85
|
|
|
$this->filesystem->remove($this->outputDirectory); |
86
|
|
|
|
87
|
|
|
if ($input->getOption('server')) { |
88
|
|
|
$this->sculpin->run($this->compositeDataSource); |
89
|
|
|
|
90
|
|
|
$this->httpServer->init(); |
91
|
|
|
|
92
|
|
|
$this->httpServer->addPeriodicTimer(1, function () { |
93
|
|
|
clearstatcache(); |
94
|
|
|
|
95
|
|
|
$this->sculpin->resetSources(); |
96
|
|
|
$this->sculpin->run($this->compositeDataSource); |
97
|
|
|
}); |
98
|
|
|
|
99
|
|
|
$this->httpServer->run(); |
100
|
|
|
} else { |
101
|
|
|
$this->sculpin->run($this->compositeDataSource); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|