-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSwordCommand.php
66 lines (54 loc) · 1.7 KB
/
SwordCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
declare(strict_types=1);
namespace ManaPHP\Commands;
use ManaPHP\AliasInterface;
use ManaPHP\Cli\Command;
use ManaPHP\Di\Attribute\Autowired;
use ManaPHP\Helper\LocalFS;
use ManaPHP\Rendering\Engine\Sword\Compiler;
class SwordCommand extends Command
{
#[Autowired] protected AliasInterface $alias;
#[Autowired] protected Compiler $swordCompiler;
/**
* precompile sword template
*
* @param bool $replace
*
* @return void
*/
public function compileAction(bool $replace = false): void
{
LocalFS::dirDelete('@runtime/sword');
$this->console->writeLn('delete `@runtime/sword` directory success');
$ext = 'sword';
foreach (LocalFS::glob("@app/Views/*.$ext") as $item) {
$this->compile($item, $replace);
}
foreach (LocalFS::glob("@app/Views/*/*.$ext") as $item) {
$this->compile($item, $replace);
}
foreach (LocalFS::glob("@app/Areas/*/Views/*/*.$ext") as $item) {
$this->compile($item, $replace);
}
foreach (LocalFS::glob("@app/Areas/*/Views/*.$ext") as $item) {
$this->compile($item, $replace);
}
}
/**
* @param string $file
* @param bool $replace
*
* @return void
*/
protected function compile(string $file, bool $replace): void
{
if ($replace) {
$compiled = str_replace('.sword', '.phtml', $file);
} else {
$compiled = str_replace($this->alias->get('@root'), $this->alias->resolve('@runtime/sword'), $file);
}
$this->swordCompiler->compileFile($file, $compiled);
$this->console->writeLn("compiled `$compiled` file generated");
}
}