-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.php
executable file
·212 lines (183 loc) · 5.8 KB
/
bot.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<?php
// bot.php
require_once 'config.php';
// Define the command-line arguments
$command = isset($argv[1]) ? $argv[1] : '';
$name = isset($argv[2]) ? $argv[2] : '';
// Check if the command is valid
if (!in_array($command, ['make:controller', 'make:model', 'make:middleware', 'make:view', 'make:language'])) {
echo "Invalid command. Usage: php artisan [make:controller|make:model|make:middleware] [name]\n";
exit(1);
}
// Execute the corresponding action
switch ($command) {
case 'make:controller':
makeController($name);
break;
case 'make:model':
makeModel($name);
break;
case 'make:middleware':
makeMiddleware($name);
break;
case 'make:view':
makeView($name);
break;
case 'make:language':
makeLanguage($name);
break;
}
// Function to create a controller
function makeController($name)
{
$basename = basename($name);
$namespace = getNameSpace($name);
$controllerTemplate = "<?php\n\n
namespace app\controllers\\{$namespace};
\n
use app\controllers\BaseController;
\n
class {$basename}Controller extends BaseController {\n\n
/**
* __construct
*
* @return void
*/
public function __construct()
{
parent::__construct();
\$this->executeMiddleware(\$this->requestParam, ['AuthMiddleware','PermissionMiddleware','NotificationMiddleware']);
}
\n\n
}\n";
$filename = APP . 'controllers/' . $name . 'Controller.php';
createFile($filename, $controllerTemplate, "Controller {$name}Controller created successfully.");
}
function makeView($name)
{
$viewTemplate = '
{assign var="title" value=$lang.heading_title}
{include file="backend/layouts/header.tpl"}
{block name="backend_page"}
<!-- Layout wrapper -->
<div class="layout-wrapper layout-content-navbar">
<div class="layout-container">
{* {$menu} *}
{block name="menu"}
{include file="backend/common/menu.tpl"}
{/block}
<!-- Layout container -->
<div class="layout-page">
{block name="nav"}
{include file="backend/layouts/nav.tpl"}
{/block}
<!-- Content wrapper -->
<div class="content-wrapper">
<!-- Content -->
<div class="container-xxl flex-grow-1 container-p-y">
{include file="backend/common/breadcrumb.tpl" route=$smarty.request.dispatch}
</div>
<!-- / Content -->
<!-- Footer -->
{block name="footer_note"}
{include file="backend/layouts/footer_note.tpl"}
{/block}
<!-- / Footer -->
<div class="content-backdrop fade"></div>
</div>
<!-- Content wrapper -->
</div>
<!-- / Layout page -->
</div>
<!-- Overlay -->
<div class="layout-overlay layout-menu-toggle"></div>
</div>
<!-- / Layout wrapper -->
{/block}
{include file="backend/layouts/footer.tpl"}
';
$filename = RESOURCES . $name . '.tpl';
createFile($filename, $viewTemplate, "View {$name} created successfully.");
}
// Function to create a model
function makeModel($name)
{
$basename = basename($name);
$namespace = getNameSpace($name);
$modelTemplate = "<?php\n
namespace app\model\\{$namespace};
\n
use app\model\BaseModel;
\n\n
class {$basename}Model extends BaseModel {\n\n\n\n
/**
* __construct
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
\n\n
}\n";
$filename = APP . 'model/' . $name . 'Model.php';
createFile($filename, $modelTemplate, "Model {$name}Model created successfully.");
}
// Function to create a middleware
function makeMiddleware($name)
{
$basename = basename($name);
$namespace = getNameSpace($name);
$middlewareTemplate = "<?php\n
namespace app\controllers\middleware\\{$namespace};
\n
class {$basename}Middleware {\n\n\n\n
public function handle(\$request) {
return \$request;
}
\n\n
}\n";
$filename = APP . 'controllers/middleware/' . $name . 'Middleware.php';
createFile($filename, $middlewareTemplate, "Middleware {$name}Middleware created successfully.");
}
function makeLanguage($name)
{
$basename = basename($name);
$namespace = getNameSpace($name);
$middlewareTemplate = "<?php\n
\n
return [
'heading_title' => '{$basename}'
];
\n";
$filename = RESOURCES . 'lang/' . $name . '.php';
createFile($filename, $middlewareTemplate, "Langugae {$name} created successfully.");
}
// Function to create a file with content and provide feedback
function createFile($filename, $content, $successMessage)
{
if (file_exists($filename)) {
echo "File already exists.\n";
exit(1);
}
if (!is_dir(dirname($filename))) {
mkdir(dirname($filename), 0755, true);
}
if (file_put_contents($filename, $content) !== false) {
echo "$successMessage\n";
} else {
echo "Error creating file.\n";
exit(1);
}
}
function getNameSpace($input)
{
// Split the string into an array
$parts = explode('/', $input);
// Remove the last element
array_pop($parts);
// Rejoin the array into a string
$output = implode('/', $parts);
return str_replace('/', '\\', $output);
}