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;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-27 20:34:37 +00:00
|
|
|
protected function getConnection()
|
|
|
|
|
{
|
2018-11-24 14:23:59 +00:00
|
|
|
return $this->connection;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function send($data)
|
|
|
|
|
{
|
2018-11-27 08:17:39 +00:00
|
|
|
$this->info("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-27 08:17:39 +00:00
|
|
|
$this->warn("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);
|
|
|
|
|
}
|
|
|
|
|
}
|