|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of Cecil. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Arnaud Ligny <[email protected]> |
|
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
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace Cecil; |
|
15
|
|
|
|
|
16
|
|
|
use Cecil\DependencyInjection\ContainerBuilder; |
|
17
|
|
|
use Symfony\Component\Console\Application as BaseApplication; |
|
18
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* The console application that handles the commands. |
|
22
|
|
|
* |
|
23
|
|
|
* This class extends the Symfony Console Application and integrates |
|
24
|
|
|
* the dependency injection container for service management. |
|
25
|
|
|
*/ |
|
26
|
|
|
class Application extends BaseApplication |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* Banner of the application. |
|
30
|
|
|
* @var string |
|
31
|
|
|
*/ |
|
32
|
|
|
private static $banner = ' ____ _ _ |
|
33
|
|
|
/ ___|___ ___(_) | |
|
34
|
|
|
| | / _ \/ __| | | A simple and powerful content-driven static site generator. |
|
35
|
|
|
| |__| __/ (__| | | |
|
36
|
|
|
\____\___|\___|_|_| by Arnaud Ligny |
|
37
|
|
|
|
|
38
|
|
|
'; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Dependency injection container. |
|
42
|
|
|
* @var ContainerInterface |
|
43
|
|
|
*/ |
|
44
|
|
|
private ContainerInterface $container; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Constructor. |
|
48
|
|
|
*/ |
|
49
|
|
|
public function __construct() |
|
50
|
|
|
{ |
|
51
|
|
|
$this->container = ContainerBuilder::build(); |
|
52
|
|
|
parent::__construct('Cecil', Builder::VERSION); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Gets the dependency injection container. |
|
57
|
|
|
* |
|
58
|
|
|
* @return ContainerInterface |
|
59
|
|
|
*/ |
|
60
|
|
|
public function getContainer(): ContainerInterface |
|
61
|
|
|
{ |
|
62
|
|
|
return $this->container; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* {@inheritdoc} |
|
67
|
|
|
*/ |
|
68
|
|
|
public function getHelp(): string |
|
69
|
|
|
{ |
|
70
|
|
|
return self::$banner . parent::getHelp(); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* {@inheritdoc} |
|
75
|
|
|
*/ |
|
76
|
|
|
protected function getDefaultCommands(): array |
|
77
|
|
|
{ |
|
78
|
|
|
$commands = [ |
|
79
|
|
|
new \Symfony\Component\Console\Command\HelpCommand(), |
|
80
|
|
|
]; |
|
81
|
|
|
|
|
82
|
|
|
// Liste des commandes à charger depuis le container |
|
83
|
|
|
$commandClasses = [ |
|
84
|
|
|
'Cecil\\Command\\About', |
|
85
|
|
|
'Cecil\\Command\\NewSite', |
|
86
|
|
|
'Cecil\\Command\\NewPage', |
|
87
|
|
|
'Cecil\\Command\\Edit', |
|
88
|
|
|
'Cecil\\Command\\Build', |
|
89
|
|
|
'Cecil\\Command\\Serve', |
|
90
|
|
|
'Cecil\\Command\\Clear', |
|
91
|
|
|
'Cecil\\Command\\CacheClear', |
|
92
|
|
|
'Cecil\\Command\\CacheClearAssets', |
|
93
|
|
|
'Cecil\\Command\\CacheClearTemplates', |
|
94
|
|
|
'Cecil\\Command\\CacheClearTranslations', |
|
95
|
|
|
'Cecil\\Command\\ShowContent', |
|
96
|
|
|
'Cecil\\Command\\ShowConfig', |
|
97
|
|
|
'Cecil\\Command\\ListCommand', |
|
98
|
|
|
'Cecil\\Command\\UtilTranslationsExtract', |
|
99
|
|
|
]; |
|
100
|
|
|
|
|
101
|
|
|
foreach ($commandClasses as $commandClass) { |
|
102
|
|
|
try { |
|
103
|
|
|
// Instanciation directe car le container ne charge pas encore les services via resource |
|
104
|
|
|
$class = str_replace('\\\\', '\\', $commandClass); |
|
105
|
|
|
$command = new $class(); |
|
106
|
|
|
if (method_exists($command, 'setContainer')) { |
|
107
|
|
|
$command->setContainer($this->container); |
|
108
|
|
|
} |
|
109
|
|
|
$commands[] = $command; |
|
110
|
|
|
} catch (\Exception $e) { |
|
111
|
|
|
// Ignorer si la commande ne peut pas être instanciée |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
if (Util\Platform::isPhar()) { |
|
116
|
|
|
try { |
|
117
|
|
|
$command = new \Cecil\Command\SelfUpdate(); |
|
118
|
|
|
$command->setContainer($this->container); |
|
119
|
|
|
$commands[] = $command; |
|
120
|
|
|
} catch (\Exception $e) { |
|
|
|
|
|
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
try { |
|
124
|
|
|
$command = new \Cecil\Command\UtilTemplatesExtract(); |
|
125
|
|
|
$command->setContainer($this->container); |
|
126
|
|
|
$commands[] = $command; |
|
127
|
|
|
} catch (\Exception $e) { |
|
|
|
|
|
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
return $commands; |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|