代码同步
This commit is contained in:
8
Server/vendor/textalk/websocket/lib/Message/Binary.php
vendored
Normal file
8
Server/vendor/textalk/websocket/lib/Message/Binary.php
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace WebSocket\Message;
|
||||
|
||||
class Binary extends Message
|
||||
{
|
||||
protected $opcode = 'binary';
|
||||
}
|
||||
8
Server/vendor/textalk/websocket/lib/Message/Close.php
vendored
Normal file
8
Server/vendor/textalk/websocket/lib/Message/Close.php
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace WebSocket\Message;
|
||||
|
||||
class Close extends Message
|
||||
{
|
||||
protected $opcode = 'close';
|
||||
}
|
||||
25
Server/vendor/textalk/websocket/lib/Message/Factory.php
vendored
Normal file
25
Server/vendor/textalk/websocket/lib/Message/Factory.php
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace WebSocket\Message;
|
||||
|
||||
use WebSocket\BadOpcodeException;
|
||||
|
||||
class Factory
|
||||
{
|
||||
public function create(string $opcode, string $payload = ''): Message
|
||||
{
|
||||
switch ($opcode) {
|
||||
case 'text':
|
||||
return new Text($payload);
|
||||
case 'binary':
|
||||
return new Binary($payload);
|
||||
case 'ping':
|
||||
return new Ping($payload);
|
||||
case 'pong':
|
||||
return new Pong($payload);
|
||||
case 'close':
|
||||
return new Close($payload);
|
||||
}
|
||||
throw new BadOpcodeException("Invalid opcode '{$opcode}' provided");
|
||||
}
|
||||
}
|
||||
53
Server/vendor/textalk/websocket/lib/Message/Message.php
vendored
Normal file
53
Server/vendor/textalk/websocket/lib/Message/Message.php
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace WebSocket\Message;
|
||||
|
||||
use DateTime;
|
||||
|
||||
abstract class Message
|
||||
{
|
||||
protected $opcode;
|
||||
protected $payload;
|
||||
protected $timestamp;
|
||||
|
||||
public function __construct(string $payload = '')
|
||||
{
|
||||
$this->payload = $payload;
|
||||
$this->timestamp = new DateTime();
|
||||
}
|
||||
|
||||
public function getOpcode(): string
|
||||
{
|
||||
return $this->opcode;
|
||||
}
|
||||
|
||||
public function getLength(): int
|
||||
{
|
||||
return strlen($this->payload);
|
||||
}
|
||||
|
||||
public function getTimestamp(): DateTime
|
||||
{
|
||||
return $this->timestamp;
|
||||
}
|
||||
|
||||
public function getContent(): string
|
||||
{
|
||||
return $this->payload;
|
||||
}
|
||||
|
||||
public function setContent(string $payload = ''): void
|
||||
{
|
||||
$this->payload = $payload;
|
||||
}
|
||||
|
||||
public function hasContent(): bool
|
||||
{
|
||||
return $this->payload != '';
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return get_class($this);
|
||||
}
|
||||
}
|
||||
8
Server/vendor/textalk/websocket/lib/Message/Ping.php
vendored
Normal file
8
Server/vendor/textalk/websocket/lib/Message/Ping.php
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace WebSocket\Message;
|
||||
|
||||
class Ping extends Message
|
||||
{
|
||||
protected $opcode = 'ping';
|
||||
}
|
||||
8
Server/vendor/textalk/websocket/lib/Message/Pong.php
vendored
Normal file
8
Server/vendor/textalk/websocket/lib/Message/Pong.php
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace WebSocket\Message;
|
||||
|
||||
class Pong extends Message
|
||||
{
|
||||
protected $opcode = 'pong';
|
||||
}
|
||||
8
Server/vendor/textalk/websocket/lib/Message/Text.php
vendored
Normal file
8
Server/vendor/textalk/websocket/lib/Message/Text.php
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace WebSocket\Message;
|
||||
|
||||
class Text extends Message
|
||||
{
|
||||
protected $opcode = 'text';
|
||||
}
|
||||
Reference in New Issue
Block a user