|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of Cecil. |
|
7
|
|
|
* |
|
8
|
|
|
* Copyright (c) Arnaud Ligny <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Cecil\Command; |
|
15
|
|
|
|
|
16
|
|
|
use Cecil\Exception\RuntimeException; |
|
17
|
|
|
use Cecil\Util; |
|
18
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
19
|
|
|
use Symfony\Component\Console\Input\InputDefinition; |
|
20
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
21
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
22
|
|
|
use Symfony\Component\Finder\Finder; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Extract built-in templates. |
|
26
|
|
|
*/ |
|
27
|
|
|
class UtilExtractTemplates extends AbstractCommand |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* {@inheritdoc} |
|
31
|
|
|
*/ |
|
32
|
|
|
protected function configure() |
|
33
|
|
|
{ |
|
34
|
|
|
$this |
|
35
|
|
|
->setName('util:extract') |
|
36
|
|
|
->setDescription('Extracts built-in templates') |
|
37
|
|
|
->setDefinition( |
|
38
|
|
|
new InputDefinition([ |
|
39
|
|
|
new InputArgument('path', InputArgument::OPTIONAL, 'Use the given path as working directory'), |
|
40
|
|
|
]) |
|
41
|
|
|
) |
|
42
|
|
|
->setHelp('Extracts built-in templates in the "layouts" directory.'); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* {@inheritdoc} |
|
47
|
|
|
* |
|
48
|
|
|
* @throws RuntimeException |
|
49
|
|
|
*/ |
|
50
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
51
|
|
|
{ |
|
52
|
|
|
try { |
|
53
|
|
|
$phar = new \Phar(Util\Plateform::getPharPath()); |
|
54
|
|
|
|
|
55
|
|
|
$templates = Finder::create() |
|
56
|
|
|
->files() |
|
57
|
|
|
->in($this->getBuilder()->getConfig()->getInternalLayoutsPath()); |
|
58
|
|
|
foreach ($templates as $template) { |
|
59
|
|
|
$templatesList[] = Util::joinPath($this->getBuilder()->getConfig()->get('layouts.internal.dir'), Util\File::getFS()->makePathRelative($template->getPathname(), $this->getBuilder()->getConfig()->getInternalLayoutsPath())); |
|
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
$phar->extractTo($this->getBuilder()->getConfig()->getLayoutsPath(), $templatesList); |
|
|
|
|
|
|
63
|
|
|
Util\File::getFS()->mirror(Util::joinPath($this->getBuilder()->getConfig()->getLayoutsPath(), $this->getBuilder()->getConfig()->get('layouts.internal.dir')), $this->getBuilder()->getConfig()->getLayoutsPath()); |
|
64
|
|
|
Util\File::getFS()->remove(Util::joinPath($this->getBuilder()->getConfig()->getLayoutsPath(), 'resources')); |
|
65
|
|
|
$output->writeln(\sprintf('<info>Built-in templates extracted to "%s".</info>', $this->getBuilder()->getConfig()->get('layouts.dir'))); |
|
66
|
|
|
} catch (\Exception $e) { |
|
67
|
|
|
throw new RuntimeException(\sprintf($e->getMessage())); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
return 0; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|