-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStringPropertyType.php
34 lines (29 loc) · 1.06 KB
/
StringPropertyType.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
declare(strict_types = 1);
namespace TypeSchema\Model;
use PSX\Schema\Attribute\Description;
#[Description('Represents a string value')]
class StringPropertyType extends ScalarPropertyType implements \JsonSerializable, \PSX\Record\RecordableInterface
{
#[Description('Optional describes the format of the string. Supported are the following types: date, date-time and time. A code generator may use a fitting data type to represent such a format, if not supported it should fallback to a string')]
protected ?string $format = null;
public function setFormat(?string $format) : void
{
$this->format = $format;
}
public function getFormat() : ?string
{
return $this->format;
}
public function toRecord() : \PSX\Record\RecordInterface
{
/** @var \PSX\Record\Record<mixed> $record */
$record = parent::toRecord();
$record->put('format', $this->format);
return $record;
}
public function jsonSerialize() : object
{
return (object) $this->toRecord()->getAll();
}
}