-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCollectionDefinitionType.php
50 lines (45 loc) · 1.32 KB
/
CollectionDefinitionType.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
declare(strict_types = 1);
namespace TypeSchema\Model;
use PSX\Schema\Attribute\DerivedType;
use PSX\Schema\Attribute\Description;
use PSX\Schema\Attribute\Discriminator;
#[Description('Base collection type')]
#[Discriminator('type')]
#[DerivedType(ArrayDefinitionType::class, 'array')]
#[DerivedType(MapDefinitionType::class, 'map')]
abstract class CollectionDefinitionType extends DefinitionType implements \JsonSerializable, \PSX\Record\RecordableInterface
{
#[Description('')]
protected ?PropertyType $schema = null;
#[Description('')]
protected ?string $type = null;
public function setSchema(?PropertyType $schema) : void
{
$this->schema = $schema;
}
public function getSchema() : ?PropertyType
{
return $this->schema;
}
public function setType(?string $type) : void
{
$this->type = $type;
}
public function getType() : ?string
{
return $this->type;
}
public function toRecord() : \PSX\Record\RecordInterface
{
/** @var \PSX\Record\Record<mixed> $record */
$record = parent::toRecord();
$record->put('schema', $this->schema);
$record->put('type', $this->type);
return $record;
}
public function jsonSerialize() : object
{
return (object) $this->toRecord()->getAll();
}
}