1 | <?php |
||
13 | class TemplateListFactory |
||
14 | { |
||
15 | /** |
||
16 | * @param string $repositoryType |
||
17 | * |
||
18 | * @return Template[] |
||
19 | */ |
||
20 | public function create($repositoryType) |
||
21 | { |
||
22 | $fileTemplateList = [ |
||
23 | 'git.readme' => 'README.md.twig', |
||
24 | 'git.license' => 'LICENSE.twig', |
||
25 | 'git.contributing' => 'CONTRIBUTING.md.twig', |
||
26 | 'git.gitignore' => '.gitignore.twig', |
||
27 | 'composer.config' => 'composer.json.twig', |
||
28 | 'phpcs.config' => 'phpcs.xml.dist.twig', |
||
29 | 'phpunit.config' => 'phpunit.xml.dist.twig', |
||
30 | 'behat.config' => 'behat.yml.twig', |
||
31 | 'ci.scrutinizer' => '.scrutinizer.yml.twig', |
||
32 | ]; |
||
33 | |||
34 | if (RepositoryType::LIBRARY === $repositoryType) { |
||
35 | $fileTemplateList['ci.travis'] = '.travis.yml.twig'; |
||
36 | } |
||
37 | |||
38 | $list = []; |
||
39 | foreach ($fileTemplateList as $templateId => $templateName) { |
||
40 | $list[$templateId] = $this->createTemplate($templateId, $templateName); |
||
41 | } |
||
42 | |||
43 | $folderTemplateList = [ |
||
44 | 'phpunit.folders' => 'tests', |
||
45 | 'behat.folders' => 'features', |
||
46 | ]; |
||
47 | |||
48 | $basePath = TemplateHelper::getTemplateBasePath(); |
||
49 | foreach ($folderTemplateList as $templateId => $templateFolder) { |
||
50 | $folderTemplate = $list[$templateId] = new FolderTemplate($templateId, $templateFolder); |
||
51 | // Iterate over files |
||
52 | $count = 0; |
||
53 | $path = realpath(sprintf('%s/base/%s', $basePath, $templateFolder)); |
||
54 | $toRemove = sprintf('%s/base/', $basePath); |
||
55 | foreach ((new Finder())->files()->in($path) as $file) { |
||
56 | $folderTemplate->addFile( |
||
57 | $this->createTemplate( |
||
58 | sprintf('%s.%s', $templateId, $count), |
||
59 | str_replace($toRemove, '', $file->getPathname()) |
||
60 | ) |
||
61 | ); |
||
62 | $count++; |
||
63 | } |
||
64 | } |
||
65 | |||
66 | // Reorder final list |
||
67 | $orderedList = [ |
||
68 | 'git.readme', |
||
69 | 'git.license', |
||
70 | 'git.contributing', |
||
71 | 'git.gitignore', |
||
72 | 'composer.config', |
||
73 | 'phpcs.config', |
||
74 | 'phpunit.config', |
||
75 | 'phpunit.folders', |
||
76 | 'behat.config', |
||
77 | 'behat.folders', |
||
78 | 'ci.scrutinizer', |
||
79 | 'ci.travis', |
||
80 | ]; |
||
81 | |||
82 | $finalList = []; |
||
83 | foreach ($orderedList as $key) { |
||
84 | if (isset($list[$key])) { |
||
85 | $finalList[$key] = $list[$key]; |
||
86 | } |
||
87 | } |
||
88 | |||
89 | return $finalList; |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * @param string $id |
||
94 | * @param string $templateName |
||
95 | * |
||
96 | * @return Template |
||
97 | */ |
||
98 | protected function createTemplate($id, $templateName) |
||
102 | |||
103 | |||
104 | /** |
||
105 | * @param string $templateName |
||
106 | * |
||
107 | * @return string |
||
108 | */ |
||
109 | protected function getOutputFilePath($templateName) |
||
113 | } |
||
114 |