2018-04-25 23:06:05 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Skobkin\Bundle\PointToolsBundle\DTO\Api\WebSocket;
|
|
|
|
|
|
|
|
use Skobkin\Bundle\PointToolsBundle\DTO\Api\ValidableInterface;
|
|
|
|
use Skobkin\Bundle\PointToolsBundle\Exception\WebSocket\UnsupportedTypeException;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* WebSocket update message
|
|
|
|
*/
|
|
|
|
class Message implements ValidableInterface
|
|
|
|
{
|
|
|
|
public const TYPE_COMMENT = 'comment';
|
|
|
|
public const TYPE_POST = 'post';
|
2019-01-19 13:27:16 +00:00
|
|
|
public const TYPE_POST_RECOMMENDATION = 'rec';
|
|
|
|
public const TYPE_COMMENT_RECOMMENDATION = 'ok';
|
2018-04-25 23:06:05 +00:00
|
|
|
|
2019-01-19 13:27:16 +00:00
|
|
|
/**
|
|
|
|
* Event type. @see Message::TYPE_* constants
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2018-04-25 23:06:05 +00:00
|
|
|
private $a;
|
|
|
|
|
2019-01-19 13:27:16 +00:00
|
|
|
/**
|
|
|
|
* Login of the user
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2018-04-25 23:06:05 +00:00
|
|
|
private $author;
|
|
|
|
|
|
|
|
/** @var string|null */
|
|
|
|
private $authorName;
|
|
|
|
|
2019-01-19 13:27:16 +00:00
|
|
|
/**
|
|
|
|
* Number of the comment in the thread
|
|
|
|
*
|
|
|
|
* @var int|null
|
|
|
|
*/
|
2018-04-25 23:06:05 +00:00
|
|
|
private $commentId;
|
|
|
|
|
2019-01-19 13:27:16 +00:00
|
|
|
/**
|
|
|
|
* ???
|
|
|
|
*
|
|
|
|
* @var bool|null
|
|
|
|
*/
|
2018-04-25 23:06:05 +00:00
|
|
|
private $cut;
|
|
|
|
|
2019-01-19 13:27:16 +00:00
|
|
|
/**
|
|
|
|
* Array of file paths
|
|
|
|
*
|
|
|
|
* @var string[]|null
|
|
|
|
*/
|
2018-04-25 23:06:05 +00:00
|
|
|
private $files;
|
|
|
|
|
|
|
|
/** @var string|null */
|
|
|
|
private $html;
|
|
|
|
|
2019-01-19 13:27:16 +00:00
|
|
|
/**
|
|
|
|
* @deprecated Link in the Post::type=feed posts
|
|
|
|
*
|
|
|
|
* @var string|null
|
|
|
|
*/
|
2018-04-25 23:06:05 +00:00
|
|
|
private $link;
|
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
private $postId;
|
|
|
|
|
|
|
|
/** @var bool|null */
|
|
|
|
private $private;
|
|
|
|
|
2019-01-19 13:27:16 +00:00
|
|
|
/**
|
|
|
|
* Number of the comment in the thread for recommendation with text
|
|
|
|
*
|
|
|
|
* @var int|null
|
|
|
|
*/
|
|
|
|
private $rcid;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Array of tags
|
|
|
|
*
|
|
|
|
* @var string[]|null
|
|
|
|
*/
|
2018-04-25 23:06:05 +00:00
|
|
|
private $tags;
|
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
private $text;
|
|
|
|
|
2019-01-19 13:27:16 +00:00
|
|
|
/**
|
|
|
|
* @deprecated ???
|
|
|
|
*
|
|
|
|
* @var string|null
|
|
|
|
*/
|
2018-04-25 23:06:05 +00:00
|
|
|
private $title;
|
|
|
|
|
2019-01-19 13:27:16 +00:00
|
|
|
/**
|
|
|
|
* Number of the comment to which this comment is answering
|
|
|
|
*
|
|
|
|
* @var string|null
|
|
|
|
*/
|
2018-04-25 23:06:05 +00:00
|
|
|
private $toCommentId;
|
|
|
|
|
2019-01-19 13:27:16 +00:00
|
|
|
/**
|
|
|
|
* Text quotation of the comment to which this comment is answering
|
|
|
|
*
|
|
|
|
* @var string|null
|
|
|
|
*/
|
2018-04-25 23:06:05 +00:00
|
|
|
private $toText;
|
|
|
|
|
2019-01-19 13:27:16 +00:00
|
|
|
/**
|
|
|
|
* Array of logins of users to which post is addressed
|
|
|
|
*
|
|
|
|
* @var string[]|null
|
|
|
|
*/
|
2018-04-25 23:06:05 +00:00
|
|
|
private $toUsers;
|
|
|
|
|
|
|
|
public function isPost(): bool
|
|
|
|
{
|
|
|
|
return self::TYPE_POST === $this->a;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isComment(): bool
|
|
|
|
{
|
|
|
|
return self::TYPE_COMMENT === $this->a;
|
|
|
|
}
|
|
|
|
|
2019-01-19 13:27:16 +00:00
|
|
|
public function isCommentRecommendation(): bool
|
2018-04-25 23:06:05 +00:00
|
|
|
{
|
2019-01-19 13:27:16 +00:00
|
|
|
return self::TYPE_COMMENT_RECOMMENDATION === $this->a;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isPostRecommendation(): bool
|
|
|
|
{
|
|
|
|
return self::TYPE_POST_RECOMMENDATION === $this->a;
|
2018-04-25 23:06:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws \RuntimeException
|
|
|
|
* @throws UnsupportedTypeException
|
|
|
|
*/
|
|
|
|
public function isValid(): bool
|
|
|
|
{
|
|
|
|
switch ($this->a) {
|
|
|
|
case self::TYPE_POST:
|
|
|
|
if (
|
|
|
|
null !== $this->author &&
|
|
|
|
null !== $this->html &&
|
|
|
|
null !== $this->postId &&
|
|
|
|
null !== $this->private &&
|
|
|
|
null !== $this->tags
|
|
|
|
) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case self::TYPE_COMMENT;
|
|
|
|
if (
|
|
|
|
null !== $this->author &&
|
|
|
|
null !== $this->commentId &&
|
|
|
|
null !== $this->html &&
|
|
|
|
null !== $this->postId &&
|
|
|
|
null !== $this->text
|
|
|
|
) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-01-19 13:27:16 +00:00
|
|
|
case self::TYPE_COMMENT_RECOMMENDATION;
|
2018-04-25 23:06:05 +00:00
|
|
|
if (
|
|
|
|
null !== $this->author &&
|
|
|
|
null !== $this->postId
|
|
|
|
) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case null:
|
|
|
|
throw new \RuntimeException('Message has NULL type.');
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
throw new UnsupportedTypeException(sprintf('Type \'%s\' is not supported.', $this->a));
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getA(): string
|
|
|
|
{
|
|
|
|
return $this->a;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setA(string $a): void
|
|
|
|
{
|
|
|
|
$this->a = $a;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getAuthor(): string
|
|
|
|
{
|
|
|
|
return $this->author;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setAuthor(string $author): void
|
|
|
|
{
|
|
|
|
$this->author = $author;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getAuthorName(): ?string
|
|
|
|
{
|
|
|
|
return $this->authorName;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setAuthorName(?string $authorName): void
|
|
|
|
{
|
|
|
|
$this->authorName = $authorName;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCommentId(): ?int
|
|
|
|
{
|
|
|
|
return $this->commentId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setCommentId(?int $commentId): void
|
|
|
|
{
|
|
|
|
$this->commentId = $commentId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCut(): ?bool
|
|
|
|
{
|
|
|
|
return $this->cut;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setCut(?bool $cut): void
|
|
|
|
{
|
|
|
|
$this->cut = $cut;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getFiles(): ?array
|
|
|
|
{
|
|
|
|
return $this->files;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setFiles(?array $files): void
|
|
|
|
{
|
|
|
|
$this->files = $files;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getHtml(): ?string
|
|
|
|
{
|
|
|
|
return $this->html;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setHtml(?string $html): void
|
|
|
|
{
|
|
|
|
$this->html = $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getLink(): ?string
|
|
|
|
{
|
|
|
|
return $this->link;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setLink(?string $link): void
|
|
|
|
{
|
|
|
|
$this->link = $link;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPostId(): string
|
|
|
|
{
|
|
|
|
return $this->postId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setPostId(string $postId): void
|
|
|
|
{
|
|
|
|
$this->postId = $postId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPrivate(): ?bool
|
|
|
|
{
|
|
|
|
return $this->private;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setPrivate(?bool $private): void
|
|
|
|
{
|
|
|
|
$this->private = $private;
|
|
|
|
}
|
|
|
|
|
2019-01-19 13:27:16 +00:00
|
|
|
public function getRcid(): ?int
|
|
|
|
{
|
|
|
|
return $this->rcid;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setRcid(?int $rcid): void
|
|
|
|
{
|
|
|
|
$this->rcid = $rcid;
|
|
|
|
}
|
|
|
|
|
2018-04-25 23:06:05 +00:00
|
|
|
public function getTags(): ?array
|
|
|
|
{
|
|
|
|
return $this->tags;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setTags(?array $tags): void
|
|
|
|
{
|
|
|
|
$this->tags = $tags;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getText(): string
|
|
|
|
{
|
|
|
|
return $this->text;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setText(string $text): void
|
|
|
|
{
|
|
|
|
$this->text = $text;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getTitle(): ?string
|
|
|
|
{
|
|
|
|
return $this->title;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setTitle(?string $title): void
|
|
|
|
{
|
|
|
|
$this->title = $title;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getToCommentId(): ?string
|
|
|
|
{
|
|
|
|
return $this->toCommentId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setToCommentId(?string $toCommentId): void
|
|
|
|
{
|
|
|
|
$this->toCommentId = $toCommentId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getToText(): ?string
|
|
|
|
{
|
|
|
|
return $this->toText;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setToText(?string $toText): void
|
|
|
|
{
|
|
|
|
$this->toText = $toText;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getToUsers(): ?array
|
|
|
|
{
|
|
|
|
return $this->toUsers;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setToUsers(?array $toUsers): void
|
|
|
|
{
|
|
|
|
$this->toUsers = $toUsers;
|
|
|
|
}
|
|
|
|
}
|