-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrun
112 lines (96 loc) · 2.77 KB
/
run
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
<?php
use Core\Utility;
function my_autoloader($class) {
// explode namespace
$classes = explode('\\', $class);
if(in_array($classes[0], ['Core','Modules']))
{
$classType = $classes[0];
unset($classes[0]);
if($classType == 'Core')
{
$importClass = 'core/src/' . implode('/',$classes);
}
else if($classType == 'Modules')
{
$classes[1] = strtolower($classes[1]);
$classes[2] = strtolower($classes[2]);
$importClass = 'modules/' . implode('/',$classes);
}
if(file_exists($importClass.'.php'))
{
require $importClass.'.php';
}
else
{
die($class . ' is not valid');
}
}
}
spl_autoload_register('my_autoloader');
require Utility::parentPath() . 'core/functions.php';
$protocol = 'http';
$port = '8080';
$address = '127.0.0.1';
$command = "";
// count command line arguments
if(isset($argv[1]))
{
if($argv[1] == 'web')
{
foreach ($argv as $arg) {
$e=explode("=",$arg);
if($e[0] == '--address')
{
$address = $e[1];
}
if($e[0] == '--port')
{
$port = $e[1];
}
}
echo "PHP Boilerplate Started at $protocol://$address:$port\n";
$cmd = "php -S ".$address.":".$port." -t public/";
shell_exec($cmd);
die();
}
$commandFile = null;
if(stringContains($argv[1], ':'))
{
$commandQuery = explode(':', $argv[1])[0];
if(in_array($commandQuery, ['db','publish','schedulers','modules']))
{
$commandFile = str_replace(':','/', $argv[1]);
$commandFile = $commandFile ? Utility::parentPath() . "core/commands/$commandFile.php" : null;
if($commandFile)
{
if(file_exists($commandFile))
{
require $commandFile;
}
else
{
echo "File core/commands/$commandFile.php not found\n";
}
}
}
else
{
// modules command
$commandFile = explode(':', $argv[1])[1];
$commandFile = $commandFile ? Utility::parentPath() . "modules/$commandQuery/commands/$commandFile.php" : null;
if($commandFile)
{
if(file_exists($commandFile))
{
require $commandFile;
}
else
{
echo "File modules/$commandQuery/commands/$commandFile.php not found\n";
}
}
}
die();
}
}