1
|
|
|
<?php |
2
|
|
|
namespace Yoanm\DefaultPhpRepository\Processor; |
3
|
|
|
|
4
|
|
|
use Yoanm\DefaultPhpRepository\Model\FolderTemplate; |
5
|
|
|
use Yoanm\DefaultPhpRepository\Model\Template; |
6
|
|
|
use Yoanm\DefaultPhpRepository\Resolver\NamespaceResolver; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class ListCommandProcessor |
10
|
|
|
*/ |
11
|
|
|
class ListCommandProcessor extends CommandProcessor |
12
|
|
|
{ |
13
|
|
|
public function process() |
14
|
|
|
{ |
15
|
|
|
$currentType = null; |
16
|
|
|
foreach ($this->getTemplateList() as $template) { |
17
|
|
|
$this->displayHeader($template, $currentType); |
18
|
|
|
|
19
|
|
|
$currentType = $this->resolveCurrentType($template); |
20
|
|
|
|
21
|
|
|
if ($template instanceof FolderTemplate) { |
22
|
|
|
$this->displayFolderTitle($template); |
23
|
|
|
$this->displayTemplateInfo($template); |
24
|
|
|
} else { |
25
|
|
|
$this->displayFileTitle($template); |
26
|
|
|
$this->displayTemplateInfo($template); |
27
|
|
|
} |
28
|
|
|
} |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param Template $template |
33
|
|
|
*/ |
34
|
|
|
protected function displayTemplateInfo(Template $template) |
35
|
|
|
{ |
36
|
|
|
$this->display(sprintf( |
37
|
|
|
' - %s/%s', |
38
|
|
|
$this->resolveTemplatePath($template), |
39
|
|
|
$template->getSource() |
40
|
|
|
)); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param Template $template |
45
|
|
|
*/ |
46
|
|
|
protected function displayFolderTitle(Template $template) |
47
|
|
|
{ |
48
|
|
|
$this->display( |
49
|
|
|
sprintf('<comment>%s : </comment><info>Folder</info>', $template->getId()), |
50
|
|
|
2, |
51
|
|
|
false |
52
|
|
|
); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param Template $template |
57
|
|
|
*/ |
58
|
|
|
protected function displayFileTitle(Template $template) |
59
|
|
|
{ |
60
|
|
|
$this->display( |
61
|
|
|
sprintf('<comment>%s : </comment><info>File</info>', $template->getId()), |
62
|
|
|
2, |
63
|
|
|
false |
64
|
|
|
); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
protected function resolveTemplatePath(Template $template) |
68
|
|
|
{ |
69
|
|
|
$basePath = 'templates'; |
70
|
|
|
if (NamespaceResolver::SYMFONY_LIBRARY_NAMESPACE === $template->getNamespace()) { |
71
|
|
|
return sprintf('%s/override/library/symfony', $basePath); |
72
|
|
|
} elseif (NamespaceResolver::LIBRARY_NAMESPACE === $template->getNamespace()) { |
73
|
|
|
sprintf('%s/override/library/php', $basePath); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
return sprintf('%s/base', $basePath); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|