-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
common.php
96 lines (72 loc) · 1.99 KB
/
common.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
define('LINE_WIDTH', 75);
define('LINE', str_repeat('-', LINE_WIDTH)."\n");
function bailout($message)
{
echo wordwrap($message, LINE_WIDTH)." Aborting.\n";
exit(1);
}
function strip_minor_versions($version)
{
preg_match('/^(?P<version>[0-9]\.[0-9]|[0-9]{2,})/', $version, $matches);
return $matches['version'];
}
function centered($text)
{
$padding = (int) ((LINE_WIDTH - strlen($text)) / 2);
return str_repeat(' ', $padding).$text;
}
function cd($dir)
{
if (false === chdir($dir)) {
bailout("Could not switch to directory $dir.");
}
}
function run($command)
{
exec($command, $output, $status);
if (0 !== $status) {
$output = implode("\n", $output);
echo "Error while running:\n ".getcwd().'$ '.$command."\nOutput:\n".LINE."$output\n".LINE;
bailout("\"$command\" failed.");
}
}
function get_icu_version_from_genrb($genrb)
{
exec($genrb.' --version - 2>&1', $output, $status);
if (0 !== $status) {
bailout($genrb.' failed.');
}
if (!preg_match('/ICU version ([\d\.]+)/', implode('', $output), $matches)) {
return null;
}
return $matches[1];
}
error_reporting(E_ALL);
set_error_handler(function ($type, $msg, $file, $line) {
throw new \ErrorException($msg, 0, $type, $file, $line);
});
set_exception_handler(function (\Throwable $exception) {
echo "\n";
$cause = $exception;
$root = true;
while (null !== $cause) {
if (!$root) {
echo "Caused by\n";
}
echo get_class($cause).': '.$cause->getMessage()."\n";
echo "\n";
echo $cause->getFile().':'.$cause->getLine()."\n";
echo $cause->getTraceAsString()."\n";
$cause = $cause->getPrevious();
$root = false;
}
});