1515}
1616
1717//load composer.json and get the "name" of pack
18- $ namespace = @json_decode (file_get_contents (__DIR__ .'/composer.json ' ))->name ;
18+ $ name = @json_decode (file_get_contents (__DIR__ .'/composer.json ' ))->name ;
1919
20- $ namespace = explode ('/ ' , $ namespace );
20+ $ namespace = explode ('/ ' , $ name );
2121
2222$ appConfig = $ composer ['Config \\' ][0 ].'/ ' ;
2323
3939$ copy = copyDirectoryContents ($ thisConfig , $ appConfig );
4040
4141//Return to application installer
42- ret ($ copy === true ? " $ namespace instaled! " : $ copy );
42+ ret ($ copy === true ? " $ name instaled! " : $ copy );
4343
4444// THE END ...
4545
5454 *
5555 * @return bool status of directory (exists/created = false or true)
5656 */
57- function checkAndOrCreateDir ($ dir , $ create = false , $ perm = 0777 )
58- {
59- if (is_dir ($ dir ) && is_writable ($ dir )) {
60- return true ;
61- } elseif ($ create === false ) {
62- return false ;
63- }
6457
65- @mkdir ($ dir , $ perm , true );
66- @chmod ($ dir , $ perm );
58+ if (!function_exists ('checkAndOrCreateDir ' )) {
59+ function checkAndOrCreateDir ($ dir , $ create = false , $ perm = 0777 )
60+ {
61+ if (is_dir ($ dir ) && is_writable ($ dir )) {
62+ return true ;
63+ } elseif ($ create === false ) {
64+ return false ;
65+ }
6766
68- if (is_writable ($ dir )) {
69- return true ;
67+ @mkdir ($ dir , $ perm , true );
68+ @chmod ($ dir , $ perm );
69+
70+ if (is_writable ($ dir )) {
71+ return true ;
72+ }
73+ return false ;
7074 }
71- return false ;
72- }
7375
7476/**
7577 * Copy entire content of the $dir[ectory]
@@ -79,37 +81,37 @@ function checkAndOrCreateDir($dir, $create = false, $perm = 0777)
7981 *
8082 * @return bool True/false success
8183 */
82- function copyDirectoryContents ($ dir , $ target )
83- {
84- $ dir = rtrim ($ dir , "\\/ " ).'/ ' ;
85- $ target = rtrim ($ target , "\\/ " ).'/ ' ;
86-
87- if (!checkAndOrCreateDir ($ target , true , 0777 )) {
88- return "ERROR: can't create directory ' $ taget'! " ;
89- }
84+ function copyDirectoryContents ($ dir , $ target )
85+ {
86+ $ dir = rtrim ($ dir , "\\/ " ).'/ ' ;
87+ $ target = rtrim ($ target , "\\/ " ).'/ ' ;
9088
91- foreach (scandir ($ dir ) as $ file ) {
92- if ($ file == '. ' || $ file == '.. ' ) {
93- continue ;
89+ if (!checkAndOrCreateDir ($ target , true , 0777 )) {
90+ return "ERROR: can't create directory ' $ taget'! " ;
9491 }
9592
96- if (is_dir ($ dir .$ file )) {
97- if (!checkAndOrCreateDir ($ target .$ file , true , 0777 )) {
98- return "ERROR: can't create directory ' $ taget$ file'! " ;
99- } else {
100- $ copy = copyDirectoryContents ($ dir .$ file , $ target .$ file );
101- if ($ copy !== true ) {
102- return $ copy ;
103- }
93+ foreach (scandir ($ dir ) as $ file ) {
94+ if ($ file == '. ' || $ file == '.. ' ) {
95+ continue ;
10496 }
105- } elseif (is_file ($ dir .$ file )) {
106- if (!copy ($ dir .$ file , $ target .$ file )) {
107- echo "\n ERROR: can't copy ' $ target$ file'! " ;
97+
98+ if (is_dir ($ dir .$ file )) {
99+ if (!checkAndOrCreateDir ($ target .$ file , true , 0777 )) {
100+ return "ERROR: can't create directory ' $ taget$ file'! " ;
101+ } else {
102+ $ copy = copyDirectoryContents ($ dir .$ file , $ target .$ file );
103+ if ($ copy !== true ) {
104+ return $ copy ;
105+ }
106+ }
107+ } elseif (is_file ($ dir .$ file )) {
108+ if (!copy ($ dir .$ file , $ target .$ file )) {
109+ echo "\n ERROR: can't copy ' $ target$ file'! " ;
110+ }
108111 }
109112 }
113+ return true ;
110114 }
111- return true ;
112- }
113115
114116/**
115117 * Return with message
@@ -118,8 +120,9 @@ function copyDirectoryContents($dir, $target)
118120 *
119121 * @return void print and exit
120122 */
121- function ret ($ msg )
122- {
123- echo "\n - $ msg " ;
124- return true ;
123+ function ret ($ msg )
124+ {
125+ echo "\n - $ msg " ;
126+ return true ;
127+ }
125128}
0 commit comments