1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BeyondCode\LaravelWebSockets\Server\Loggers; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
use Ratchet\ConnectionInterface; |
7
|
|
|
use Ratchet\MessageComponentInterface; |
8
|
|
|
|
9
|
|
|
class HttpLogger extends Logger implements MessageComponentInterface |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* The HTTP app instance to watch. |
13
|
|
|
* |
14
|
|
|
* @var \Ratchet\Http\HttpServerInterface |
15
|
|
|
*/ |
16
|
|
|
protected $app; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Create a new instance and add the app to watch. |
20
|
|
|
* |
21
|
|
|
* @param \Ratchet\MessageComponentInterface $app |
22
|
|
|
* @return self |
23
|
|
|
*/ |
24
|
|
|
public static function decorate(MessageComponentInterface $app): self |
25
|
|
|
{ |
26
|
|
|
$logger = app(self::class); |
27
|
|
|
|
28
|
|
|
return $logger->setApp($app); |
|
|
|
|
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Set a new app to watch. |
33
|
|
|
* |
34
|
|
|
* @param \Ratchet\MessageComponentInterface $app |
35
|
|
|
* @return $this |
36
|
|
|
*/ |
37
|
|
|
public function setApp(MessageComponentInterface $app) |
38
|
|
|
{ |
39
|
|
|
$this->app = $app; |
|
|
|
|
40
|
|
|
|
41
|
|
|
return $this; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Handle the HTTP open request. |
46
|
|
|
* |
47
|
|
|
* @param \Ratchet\ConnectionInterface $connection |
48
|
|
|
* @return void |
49
|
|
|
*/ |
50
|
|
|
public function onOpen(ConnectionInterface $connection) |
51
|
|
|
{ |
52
|
|
|
$this->app->onOpen($connection); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Handle the HTTP message request. |
57
|
|
|
* |
58
|
|
|
* @param \Ratchet\ConnectionInterface $connection |
59
|
|
|
* @param mixed $message |
60
|
|
|
* @return void |
61
|
|
|
*/ |
62
|
|
|
public function onMessage(ConnectionInterface $connection, $message) |
63
|
|
|
{ |
64
|
|
|
$this->app->onMessage($connection, $message); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Handle the HTTP close request. |
69
|
|
|
* |
70
|
|
|
* @param \Ratchet\ConnectionInterface $connection |
71
|
|
|
* @return void |
72
|
|
|
*/ |
73
|
|
|
public function onClose(ConnectionInterface $connection) |
74
|
|
|
{ |
75
|
|
|
$this->app->onClose($connection); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Handle HTTP errors. |
80
|
|
|
* |
81
|
|
|
* @param \Ratchet\ConnectionInterface $connection |
82
|
|
|
* @param Exception $exception |
83
|
|
|
* @return void |
84
|
|
|
*/ |
85
|
|
|
public function onError(ConnectionInterface $connection, Exception $exception) |
86
|
|
|
{ |
87
|
|
|
$exceptionClass = get_class($exception); |
88
|
|
|
|
89
|
|
|
$message = "Exception `{$exceptionClass}` thrown: `{$exception->getMessage()}`"; |
90
|
|
|
|
91
|
|
|
if ($this->verbose) { |
92
|
|
|
$message .= $exception->getTraceAsString(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
$this->error($message); |
96
|
|
|
|
97
|
|
|
$this->app->onError($connection, $exception); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.