@@ -51,6 +51,88 @@ public function install(InstalledRepositoryInterface $repo, PackageInterface $pa
5151 }
5252
5353 //ME Code ----
54- if (file_exists ($ downloadPath .'/Config ' ) && is_read.. .
54+ $ packConfig = $ downloadPath .'/Config ' ;
55+ $ appConfig = $ this ->baseDir .'/.php/Config ' ;
56+
57+ echo "\n\n\tPackConfig: $ packConfig \n\tAppConfig: $ appConfig \n\n" ;
58+
59+ if (file_exists ($ packConfig ) && is_readable ($ packConfig )){
60+ echo "\n\t--- Config exists --- " ;
61+ self ::checkAndOrCreateDir ($ appConfig , true );
62+ self ::copyDirectoryContents ($ packConfig , $ appConfig );
63+ }
64+ }
65+
66+
67+ /**
68+ * Check or create a directory
69+ * @param string $dir path of the directory
70+ * @param boolean $create False/true for create
71+ * @param string $perm indiucates a permission - default 0777
72+ *
73+ * @return bool status of directory (exists/created = false or true)
74+ */
75+ static private function checkAndOrCreateDir ($ dir , $ create = false , $ perm = 0777 )
76+ {
77+ if (is_dir ($ dir ) && is_writable ($ dir )) {
78+ return true ;
79+ } elseif ($ create === false ) {
80+ return false ;
81+ }
82+
83+ @mkdir ($ dir , $ perm , true );
84+ @chmod ($ dir , $ perm );
85+
86+ if (!is_writable ($ dir )) {
87+ return false ;
88+ }
89+
90+ return true ;
91+ }
92+
93+ /**
94+ * Copy entire content of the $dir[ectory]
95+ * @param string $dir Origin
96+ * @param string $target Destination
97+ * @return bool True/false success
98+ */
99+ static private function copyDirectoryContents ($ dir , $ target , $ overwrite = true , $ base = '' )
100+ {
101+ $ dir = rtrim ($ dir , "\\/ " ).'/ ' ;
102+ $ target = rtrim ($ target , "\\/ " ).'/ ' ;
103+ $ report = ['error ' =>[],'copied ' =>[]];
104+
105+ if (!static ::checkAndOrCreateDir ($ target , true , 0777 )) {
106+ $ report ['error ' ]['permission ' ] = $ taget ;
107+ return $ report ;
108+ }
109+
110+ foreach (scandir ($ dir ) as $ file ) {
111+ if ($ file == '. ' || $ file == '.. ' ) {
112+ continue ;
113+ }
114+
115+ if (is_dir ($ dir .$ file )) {
116+ if (!static ::checkAndOrCreateDir ($ target .$ file , true , 0777 )) {
117+ $ report ['error ' ]['permission ' ] = $ taget .$ file ;
118+ return $ report ;
119+ } else {
120+ $ copy = static ::copyDirectoryContents ($ dir .$ file , $ target .$ file , $ overwrite , $ base );
121+ $ report = array_merge_recursive ($ report , $ copy );
122+ }
123+ } elseif (is_file ($ dir .$ file )) {
124+ if ($ overwrite === false && file_exists ($ target .$ file )) {
125+ $ report ['error ' ]['overwrite ' ][] = str_replace ($ base .'/ ' , '' , $ target .$ file );
126+ continue ;
127+ }
128+ if (!copy ($ dir .$ file , $ target .$ file )) {
129+ $ report ['error ' ]['permission ' ] = $ target .$ file ;
130+ return $ report ;
131+ } else {
132+ $ report ['copied ' ][] = str_replace ($ base .'/ ' , '' , $ target .$ file );
133+ }
134+ }
135+ }
136+ return $ report ;
55137 }
56138}
0 commit comments