-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8814f47
commit 88843c8
Showing
7 changed files
with
128 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?php | ||
\Devbr\Router::this()->respond('get', 'about', function () { | ||
echo '<h1>About</h1><p>Welcome</p>'; | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,6 @@ | |
"php": ">=5.6.28" | ||
}, | ||
"autoload": { | ||
"psr-4": {"Lib\\": ""} | ||
"psr-4": {"Devbr\\": ""} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,119 @@ | ||
<?php | ||
|
||
if (php_sapi_name() !== 'cli' || !defined('_CONFIG')) { | ||
exit("\n\tI can not run out of system!\n"); | ||
if (php_sapi_name() !== 'cli') { | ||
ret('It only runs in CLI mode!'); | ||
} | ||
|
||
$composer_psr4 = dirname(dirname(__DIR__)).'/composer/autoload_psr4.php'; | ||
if (!file_exists($composer_psr4)) { | ||
ret("I can't find Composer data!"); | ||
} | ||
|
||
$composer = require_once $composer_psr4; | ||
if (!isset($composer['Config\\'][0])) { | ||
ret("I can't find Composer data!"); | ||
} | ||
|
||
//load composer.json and get the "name" of pack | ||
$namespace = @json_decode(file_get_contents(__DIR__.'/composer.json'))->name; | ||
$appConfig = $composer['Config\\'][0].'/'.$namespace.'/'; | ||
|
||
$thisConfig = __DIR__.'/Config/'; | ||
//exit("\n\n\---> $appConfig\n"); | ||
|
||
if (!is_dir($thisConfig)) { | ||
return; | ||
ret("I can't find 'Config' directory in this pack!"); | ||
} | ||
|
||
$namespace = @json_decode(file_get_contents(__DIR__.'/composer.json'))->name; | ||
/* OPTIONAL | ||
* load composer.json and get the "name" of pack | ||
* $appConfig = _CONFIG.$namespace; | ||
*/ | ||
|
||
$appConfig = _CONFIG; | ||
if (is_dir($appConfig)) { | ||
ret("Configuration already exists - ignored."); | ||
} | ||
|
||
//Coping all files (and directorys) in /Config | ||
$copy = \Lib\Cli\Main::copyDirectoryContents($thisConfig, $appConfig); | ||
$copy = copyDirectoryContents($thisConfig, $appConfig); | ||
|
||
//Return to application installer | ||
return "\n---".($copy === true ? " $namespace instaled!" : $copy); | ||
ret($copy === true ? " $namespace instaled!" : $copy); | ||
|
||
// THE END ... | ||
|
||
|
||
|
||
/** | ||
* Check or create a directory | ||
* | ||
* @param string $dir path of the directory | ||
* @param boolean $create False/true for create | ||
* @param string $perm indiucates a permission - default 0777 | ||
* | ||
* @return bool status of directory (exists/created = false or true) | ||
*/ | ||
function checkAndOrCreateDir($dir, $create = false, $perm = 0777) | ||
{ | ||
if (is_dir($dir) && is_writable($dir)) { | ||
return true; | ||
} elseif ($create === false) { | ||
return false; | ||
} | ||
|
||
@mkdir($dir, $perm, true); | ||
@chmod($dir, $perm); | ||
|
||
if (is_writable($dir)) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Copy entire content of the $dir[ectory] | ||
* | ||
* @param string $dir Origin | ||
* @param string $target Destination | ||
* | ||
* @return bool True/false success | ||
*/ | ||
function copyDirectoryContents($dir, $target) | ||
{ | ||
$dir = rtrim($dir, "\\/ ").'/'; | ||
$target = rtrim($target, "\\/ ").'/'; | ||
|
||
if (!checkAndOrCreateDir($target, true, 0777)) { | ||
return "ERROR: can't create directory '$taget'!"; | ||
} | ||
|
||
foreach (scandir($dir) as $file) { | ||
if ($file == '.' || $file == '..') { | ||
continue; | ||
} | ||
|
||
if (is_dir($dir.$file)) { | ||
if (!checkAndOrCreateDir($target.$file, true, 0777)) { | ||
return "ERROR: can't create directory '$taget$file'!"; | ||
} else { | ||
$copy = copyDirectoryContents($dir.$file, $target.$file); | ||
if ($copy !== true) { | ||
return $copy; | ||
} | ||
} | ||
} elseif (is_file($dir.$file)) { | ||
if (!copy($dir.$file, $target.$file)) { | ||
echo "\n ERROR: can't copy '$target$file'!"; | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
/** | ||
* Return with message | ||
* | ||
* @param string $msg message | ||
* | ||
* @return void print and exit | ||
*/ | ||
function ret($msg) | ||
{ | ||
echo "\n - $msg\n\n"; | ||
return true; | ||
} |