Files
sysPass/lib/SP/Core/Messages/TaskMessage.php
Rubén D 41703b50f9 * [MOD] Strict type checking (WIP)
Signed-off-by: Rubén D <nuxsmin@syspass.org>
2020-12-20 14:24:42 +01:00

242 lines
4.6 KiB
PHP

<?php
/*
* sysPass
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2020, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
* sysPass is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* sysPass is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
*/
namespace SP\Core\Messages;
use JsonSerializable;
/**
* Class TaskMessage
*
* @package SP\Core\Messages
*/
final class TaskMessage implements MessageInterface, JsonSerializable
{
/**
* @var string
*/
protected $taskId;
/**
* @var string
*/
protected $task;
/**
* @var string
*/
protected $message;
/**
* @var int
*/
protected $time = 0;
/**
* @var int
*/
protected $progress = 0;
/**
* @var int
*/
protected $end = 0;
/**
* TaskMessage constructor.
*
* @param string $taskId
* @param string $task
*/
public function __construct(string $taskId, string $task)
{
$this->taskId = $taskId;
$this->task = $task;
}
/**
* @return string
*/
public function getTask()
{
return $this->task;
}
/**
* @param string $task
*
* @return TaskMessage
*/
public function setTask(string $task): TaskMessage
{
$this->task = $task;
return $this;
}
/**
* @return string|null
*/
public function getMessage(): ?string
{
return $this->message;
}
/**
* @param string $message
*
* @return TaskMessage
*/
public function setMessage(string $message)
{
$this->message = $message;
return $this;
}
/**
* @return int
*/
public function getTime(): int
{
return $this->time;
}
/**
* @param int $time
*
* @return TaskMessage
*/
public function setTime(int $time): TaskMessage
{
$this->time = $time;
return $this;
}
/**
* @return int
*/
public function getProgress(): int
{
return $this->progress;
}
/**
* @param int $progress
*
* @return TaskMessage
*/
public function setProgress(int $progress): TaskMessage
{
$this->progress = $progress;
return $this;
}
/**
* @return int
*/
public function getEnd(): int
{
return $this->end;
}
/**
* @param int $end
*
* @return TaskMessage
*/
public function setEnd(int $end): TaskMessage
{
$this->end = $end;
return $this;
}
/**
* Componer un mensaje en formato texto
*
* @param string $delimiter
*
* @return string
*/
public function composeText(string $delimiter = ';'): string
{
return implode($delimiter, [
'taskId' => $this->taskId,
'task' => $this->task,
'message' => $this->message,
'time' => $this->time,
'progress' => $this->progress,
'end' => $this->end
]);
}
/**
* Componer un mensaje en formato HTML
*
* @return string
*/
public function composeHtml(): string
{
return $this->composeText();
}
/**
* Componer un mensaje en formato JSON
*/
public function composeJson()
{
return json_encode($this);
}
/**
* Specify data which should be serialized to JSON
*
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
* @return mixed data which can be serialized by <b>json_encode</b>,
* which is a value of any type other than a resource.
* @since 5.4.0
*/
public function jsonSerialize()
{
return get_object_vars($this);
}
/**
* @return string
*/
public function getTaskId(): string
{
return $this->taskId;
}
/**
* @param string $taskId
*
* @return TaskMessage
*/
public function setTaskId(string $taskId)
{
$this->taskId = $taskId;
return $this;
}
}