-
Notifications
You must be signed in to change notification settings - Fork 14
/
TextOption.php
109 lines (87 loc) · 2.36 KB
/
TextOption.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
namespace inklabs\kommerce\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use inklabs\kommerce\Lib\UuidInterface;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Constraints as Assert;
class TextOption implements IdEntityInterface
{
use TimeTrait, IdTrait;
/** @var string */
protected $name;
/** @var string|null */
protected $description;
/** @var int */
protected $sortOrder;
/** @var TextOptionType */
protected $type;
/** @var ArrayCollection|Tag[] */
protected $tags;
public function __construct(UuidInterface $id = null)
{
$this->setId($id);
$this->setCreated();
$this->tags = new ArrayCollection;
$this->sortOrder = 0;
$this->setType(TextOptionType::text());
}
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$metadata->addPropertyConstraint('name', new Assert\NotBlank);
$metadata->addPropertyConstraint('name', new Assert\Length([
'max' => 255,
]));
$metadata->addPropertyConstraint('description', new Assert\Length([
'max' => 65535,
]));
$metadata->addPropertyConstraint('sortOrder', new Assert\NotNull);
$metadata->addPropertyConstraint('sortOrder', new Assert\Range([
'min' => 0,
'max' => 65535,
]));
$metadata->addPropertyConstraint('type', new Assert\Valid);
}
public function setType(TextOptionType $type)
{
$this->type = $type;
}
public function getType(): TextOptionType
{
return $this->type;
}
public function setName(string $name)
{
$this->name = $name;
}
public function getName(): string
{
return $this->name;
}
public function setDescription(string $description)
{
$this->description = $description;
}
public function getDescription(): ?string
{
return $this->description;
}
public function addTag(Tag $tag)
{
$this->tags[] = $tag;
}
/**
* @return Tag[]
*/
public function getTags()
{
return $this->tags;
}
public function setSortOrder(int $sortOrder)
{
$this->sortOrder = $sortOrder;
}
public function getSortOrder(): int
{
return $this->sortOrder;
}
}