1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Bright Answer ZendSentry |
5
|
|
|
* |
6
|
|
|
* This source file is part of the Bright Answer ZendSentry package |
7
|
|
|
* |
8
|
|
|
* @package ZendSentry\ZendSentry |
9
|
|
|
* @license MIT License {@link /docs/LICENSE} |
10
|
|
|
* @copyright Copyright (c) 2018, Bright Answer OÜ |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace ZendSentry; |
14
|
|
|
|
15
|
|
|
use Raven_Client as RavenClient; |
16
|
|
|
use Raven_ErrorHandler as RavenErrorHandler; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @package ZendSentry\ZendSentry |
20
|
|
|
*/ |
21
|
|
|
class ZendSentry |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var string $nonce |
25
|
|
|
*/ |
26
|
|
|
private static $nonce; |
27
|
|
|
/** |
28
|
|
|
* @var RavenClient $ravenClient |
29
|
|
|
*/ |
30
|
|
|
private $ravenClient; |
31
|
|
|
/** |
32
|
|
|
* @var RavenErrorHandler $ravenErrorHandler |
33
|
|
|
*/ |
34
|
|
|
private $ravenErrorHandler; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param RavenClient $ravenClient |
38
|
|
|
* @param RavenErrorHandler $ravenErrorHandler |
39
|
|
|
*/ |
40
|
|
|
public function __construct(RavenClient $ravenClient, RavenErrorHandler $ravenErrorHandler = null) |
41
|
|
|
{ |
42
|
|
|
$this->ravenClient = $ravenClient; |
43
|
|
|
$this->setOrLoadRavenErrorHandler($ravenErrorHandler); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param null|RavenErrorHandler $ravenErrorHandler |
48
|
|
|
*/ |
49
|
|
|
private function setOrLoadRavenErrorHandler($ravenErrorHandler) |
50
|
|
|
{ |
51
|
|
|
if ($ravenErrorHandler !== null) { |
52
|
|
|
$this->ravenErrorHandler = $ravenErrorHandler; |
53
|
|
|
} else { |
54
|
|
|
$this->ravenErrorHandler = new RavenErrorHandler($this->ravenClient); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param string $nonce |
60
|
|
|
*/ |
61
|
|
|
public static function setCSPNonce(string $nonce) |
62
|
|
|
{ |
63
|
|
|
self::$nonce = $nonce; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param bool $callExistingHandler |
68
|
|
|
* @param int $errorReporting |
69
|
|
|
* |
70
|
|
|
* @return ZendSentry |
71
|
|
|
*/ |
72
|
|
|
public function registerErrorHandler($callExistingHandler = true, $errorReporting = E_ALL): ZendSentry |
73
|
|
|
{ |
74
|
|
|
$this->ravenErrorHandler->registerErrorHandler($callExistingHandler, $errorReporting); |
|
|
|
|
75
|
|
|
return $this; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param bool $callExistingHandler |
80
|
|
|
* |
81
|
|
|
* @return ZendSentry |
82
|
|
|
*/ |
83
|
|
|
public function registerExceptionHandler($callExistingHandler = true): ZendSentry |
84
|
|
|
{ |
85
|
|
|
$this->ravenErrorHandler->registerExceptionHandler($callExistingHandler); |
86
|
|
|
return $this; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @param int $reservedMemorySize |
91
|
|
|
* |
92
|
|
|
* @return ZendSentry |
93
|
|
|
*/ |
94
|
|
|
public function registerShutdownFunction($reservedMemorySize = 10): ZendSentry |
95
|
|
|
{ |
96
|
|
|
$this->ravenErrorHandler->registerShutdownFunction($reservedMemorySize); |
97
|
|
|
return $this; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return null|string |
102
|
|
|
*/ |
103
|
|
|
public function getCSPNonce(): ?string |
104
|
|
|
{ |
105
|
|
|
return self::$nonce; |
106
|
|
|
} |
107
|
|
|
} |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: