Skip to content

Commit 399e62c

Browse files
committed
New Config
1 parent 85fc703 commit 399e62c

File tree

5 files changed

+122
-22
lines changed

5 files changed

+122
-22
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Config\Html
3+
* Config\Devbr\Html
44
* PHP version 7
55
*
66
* @category Html
@@ -12,7 +12,7 @@
1212
* @link http://paulorocha.tk/devbr
1313
*/
1414

15-
namespace Config\Lib;
15+
namespace Config\Devbr;
1616

1717
/**
1818
* Config\Html Class

Html.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Lib\Html
3+
* Devbr\Html
44
* PHP version 7
55
*
66
* @category Html
@@ -12,10 +12,10 @@
1212
* @link http://paulorocha.tk/devbr
1313
*/
1414

15-
namespace Lib;
15+
namespace Devbr;
1616

1717
/**
18-
* Lib\Html Class
18+
* Devbr\Html Class
1919
*
2020
* @category Html
2121
* @package Library
@@ -72,8 +72,8 @@ function __construct(
7272
foreach ($config as $k => $v) {
7373
$this->{$k} = $v;
7474
}
75-
} elseif (method_exists('Config\Lib\Html', 'getParams')) {
76-
foreach ((new \Config\Lib\Html)->getParams() as $k => $v) {
75+
} elseif (method_exists('Config\Devbr\Html\Html', 'getParams')) {
76+
foreach ((new \Config\Devbr\Html\Html)->getParams() as $k => $v) {
7777
$this->{$k} = $v;
7878
}
7979
}
@@ -677,7 +677,7 @@ private function _var($ret)
677677
return '';
678678
}
679679
//$ret['-content-'] .= $v;
680-
$ret['-content-'] .= '<?php echo Lib\Html::get("'.trim($ret['var']).'")?>';
680+
$ret['-content-'] .= '<?php echo Devbr\Html::get("'.trim($ret['var']).'")?>';
681681

682682
//List type
683683
if (is_array($v)) {

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Composer require devbr/html
1919
## Uso
2020

2121
```
22-
$html = new Lib\Html;
22+
$html = new Devbr\Html;
2323
$html->render('index')->send();
2424
```
2525

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
"php": ">=5.6.28"
2020
},
2121
"autoload": {
22-
"psr-4": {"Lib\\": ""}
22+
"psr-4": {"Devbr\\": ""}
2323
}
2424
}

install.php

Lines changed: 112 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,125 @@
11
<?php
22

3-
if (php_sapi_name() !== 'cli' || !defined('_CONFIG')) {
4-
exit("\n\tI can not run out of system!\n");
3+
if (php_sapi_name() !== 'cli') {
4+
ret('It only runs in CLI mode!');
5+
}
6+
7+
$composer_psr4 = dirname(dirname(__DIR__)).'/composer/autoload_psr4.php';
8+
if (!file_exists($composer_psr4)) {
9+
ret("I can't find Composer data!");
10+
}
11+
12+
$composer = require_once $composer_psr4;
13+
if (!isset($composer['Config\\'][0])) {
14+
ret("I can't find Composer data!");
15+
}
16+
17+
//load composer.json and get the "name" of pack
18+
$namespace = @json_decode(file_get_contents(__DIR__.'/composer.json'))->name;
19+
20+
$namespace = explode('/', $namespace);
21+
22+
$appConfig = $composer['Config\\'][0].'/';
23+
24+
foreach ($namespace as $value) {
25+
$appConfig .= ucfirst($value).'/';
526
}
627

728
$thisConfig = __DIR__.'/Config/';
829

930
if (!is_dir($thisConfig)) {
10-
return;
31+
ret("I can't find 'Config' directory in this pack!");
1132
}
1233

13-
$namespace = @json_decode(file_get_contents(__DIR__.'/composer.json'))->name;
14-
/* OPTIONAL
15-
* load composer.json and get the "name" of pack
16-
* $appConfig = _CONFIG.$namespace;
17-
*/
18-
19-
$appConfig = _CONFIG;
34+
if (is_dir($appConfig)) {
35+
ret("Configuration already exists - ignored.");
36+
}
2037

2138
//Coping all files (and directorys) in /Config
22-
$copy = \Lib\Cli\Main::copyDirectoryContents($thisConfig, $appConfig);
39+
$copy = copyDirectoryContents($thisConfig, $appConfig);
2340

2441
//Return to application installer
25-
return "\n---".($copy === true ? " $namespace instaled!" : $copy);
42+
ret($copy === true ? " $namespace instaled!" : $copy);
43+
44+
// THE END ...
45+
46+
47+
48+
/**
49+
* Check or create a directory
50+
*
51+
* @param string $dir path of the directory
52+
* @param boolean $create False/true for create
53+
* @param string $perm indiucates a permission - default 0777
54+
*
55+
* @return bool status of directory (exists/created = false or true)
56+
*/
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+
}
64+
65+
@mkdir($dir, $perm, true);
66+
@chmod($dir, $perm);
67+
68+
if (is_writable($dir)) {
69+
return true;
70+
}
71+
return false;
72+
}
73+
74+
/**
75+
* Copy entire content of the $dir[ectory]
76+
*
77+
* @param string $dir Origin
78+
* @param string $target Destination
79+
*
80+
* @return bool True/false success
81+
*/
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+
}
90+
91+
foreach (scandir($dir) as $file) {
92+
if ($file == '.' || $file == '..') {
93+
continue;
94+
}
95+
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+
}
104+
}
105+
} elseif (is_file($dir.$file)) {
106+
if (!copy($dir.$file, $target.$file)) {
107+
echo "\n ERROR: can't copy '$target$file'!";
108+
}
109+
}
110+
}
111+
return true;
112+
}
113+
114+
/**
115+
* Return with message
116+
*
117+
* @param string $msg message
118+
*
119+
* @return void print and exit
120+
*/
121+
function ret($msg)
122+
{
123+
echo "\n - $msg";
124+
return true;
125+
}

0 commit comments

Comments
 (0)