This repository was archived by the owner on Jan 5, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModulusCLI.php
More file actions
124 lines (104 loc) · 2.51 KB
/
ModulusCLI.php
File metadata and controls
124 lines (104 loc) · 2.51 KB
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
<?php
namespace Modulus\Console;
use Exception;
use Modulus\Support\Filesystem;
use AtlantisPHP\Console\Application;
use Modulus\Framework\Application as App;
class ModulusCLI
{
/**
* Application root directory
*
* @var string $appdir
*/
public static $appdir;
/**
* Application public directory
*
* @var string $approot
*/
public static $approot;
/**
* Commands location.
*
* @return string
*/
public static function config() : string
{
return __DIR__ . DIRECTORY_SEPARATOR . 'Commands';
}
/**
* Create folder it doesn't exist.
*
* @param string $folder
* @return bool
*/
public static function _dir(string $folder) : bool
{
if (is_dir($folder)) {
return true;
}
mkdir($folder, 0777, true);
return false;
}
/**
* Display an error if something happened
*
* @param Exception $e
*/
public static function fails(Exception $e) : void
{
echo "\033[31mModulusCLI failed to execute command.\033[0m\n";
die($e->getMessage() . "\n");
}
/**
* Boot the modulusPHP CLI
*
* @return object
*/
public static function boot() : object
{
ModulusCLI::$appdir = config('app.dir');
ModulusCLI::$approot = config('app.root');
$app = new Application('Modulus Craftsman', (new ModulusCLI)->getVersion());
$app->load(ModulusCLI::config());
Self::autoload_plugins(true, $app);
return $app;
}
/**
* Get application version from composer file
*
* @return string
*/
public function getVersion()
{
$composerJson = config('app.dir') . 'composer.json';
if (file_exists($composerJson)) {
$composer = json_decode(file_get_contents($composerJson, true));
$version = isset($composer->version) ? $composer->version : '1';
$require = isset($composer->require) ? (array)$composer->require : false;
if (!is_array($require)) return "{$version} (1)";
if (isset($require['modulusphp/framework'])) {
return $version . " ({$require['modulusphp/framework']})";
} else {
return "{$version} (1)";
}
}
return '1';
}
/**
* autoload_plugins
*
* @param bool $isConsole
* @return void
*/
public static function autoload_plugins(bool $isConsole, $craftsman)
{
$plugins = config('app.plugins');
if (env('DEV_AUTOLOAD_PLUGINS') == true) {
foreach($plugins as $plugin => $class) {
$class::console((object)array_merge(App::prototype($isConsole), ['craftsman' => $craftsman]));
}
}
}
}