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

61 lines
1.4 KiB
PHP
Raw Normal View History

2018-11-24 14:23:59 +00:00
<?php
namespace BeyondCode\LaravelWebSockets\Server\Logger;
use Ratchet\ConnectionInterface;
class ConnectionLogger extends Logger implements ConnectionInterface
{
/** @var \Ratchet\ConnectionInterface */
protected $connection;
public static function decorate(ConnectionInterface $app): ConnectionLogger
{
$logger = app(ConnectionLogger::class);
return $logger->setConnection($app);
}
public function setConnection(ConnectionInterface $connection)
{
$this->connection = $connection;
return $this;
}
protected function getConnection() {
return $this->connection;
}
public function send($data)
{
2018-11-24 21:07:53 +00:00
$this->info("{$this->connection->client->appId}: connection id {$this->connection->socketId} sending message {$data}");
2018-11-24 14:23:59 +00:00
$this->connection->send($data);
}
public function close()
{
2018-11-24 21:07:53 +00:00
$this->warn("{$this->connection->client->appId}: connection id {$this->connection->socketId} closing.");
2018-11-24 14:23:59 +00:00
$this->connection->close();
}
public function __set($name, $value)
{
return $this->connection->$name = $value;
}
public function __get($name)
{
return $this->connection->$name;
}
public function __isset($name) {
return isset($this->connection->$name);
}
public function __unset($name) {
unset($this->connection->$name);
}
}