/
teleport.php
72 lines (59 loc) · 1.95 KB
/
teleport.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
<?php
$start = microtime(true);
if (PHP_SAPI !== 'cli') {
echo 'fatal: teleport should be invoked via the CLI version of PHP; you are using the ' . PHP_SAPI . ' SAPI' . PHP_EOL;
exit(E_USER_ERROR);
}
$debug = (array_search('--debug', $argv, true) !== false);
if ($debug) error_reporting(-1);
if (function_exists('ini_set')) {
@ini_set('display_errors', 1);
$memoryLimit = trim(ini_get('memory_limit'));
if ($memoryLimit != -1) {
$memoryInBytes = function ($value) {
$unit = strtolower(substr($value, -1, 1));
$value = (int)$value;
switch ($unit) {
case 'g':
$value *= 1024;
case 'm':
$value *= 1024;
case 'k':
$value *= 1024;
}
return $value;
};
// Increase memory_limit if it is lower than 512M
if ($memoryInBytes($memoryLimit) < 512 * 1024 * 1024) {
@ini_set('memory_limit', '512M');
}
unset($memoryInBytes);
}
unset($memoryLimit);
}
try {
require_once __DIR__ . '/../src/bootstrap.php';
define('TELEPORT_BASE_PATH', rtrim(getcwd(), '/') . DIRECTORY_SEPARATOR);
$options = array(
'debug' => $debug
);
if (is_readable('config.php')) {
$options = include 'config.php';
}
$teleport = \Teleport\Teleport::instance($options);
$request = $teleport->getRequest();
array_shift($argv);
$request->handle($argv);
$results = implode(PHP_EOL, $request->getResults());
echo trim($results) . PHP_EOL;
if ($debug) {
printf("execution finished with exit code 0 in %2.4f seconds" . PHP_EOL, microtime(true) - $start);
}
exit(0);
} catch (\Exception $e) {
echo $e->getMessage() . PHP_EOL;
if ($debug) {
printf("execution failed with exit code {$e->getCode()} in %2.4f seconds" . PHP_EOL, microtime(true) - $start);
}
exit($e->getCode());
}