diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2023-04-13 02:14:53 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2023-04-13 02:14:53 +0300 |
commit | d0fa8d6f63003a6cb2f1897158bc587ab2344ea3 (patch) | |
tree | 5a6c165e928354a59eea48030c5de51067d381e4 /src/messages/Message.php | |
parent | 5272c5f541a75b2a7824df4264ad7e69c6e346fa (diff) |
1.6.0: support signals
Diffstat (limited to 'src/messages/Message.php')
-rw-r--r-- | src/messages/Message.php | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/messages/Message.php b/src/messages/Message.php new file mode 100644 index 0000000..df7464e --- /dev/null +++ b/src/messages/Message.php @@ -0,0 +1,43 @@ +<?php + +namespace jobd\messages; + + +abstract class Message { + + const REQUEST = 0; + const RESPONSE = 1; + const PING = 2; + const PONG = 3; + + protected $type; + + /** + * Message constructor. + * @param int $type + */ + public function __construct(int $type) + { + $this->type = $type; + } + + /** + * @return array + */ + abstract protected function getContent(): array; + + /** + * @return string + */ + public function serialize(): string + { + $data = [$this->type]; + $content = $this->getContent(); + + if (!empty($content)) + $data[] = $content; + + return json_encode($data); + } + +}
\ No newline at end of file |