1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sylius\Component\Attribute\Model; |
13
|
|
|
|
14
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
15
|
|
|
use Doctrine\Common\Collections\Collection; |
16
|
|
|
use Sylius\Component\Attribute\AttributeType\TextAttributeType; |
17
|
|
|
use Sylius\Component\Resource\Model\TimestampableTrait; |
18
|
|
|
use Sylius\Component\Resource\Model\TranslatableTrait; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @author Paweł Jędrzejewski <[email protected]> |
22
|
|
|
* @author Gonzalo Vilaseca <[email protected]> |
23
|
|
|
* @author Mateusz Zalewski <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
class Attribute implements AttributeInterface |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
use TimestampableTrait; |
28
|
|
|
use TranslatableTrait { |
29
|
|
|
__construct as private initializeTranslationsCollection; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var mixed |
34
|
|
|
*/ |
35
|
|
|
protected $id; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
protected $code; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
protected $type = TextAttributeType::TYPE; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var array |
49
|
|
|
*/ |
50
|
|
|
protected $configuration = []; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var AttributeValueInterface[]|Collection |
54
|
|
|
*/ |
55
|
|
|
protected $values; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var string |
59
|
|
|
*/ |
60
|
|
|
protected $storageType; |
61
|
|
|
|
62
|
|
|
public function __construct() |
63
|
|
|
{ |
64
|
|
|
$this->initializeTranslationsCollection(); |
65
|
|
|
|
66
|
|
|
$this->values = new ArrayCollection(); |
67
|
|
|
$this->createdAt = new \DateTime(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* {@inheritdoc} |
72
|
|
|
*/ |
73
|
|
|
public function __toString() |
74
|
|
|
{ |
75
|
|
|
return $this->getName(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* {@inheritdoc} |
80
|
|
|
*/ |
81
|
|
|
public function getId() |
82
|
|
|
{ |
83
|
|
|
return $this->id; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* {@inheritdoc} |
88
|
|
|
*/ |
89
|
|
|
public function getCode() |
90
|
|
|
{ |
91
|
|
|
return $this->code; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* {@inheritdoc} |
96
|
|
|
*/ |
97
|
|
|
public function setCode($code) |
98
|
|
|
{ |
99
|
|
|
$this->code = $code; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* {@inheritdoc} |
104
|
|
|
*/ |
105
|
|
|
public function getName() |
106
|
|
|
{ |
107
|
|
|
return $this->getTranslation()->getName(); |
|
|
|
|
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* {@inheritdoc} |
112
|
|
|
*/ |
113
|
|
|
public function setName($name) |
114
|
|
|
{ |
115
|
|
|
$this->getTranslation()->setName($name); |
|
|
|
|
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* {@inheritdoc} |
120
|
|
|
*/ |
121
|
|
|
public function getType() |
122
|
|
|
{ |
123
|
|
|
return $this->type; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* {@inheritdoc} |
128
|
|
|
*/ |
129
|
|
|
public function setType($type) |
130
|
|
|
{ |
131
|
|
|
$this->type = $type; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* {@inheritdoc} |
136
|
|
|
*/ |
137
|
|
|
public function getConfiguration() |
138
|
|
|
{ |
139
|
|
|
return $this->configuration; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* {@inheritdoc} |
144
|
|
|
*/ |
145
|
|
|
public function setConfiguration(array $configuration) |
146
|
|
|
{ |
147
|
|
|
$this->configuration = $configuration; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* {@inheritdoc} |
152
|
|
|
*/ |
153
|
|
|
public function getValues() |
154
|
|
|
{ |
155
|
|
|
return $this->values; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @param string $storageType |
160
|
|
|
*/ |
161
|
|
|
public function setStorageType($storageType) |
162
|
|
|
{ |
163
|
|
|
$this->storageType = $storageType; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @return string |
168
|
|
|
*/ |
169
|
|
|
public function getStorageType() |
170
|
|
|
{ |
171
|
|
|
return $this->storageType; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* {@inheritdoc} |
176
|
|
|
*/ |
177
|
|
|
protected function createTranslation() |
178
|
|
|
{ |
179
|
|
|
return new AttributeTranslation(); |
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
|