<?php #todo кажется часть полей вроде city, room, color, invis напрямик зависит от login (отправитель) #todo если это так, частью сеттеров можно будет пожертвовать. class ChatMessage { private string $city = 'capitalcity'; private int $room = 0; private string $login = ''; private string $to = ''; private string $text; private int $time = 0; private int $type = 0; private int $typeTime = 0; private string $color = '#000'; private int $sound = 0; private int $spam = 0; private bool $isAlert = false; private int $invis = 0; private int $da = 0; private int $delete = 0; private int $molch = 0; private int $dn = 0; /** * Феерверки, чёрт подери! * _incl_data\class\magic\feerverks.php * @var string|null */ private ?string $fireworks = null; /** * @return int */ public function getDn(): int { return $this->dn; } /** * @param int $dn */ public function setDn(int $dn): void { $this->dn = $dn; } /** * @return int */ public function getDelete(): int { return $this->delete; } /** * @param int $delete */ public function setDelete(int $delete): void { $this->delete = $delete; } /** * @return int */ public function getMolch(): int { return $this->molch; } /** * @param int $molch */ public function setMolch(int $molch): void { $this->molch = $molch; } /** * @return int */ public function getInvis(): int { return $this->invis; } /** * @param int $invis */ public function setInvis(int $invis): void { $this->invis = $invis; } /** * @return int */ public function getDa(): int { return $this->da; } /** * @param int $da */ public function setDa(int $da): void { $this->da = $da; } /** * @return int */ public function getSpam(): int { return $this->spam; } /** * @param int $spam */ public function setSpam(int $spam): void { $this->spam = $spam; } /** * @return int */ public function getSound(): int { return $this->sound; } /** * @param int $sound */ public function setSound(int $sound): void { $this->sound = $sound; } /** * @return string */ public function getCity(): string { return $this->city; } /** * @return int */ public function getRoom(): int { return $this->room; } /** * @return string */ public function getLogin(): string { return $this->login; } /** * @return string */ public function getTo(): string { return $this->to; } /** * @return string */ public function getText(): string { if ($this->isAlert) { return '<span style="color: red">Внимание!</span> ' . $this->text; } return $this->text; } /** * @return int */ public function getTime(): int { if (!$this->time) { $this->time = time(); } return $this->time; } /** * @return int */ public function getType(): int { return $this->type; } /** * @return int */ public function getTypeTime(): int { return $this->typeTime; } /** * @return string */ public function getColor(): string { return $this->color; } /** * @param string $city */ public function setCity(string $city): void { $this->city = $city; } /** * @param int $room */ public function setRoom(int $room): void { $this->room = $room; } /** * @param string $login */ public function setLogin(string $login): void { $this->login = $login; } /** * @param string $to */ public function setTo(string $to): void { $this->to = $to; } /** * @param string $text */ public function setText(string $text): void { $this->text = $text; } /** * @param int $time */ public function setTime(int $time): void { $this->time = $time; } /** * @param int $type */ public function setType(int $type): void { $this->type = $type; } /** * @param int $typeTime */ public function setTypeTime(int $typeTime): void { $this->typeTime = $typeTime; } /** * @param string $color */ public function setColor(string $color): void { $this->color = $color; } /** * Добавляет к сообщению красный префикс "Внимание!". * @param bool $isAlert */ public function setIsAlert(bool $isAlert): void { $this->isAlert = $isAlert; } /** * @return string|null */ public function getFireworks(): ?string { return $this->fireworks; } /** * @param string|null $fireworks */ public function setFireworks(?string $fireworks): void { $this->fireworks = $fireworks; } /** * Заглушка для опциональной передачи параметров. * @param string $json * @return void */ public function setParamsFromJson(string $json): void { $params = json_decode($json, true); foreach ($params as $param => $value) { $method = 'set' . ucfirst($param); if (method_exists(self::class, $method)) { $this->$method($value); } } } }