|
1
|
|
|
<?php |
|
2
|
|
|
namespace Yoanm\DefaultPhpRepository\Processor; |
|
3
|
|
|
|
|
4
|
|
|
use Symfony\Component\Finder\Finder; |
|
5
|
|
|
use Yoanm\DefaultPhpRepository\Helper\PathHelper; |
|
6
|
|
|
use Yoanm\DefaultPhpRepository\Registry\TemplateRegistry; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class TemplateFolderProcessor |
|
10
|
|
|
*/ |
|
11
|
|
|
class TemplateFolderProcessor extends TemplateFileProcessor |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @param string $templateFolderPath |
|
15
|
|
|
* @param string $templateOutputRootDir |
|
16
|
|
|
*/ |
|
17
|
|
|
public function process($templateFolderPath, $templateOutputRootDir = '.') |
|
18
|
|
|
{ |
|
19
|
|
|
$finder = new Finder(); |
|
20
|
|
|
$finder->files()->in($templateFolderPath); |
|
21
|
|
|
|
|
22
|
|
|
/** @var \SplFileInfo $file */ |
|
23
|
|
|
foreach ($finder as $file) { |
|
24
|
|
|
$templateFilename = $file->getFilename(); |
|
25
|
|
|
$templateFilePath = $file->getRealPath(); |
|
26
|
|
|
$templateOutputFileDir = $this->resolveTemplateOutputDir( |
|
27
|
|
|
$templateFilename, |
|
28
|
|
|
$templateFilePath, |
|
29
|
|
|
$templateOutputRootDir |
|
30
|
|
|
); |
|
31
|
|
|
|
|
32
|
|
|
$templateOutputFilePath = sprintf( |
|
33
|
|
|
'%s%s', |
|
34
|
|
|
PathHelper::appendPathSeparator($templateOutputFileDir), |
|
35
|
|
|
$this->getHelper()->resolveOutputFilename($templateFilename) |
|
36
|
|
|
); |
|
37
|
|
|
|
|
38
|
|
|
$this->getHelper()->dumpTemplate($templateFilePath, $templateOutputFilePath); |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param string $templateFilename |
|
44
|
|
|
* @param string $templateFilePath |
|
45
|
|
|
* @param string $templateOutputRootDir |
|
46
|
|
|
* @return string |
|
47
|
|
|
*/ |
|
48
|
|
|
protected function resolveTemplateOutputDir( |
|
49
|
|
|
$templateFilename, |
|
50
|
|
|
$templateFilePath, |
|
51
|
|
|
$templateOutputRootDir |
|
52
|
|
|
) { |
|
53
|
|
|
$resolved = sprintf( |
|
54
|
|
|
'%s%s', |
|
55
|
|
|
PathHelper::appendPathSeparator($templateOutputRootDir), |
|
56
|
|
|
str_replace([TemplateRegistry::getRootTemplateDir(), $templateFilename], '', $templateFilePath) |
|
57
|
|
|
); |
|
58
|
|
|
|
|
59
|
|
|
return $resolved; |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|