1
|
|
|
<?php |
|
|
|
|
2
|
|
|
namespace Classes; |
3
|
|
|
|
4
|
|
|
|
5
|
|
|
use Classes\Maker\AbstractMaker; |
6
|
|
|
|
7
|
|
|
require_once 'Maker/AbstractMaker.php'; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @author Pedro Alarcao <[email protected]> |
11
|
|
|
* @link https://github.com/pedro151/orm-generator |
12
|
|
|
*/ |
13
|
|
|
class MakerConfigFile extends AbstractMaker |
14
|
|
|
{ |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* caminho de pastas Base |
18
|
|
|
* |
19
|
|
|
* @type string |
20
|
|
|
*/ |
21
|
|
|
private $baseLocation = ''; |
22
|
|
|
|
23
|
|
|
private $template = 'Classes/templates/file_configs/ini.php'; |
24
|
|
|
|
25
|
|
|
private $msg = "\033[0mPlease enter the value for %index% \033[1;33m[%config%]:\033[0m "; |
26
|
|
|
|
27
|
|
|
private $configs = array ( |
28
|
|
|
'name-ini' => 'config' , |
29
|
|
|
'framework' => 'none' , |
30
|
|
|
'driver' => 'pgsql' , |
31
|
|
|
'environment' => 'dev' , |
32
|
|
|
'host' => 'localhost' , |
33
|
|
|
'database' => null , |
34
|
|
|
'schema' => null , |
35
|
|
|
'username' => null , |
36
|
|
|
'password' => null |
37
|
|
|
); |
38
|
|
|
|
39
|
|
|
public function __construct ( $argv , $basePath ) |
40
|
|
|
{ |
41
|
|
|
$this->argv = $this->parseConfig ( $basePath , $argv ); |
|
|
|
|
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Analisa e estrutura a Configuracao do generate |
46
|
|
|
* |
47
|
|
|
* @param string $_path |
|
|
|
|
48
|
|
|
* @param array $argv |
49
|
|
|
* |
50
|
|
|
* @return array |
51
|
|
|
* @throws \Exception |
52
|
|
|
*/ |
53
|
|
|
private function parseConfig ( $basePath , $argv ) |
54
|
|
|
{ |
55
|
|
|
$this->baseLocation = $basePath; |
56
|
|
|
|
57
|
|
|
$arrayIO = array_diff_key ( $this->configs , $argv ); |
58
|
|
View Code Duplication |
foreach ( $arrayIO as $index => $config ) |
|
|
|
|
59
|
|
|
{ |
60
|
|
|
$attribs = array ( "%index%" => $index , "%config%" => $config ); |
61
|
|
|
echo strtr ( $this->msg , $attribs ); |
62
|
|
|
$line = trim ( fgets ( STDIN ) ); |
63
|
|
|
if ( ! empty( $line ) ) |
64
|
|
|
{ |
65
|
|
|
$this->configs[ $index ] = strtolower ( $line ); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
$this->configs ['version'] = Config::$version; |
69
|
|
|
return $argv + array_filter ( $this->configs ); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function run () |
73
|
|
|
{ |
74
|
|
|
$path = $this->baseLocation . DIRECTORY_SEPARATOR . "configs"; |
75
|
|
|
self::makeDir ( $path ); |
76
|
|
|
self::makeSourcer ( |
77
|
|
|
$path . DIRECTORY_SEPARATOR . $this->argv[ 'name-ini' ] . '.ini' , |
78
|
|
|
$this->getParsedTplContents ( $this->template , $this->argv ) |
79
|
|
|
); |
80
|
|
|
echo "\n\033[1;32mSuccessfully process finished!\n\033[0m"; |
81
|
|
|
} |
82
|
|
|
} |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.