laravel-websockets/src/Server/Logger/HttpLogger.php

58 lines
1.3 KiB
PHP
Raw Normal View History

2018-11-27 20:30:33 +00:00
<?php
namespace BeyondCode\LaravelWebSockets\Server\Logger;
use Exception;
use Ratchet\ConnectionInterface;
use Ratchet\MessageComponentInterface;
class HttpLogger extends Logger implements MessageComponentInterface
{
/** @var \Ratchet\Http\HttpServerInterface */
protected $app;
2018-12-04 21:22:33 +00:00
public static function decorate(MessageComponentInterface $app): self
2018-11-27 20:30:33 +00:00
{
2018-12-04 21:22:33 +00:00
$logger = app(self::class);
2018-11-27 20:30:33 +00:00
return $logger->setApp($app);
}
public function setApp(MessageComponentInterface $app)
{
$this->app = $app;
return $this;
}
public function onOpen(ConnectionInterface $connection)
{
$this->app->onOpen($connection);
}
public function onMessage(ConnectionInterface $connection, $message)
{
$this->app->onMessage($connection, $message);
}
public function onClose(ConnectionInterface $connection)
{
$this->app->onClose($connection);
}
public function onError(ConnectionInterface $connection, Exception $exception)
{
$exceptionClass = get_class($exception);
$message = "Exception `{$exceptionClass}` thrown: `{$exception->getMessage()}`";
if ($this->verbose) {
$message .= $exception->getTraceAsString();
}
$this->error($message);
$this->app->onError($connection, $exception);
}
2018-12-04 21:22:33 +00:00
}