-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathconsole
executable file
·68 lines (61 loc) · 2.1 KB
/
console
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
#!/usr/bin/env php
<?php
ini_set('display_errors', '1');
if (function_exists('pcntl_async_signals')) {
pcntl_async_signals(true);
} else {
declare(ticks=1);
}
require __DIR__ . '/vendor/autoload.php';
// If profiling is requested, set it up now. Profiling can be enabled from the
// command line by providing XHProf location, e.g.
// RECMAN_PROFILE=http://localhost/xhprof ./console ...
if ($profilerBaseUrl = getenv('RECMAN_PROFILE')) {
$profiler = new \RecordManager\Base\Utils\Profiler($profilerBaseUrl);
$profiler->start();
}
// Register a signal handler so that any shutdown functions run if execution is
// interrupted
$signalHandler = function ($signo) {
exit(255);
};
if (function_exists('pcntl_signal')) {
pcntl_signal(SIGINT, $signalHandler);
pcntl_signal(SIGTERM, $signalHandler);
}
// Handle basepath and config overrides ("--config.Section.parameter = value"):
$basepath = null;
$overrides = [];
$remainingArgs = [];
foreach ($_SERVER['argv'] as $parameter) {
if (!str_starts_with($parameter, '--') || !str_contains($parameter, '=')) {
$remainingArgs[] = $parameter;
continue;
}
$parsed = @parse_ini_string(substr($parameter, 2));
if (false === $parsed) {
$remainingArgs[] = $parameter;
continue;
}
if (isset($parsed['basepath'])) {
$basepath = $parsed['basepath'];
} else {
reset($parsed);
$key = key($parsed);
if (preg_match('/^config\.([^.]+)\.(.+)/', $key, $matches)) {
$overrides[$matches[1]][$matches[2]] = $parsed[$key];
} else {
$remainingArgs[] = $parameter;
}
}
}
$_SERVER['argv'] = $remainingArgs;
$_SERVER['argc'] = count($remainingArgs);
define('RECMAN_BASE_PATH', $basepath ?: getenv('RECMAN_BASE_PATH') ?: __DIR__);
$app = Laminas\Mvc\Application::init(require 'conf/application.config.php');
$sm = $app->getServiceManager();
if ($overrides) {
$configReader = $sm->get(\RecordManager\Base\Settings\Ini::class);
$configReader->addOverrides('recordmanager.ini', $overrides);
}
return $sm->get(\RecordManager\Base\ConsoleRunner::class)->run();