|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* © 2018 - Phoponent |
|
5
|
|
|
* Author: Nicolas Choquet |
|
6
|
|
|
* Email: [email protected] |
|
7
|
|
|
* LICENSE GPL ( GNU General Public License ) |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace phoponent\framework\command; |
|
11
|
|
|
|
|
12
|
|
|
use phoponent\framework\static_classe\debug; |
|
13
|
|
|
use phoponent\framework\traits\command; |
|
14
|
|
|
|
|
15
|
|
|
class make { |
|
16
|
|
|
use command; |
|
17
|
|
|
|
|
18
|
|
|
private function create_component($type, $tag) { |
|
19
|
|
|
if(!is_dir("phoponent/app/components/{$type}/{$tag}")) { |
|
20
|
|
|
mkdir("phoponent/app/components/{$type}/{$tag}/models", 0777, true); |
|
21
|
|
|
mkdir("phoponent/app/components/{$type}/{$tag}/views/src", 0777, true); |
|
22
|
|
|
} |
|
23
|
|
|
file_put_contents( |
|
24
|
|
|
"phoponent/app/components/{$type}/{$tag}/{$tag}.php", |
|
25
|
|
|
"<?php |
|
26
|
|
|
namespace phoponent\app\component\\$type; |
|
27
|
|
|
|
|
28
|
|
|
".( $type === 'core' ? "use phoponent\\framework\\classe\\xphp_tag;" : '' )." |
|
29
|
|
|
class {$tag} extends ".($type === 'custom' ? '\phoponent\app\component\core\\'.$tag : 'xphp_tag')." { |
|
30
|
|
|
public function render():string { |
|
31
|
|
|
\$hello_world = \$this->get_model('{$tag}')->get_hello_world(); |
|
32
|
|
|
\$view = \$this->get_view('{$tag}')->set_vars([ |
|
33
|
|
|
'value' => \$hello_world, |
|
34
|
|
|
'class' => __CLASS__, |
|
35
|
|
|
])->render(); |
|
36
|
|
|
return \$view; |
|
37
|
|
|
} |
|
38
|
|
|
}" |
|
39
|
|
|
); |
|
40
|
|
|
|
|
41
|
|
|
file_put_contents( |
|
42
|
|
|
"phoponent/app/components/{$type}/{$tag}/views/{$tag}.view.php", |
|
43
|
|
|
"<?php |
|
44
|
|
|
namespace phoponent\app\component\\$type\\$tag\mvc\\view; |
|
45
|
|
|
|
|
46
|
|
|
use phoponent\\framework\\traits\\view; |
|
47
|
|
|
class {$tag}".($type === 'custom' ? ' extends \phoponent\app\component\\core\\'.$tag.'\\mvc\\view\\'.$tag : '')." { |
|
48
|
|
|
use view; |
|
49
|
|
|
}" |
|
50
|
|
|
); |
|
51
|
|
|
|
|
52
|
|
|
file_put_contents( |
|
53
|
|
|
"phoponent/app/components/{$type}/{$tag}/views/src/{$tag}.view.html", |
|
54
|
|
|
$type === 'core' ? "<div> @class@ </div>" : '@parent@' |
|
55
|
|
|
); |
|
56
|
|
|
|
|
57
|
|
|
file_put_contents( |
|
58
|
|
|
"phoponent/app/components/{$type}/{$tag}/models/{$tag}.php", |
|
59
|
|
|
"<?php |
|
60
|
|
|
namespace phoponent\app\component\\$type\\$tag\mvc\model; |
|
61
|
|
|
|
|
62
|
|
|
use phoponent\\framework\\traits\\model; |
|
63
|
|
|
class {$tag}".($type === 'custom' ? ' extends \phoponent\app\component\core\\'.$tag.'\\mvc\\model\\'.$tag : '')." { |
|
64
|
|
|
use model; |
|
65
|
|
|
|
|
66
|
|
|
public function get_hello_world() { |
|
67
|
|
|
return 'Hello World'; |
|
68
|
|
|
} |
|
69
|
|
|
}" |
|
70
|
|
|
); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function component() { |
|
74
|
|
|
if(($tag = $this->argument('tag')) !== null) { |
|
75
|
|
|
$tag = ucfirst($tag); |
|
76
|
|
|
$type = $this->argument('type') ? $this->argument('type') : 'core'; |
|
77
|
|
|
if($type === 'custom' && !is_dir("phoponent/app/components/core/{$tag}")) { |
|
78
|
|
|
$this->create_component('core', $tag); |
|
79
|
|
|
$this->create_component('custom', $tag); |
|
80
|
|
|
} |
|
81
|
|
|
else { |
|
82
|
|
|
$this->create_component($type, $tag); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function debug() { |
|
88
|
|
|
debug::set_debug(); |
|
89
|
|
|
} |
|
90
|
|
|
} |