1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the puli/installer package. |
5
|
|
|
* |
6
|
|
|
* (c) Bernhard Schussek <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Puli\Installer; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Handles and stores errors. |
16
|
|
|
* |
17
|
|
|
* This file was adapted from the installer file bundled with Composer. For the |
18
|
|
|
* original file, authors and copyright information see |
19
|
|
|
* |
20
|
|
|
* https://github.com/composer/getcomposer.org/blob/master/web/installer |
21
|
|
|
* |
22
|
|
|
* @author Nils Adermann <[email protected]> |
23
|
|
|
* @author Jordi Boggiano <[email protected]> |
24
|
|
|
* @author Thomas Rudolph <[email protected]> |
25
|
|
|
* @author Bernhard Schussek <[email protected]> |
26
|
|
|
*/ |
27
|
|
|
final class ErrorHandler |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var string[] |
31
|
|
|
*/ |
32
|
|
|
private static $errors = array(); |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Registers the error handler. |
36
|
|
|
*/ |
37
|
5 |
|
public static function register() |
38
|
|
|
{ |
39
|
5 |
|
self::$errors = array(); |
40
|
|
|
|
41
|
5 |
|
set_error_handler(array(__CLASS__, 'handleError')); |
42
|
5 |
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Unregisters the error handler. |
46
|
|
|
*/ |
47
|
5 |
|
public static function unregister() |
48
|
|
|
{ |
49
|
5 |
|
restore_error_handler(); |
50
|
5 |
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Returns the caught errors. |
54
|
|
|
* |
55
|
|
|
* @return string[] The caught error messages. |
56
|
|
|
*/ |
57
|
|
|
public static function getErrors() |
58
|
|
|
{ |
59
|
|
|
return self::$errors; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Returns whether the handler caught any errors. |
64
|
|
|
* |
65
|
|
|
* @return bool Returns `true` if the handler caught errors and `false` |
66
|
|
|
* otherwise. |
67
|
|
|
*/ |
68
|
5 |
|
public static function hasErrors() |
69
|
|
|
{ |
70
|
5 |
|
return count(self::$errors) > 0; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Handles an error. |
75
|
|
|
* |
76
|
|
|
* @param int $code The error code. |
77
|
|
|
* @param string $message The error message. |
78
|
|
|
*/ |
79
|
|
|
public static function handleError($code, $message) |
80
|
|
|
{ |
81
|
|
|
self::$errors[] = preg_replace('{^copy\(.*?\): }', '', $message); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
private function __construct() |
85
|
|
|
{ |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|