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+ $ createdFiles = [];
26+ foreach ($ files as $ i => $ file ) {
27+ $ isDir = substr ($ file , -1 , 1 ) == '/ ' ;
28+ if ($ isDir ) {
29+ $ path = $ root . '/ ' . substr ($ file , 0 , -1 );
30+ $ createdFiles [$ file ] = $ path ;
31+ mkdir ($ path , 0755 );
32+ continue ;
33+ }
34+ $ path = $ root . '/ ' . $ file . '.md ' ;
35+ $ createdFiles [$ file ] = $ file . '.md ' ;
36+ file_put_contents ($ path , '' );
37+ chmod ($ path , 0644 );
38+ }
39+ return $ createdFiles ;
40+ }
41+
42+ public function createFileList ($ validatorResults )
43+ {
44+ $ files = [];
45+ foreach ($ validatorResults as $ label => $ complianceResult ) {
46+ if (in_array ($ complianceResult ['state ' ], [
47+ ComplianceValidator::STATE_OPTIONAL_NOT_PRESENT ,
48+ ComplianceValidator::STATE_REQUIRED_NOT_PRESENT ,
49+ ])) {
50+ $ files [$ label ] = $ complianceResult ['expected ' ];
51+ }
52+ }
53+ return $ files ;
54+ }
55+
56+ public function outputResults ($ results )
57+ {
58+ foreach ($ results as $ file ) {
59+ echo "Created {$ file }" . PHP_EOL ;
60+ }
61+ }
62+ }
0 commit comments