Einführung des Modells.

This commit is contained in:
2021-03-29 15:07:07 +02:00
parent 9e2e94c116
commit e4cd00caf1
6 changed files with 153 additions and 3 deletions
+11
View File
@@ -0,0 +1,11 @@
<?php
namespace TorstenHettstedt\TimekeepingApi\Models;
use JsonSerializable;
interface ModelInterface extends JsonSerializable
{
}
+65
View File
@@ -0,0 +1,65 @@
<?php
namespace TorstenHettstedt\TimekeepingApi\Models;
use DateInterval;
use DateTime;
use JetBrains\PhpStorm\ArrayShape;
class WorkingHours implements ModelInterface
{
protected ?DateTime $workingDay = null;
protected ?DateInterval $workingTime = null;
/**
* @return DateTime|null
*/
public function getWorkingDay(): ?DateTime
{
return $this->workingDay;
}
/**
* @param DateTime $workingDay
*
* @return WorkingHours
*/
public function setWorkingDay(DateTime $workingDay): WorkingHours
{
$this->workingDay = $workingDay;
return $this;
}
/**
* @return DateInterval|null
*/
public function getWorkingTime(): ?DateInterval
{
return $this->workingTime;
}
/**
* @param DateInterval $workingTime
*
* @return WorkingHours
*/
public function setWorkingTime(DateInterval $workingTime): WorkingHours
{
$this->workingTime = $workingTime;
return $this;
}
/**
* @return array<string, string>
*/
#[ArrayShape(['workingDay' => "string", 'workingTime' => "string"])]
public function jsonSerialize(): array
{
return [
'workingDay' => $this->getWorkingDay()->format('Y-m-d'),
'workingTime' => $this->getWorkingTime()->format('%H:%I:%S')
];
}
}