forked from agentejo/cockpit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cp
executable file
·74 lines (54 loc) · 1.64 KB
/
cp
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
#!/usr/bin/env php
<?php
if (PHP_SAPI !== 'cli') {
exit('Script needs to be run from Command Line Interface (cli)');
}
define('COCKPIT_CLI', true);
// set default timezone
date_default_timezone_set('UTC');
include_once(__DIR__.'/bootstrap.php');
$_REQUEST = CLI::opts(); // make option available via $app->param()
$app = cockpit();
$request = new \Lime\Request([
'request' => $_REQUEST,
'server' => $_SERVER,
'site_url' => $app['site_url'],
'base_url' => $app['base_url'],
'base_route' => $app['base_route']
]);
$app->request = $request;
register_shutdown_function(function() use($app){
$app->trigger('shutdown');
});
set_exception_handler(function($exception) use($app) {
$error = [
'message' => $exception->getMessage(),
'file' => $exception->getFile(),
'line' => $exception->getLine(),
];
$app->trigger('error', [$error, $exception]);
if (function_exists('cockpit_error_handler')) {
cockpit_error_handler($error);
}
CLI::writeln('COCKPIT CLI ERROR:', false);
CLI::writeln('-> in '.$error['file'].':'.$error['line']."\n");
CLI::writeln($error['message']."\n");
});
if (isset($argv[1])) {
$cmd = str_replace('../', '', $argv[1]);
$script = $app->path("#config:cli/{$cmd}.php");
if (!$script) {
$script = $app->path("#cli:{$cmd}.php");
}
switch ($cmd) {
case 'test':
CLI::writeln('Yepp!', true);
break;
default:
if ($script) {
include($script);
} else {
CLI::writeln("Error: Command \"{$cmd}\" not found!", false);
}
}
}