|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the PHINT package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Jitendra Adhikari <[email protected]> |
|
7
|
|
|
* <https://github.com/adhocore> |
|
8
|
|
|
* |
|
9
|
|
|
* Licensed under MIT license. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Ahc\Phint\Console; |
|
13
|
|
|
|
|
14
|
|
|
class ExportCommand extends BaseCommand |
|
15
|
|
|
{ |
|
16
|
|
|
/** @var string Command name */ |
|
17
|
|
|
protected $_name = 'export'; |
|
18
|
|
|
|
|
19
|
|
|
/** @var string Command description */ |
|
20
|
|
|
protected $_desc = 'Export factory templates so you can customize and use them'; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Configure the command options/arguments. |
|
24
|
|
|
* |
|
25
|
|
|
* @return void |
|
26
|
|
|
*/ |
|
27
|
|
|
protected function onConstruct() |
|
28
|
|
|
{ |
|
29
|
|
|
$this |
|
30
|
|
|
->option('-t --to <directory>', 'Output directory') |
|
31
|
|
|
->option('-o --overwrite', 'Overwrite if target file exists', 'boolval', false) |
|
32
|
|
|
->usage( |
|
33
|
|
|
'<bold> phint export</end> -t . Exports to current dir<eol/>' . |
|
34
|
|
|
'<bold> phint e</end> <comment>--to ~/myphint</end> Exports to ~/myphint dir<eol/>' |
|
35
|
|
|
); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Generate test stubs. |
|
40
|
|
|
* |
|
41
|
|
|
* @return void |
|
42
|
|
|
*/ |
|
43
|
|
|
public function execute() |
|
44
|
|
|
{ |
|
45
|
|
|
$io = $this->app()->io(); |
|
46
|
|
|
$res = __DIR__ . '/../../resources'; |
|
47
|
|
|
$dir = $this->_pathUtil->expand($this->to, $this->_workDir); |
|
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
$this->_pathUtil->ensureDir($dir); |
|
50
|
|
|
|
|
51
|
|
|
$count = 0; |
|
52
|
|
|
$templates = $this->_pathUtil->findFiles([$res], '.twig', true); |
|
53
|
|
|
|
|
54
|
|
|
$io->comment('Exporting ...', true); |
|
55
|
|
|
|
|
56
|
|
|
foreach ($templates as $template) { |
|
57
|
|
|
$target = \str_replace($res, $dir, $template); |
|
58
|
|
|
|
|
59
|
|
|
if (\is_file($target) && !$this->overwrite) { |
|
|
|
|
|
|
60
|
|
|
continue; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
$content = \file_get_contents($template); |
|
64
|
|
|
$count += (int) $this->_pathUtil->writeFile($target, $content); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
$io->cyan("$count template(s) copied to {$this->to}", true); |
|
68
|
|
|
if ($count) { |
|
69
|
|
|
$io->comment('Now you can customize those templates and use like so:', true); |
|
70
|
|
|
$io->bold(' phint init --template ' . $this->_pathUtil->expand($this->to), true); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
$io->ok('Done', true); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|