-
Notifications
You must be signed in to change notification settings - Fork 14
/
Attribute.php
121 lines (98 loc) · 2.84 KB
/
Attribute.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
110
111
112
113
114
115
116
117
118
119
120
121
<?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 Attribute implements IdEntityInterface
{
use TimeTrait, IdTrait;
/** @var string */
protected $name;
/** @var string|null */
protected $description;
/** @var AttributeChoiceType */
private $choiceType;
/** @var int */
protected $sortOrder;
/** @var AttributeValue[] */
protected $attributeValues;
/** @var ProductAttribute[] */
protected $productAttributes;
public function __construct(string $name, AttributeChoiceType $choiceType, int $sortOrder, UuidInterface $id = null)
{
$this->setId($id);
$this->setCreated();
$this->name = $name;
$this->choiceType = $choiceType;
$this->sortOrder = $sortOrder;
$this->attributeValues = new ArrayCollection();
$this->productAttributes = new ArrayCollection();
}
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$metadata->addPropertyConstraint('name', new Assert\NotBlank);
$metadata->addPropertyConstraint('name', new Assert\Length([
'max' => 255,
]));
$metadata->addPropertyConstraint('sortOrder', new Assert\NotNull);
$metadata->addPropertyConstraint('sortOrder', new Assert\Range([
'min' => 0,
'max' => 65535,
]));
}
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 setChoiceType(AttributeChoiceType $choiceType)
{
$this->choiceType = $choiceType;
}
public function getChoiceType(): AttributeChoiceType
{
return $this->choiceType;
}
public function setSortOrder(int $sortOrder)
{
$this->sortOrder = $sortOrder;
}
public function getSortOrder(): int
{
return $this->sortOrder;
}
public function addAttributeValue(AttributeValue $attributeValue)
{
$this->attributeValues->add($attributeValue);
}
/**
* @return AttributeValue[]
*/
public function getAttributeValues()
{
return $this->attributeValues;
}
/**
* @return ProductAttribute[]
*/
public function getProductAttributes()
{
return $this->productAttributes;
}
public function addProductAttribute(ProductAttribute $productAttribute)
{
$this->productAttributes->add($productAttribute);
}
}