1+ <?php
2+
3+ namespace PDS \Skeleton ;
4+
5+ use PDS \Skeleton \ComplianceValidator ;
6+
7+ class PackageGenerator
8+ {
9+ public function execute ()
10+ {
11+ $ validator = new ComplianceValidator ();
12+ $ lines = $ validator ->getFiles ();
13+ $ validatorResults = $ validator ->validate ($ lines );
14+ $ files = $ this ->createFiles ($ validatorResults );
15+ $ this ->outputResults ($ files );
16+ return true ;
17+ }
18+
19+ public function createFiles ($ validatorResults , $ root = null )
20+ {
21+ if ($ root == null ) {
22+ $ root = realpath (__DIR__ . "/../../../../../../ " );
23+ }
24+ $ files = $ this ->createFileList ($ validatorResults );
25+ foreach ($ files as $ file ) {
26+ $ isDir = substr ($ file , -1 , 1 ) == '/ ' ;
27+ if ($ isDir ) {
28+ $ path = $ root . '/ ' . substr ($ file , 0 , -1 );
29+ mkdir ($ path , 0755 );
30+ continue ;
31+ }
32+ $ path = $ root . '/ ' . $ file . '.md ' ;
33+ file_put_contents ($ path , '' );
34+ chmod ($ path , 0644 );
35+ }
36+ return $ files ;
37+ }
38+
39+ public function createFileList ($ validatorResults )
40+ {
41+ $ files = [];
42+ foreach ($ validatorResults as $ label => $ complianceResult ) {
43+ if (in_array ($ complianceResult ['state ' ], [
44+ ComplianceValidator::STATE_OPTIONAL_NOT_PRESENT ,
45+ ComplianceValidator::STATE_REQUIRED_NOT_PRESENT ,
46+ ])) {
47+ $ files [$ label ] = $ complianceResult ['expected ' ];
48+ }
49+ }
50+ return $ files ;
51+ }
52+
53+ public function outputResults ($ results )
54+ {
55+ foreach ($ results as $ file ) {
56+ echo "Created {$ file }" . PHP_EOL ;
57+ }
58+ }
59+ }
0 commit comments