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\Variation\Model; |
13
|
|
|
|
14
|
|
|
use Sylius\Component\Resource\Model\TranslatableTrait; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @author Paweł Jędrzejewski <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
class OptionValue implements OptionValueInterface |
20
|
|
|
{ |
21
|
|
|
use TranslatableTrait { |
22
|
|
|
__construct as private initializeTranslationCollection; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var mixed |
27
|
|
|
*/ |
28
|
|
|
protected $id; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
protected $code; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
protected $value; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var OptionInterface |
42
|
|
|
*/ |
43
|
|
|
protected $option; |
44
|
|
|
|
45
|
|
|
public function __construct() |
46
|
|
|
{ |
47
|
|
|
$this->initializeTranslationCollection(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* {@inheritdoc} |
52
|
|
|
*/ |
53
|
|
|
public function __toString() |
54
|
|
|
{ |
55
|
|
|
return $this->getValue(); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* {@inheritdoc} |
60
|
|
|
*/ |
61
|
|
|
public function getId() |
62
|
|
|
{ |
63
|
|
|
return $this->id; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* {@inheritdoc} |
68
|
|
|
*/ |
69
|
|
|
public function getCode() |
70
|
|
|
{ |
71
|
|
|
return $this->code; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* {@inheritdoc} |
76
|
|
|
*/ |
77
|
|
|
public function setCode($code) |
78
|
|
|
{ |
79
|
|
|
$this->code = $code; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* {@inheritdoc} |
84
|
|
|
*/ |
85
|
|
|
public function getOption() |
86
|
|
|
{ |
87
|
|
|
return $this->option; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* {@inheritdoc} |
92
|
|
|
*/ |
93
|
|
|
public function setOption(OptionInterface $option = null) |
94
|
|
|
{ |
95
|
|
|
$this->option = $option; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* {@inheritdoc} |
100
|
|
|
*/ |
101
|
|
|
public function getValue() |
102
|
|
|
{ |
103
|
|
|
return $this->translate()->getValue(); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* {@inheritdoc} |
108
|
|
|
*/ |
109
|
|
|
public function setValue($value) |
110
|
|
|
{ |
111
|
|
|
$this->translate()->setValue($value); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* {@inheritdoc} |
116
|
|
|
*/ |
117
|
|
|
public function getOptionCode() |
118
|
|
|
{ |
119
|
|
|
if (null === $this->option) { |
120
|
|
|
throw new \BadMethodCallException('The option have not been created yet so you cannot access proxy methods.'); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
return $this->option->getCode(); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* {@inheritdoc} |
128
|
|
|
*/ |
129
|
|
|
public function getName() |
130
|
|
|
{ |
131
|
|
|
if (null === $this->option) { |
132
|
|
|
throw new \BadMethodCallException('The option have not been created yet so you cannot access proxy methods.'); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
return $this->option->getName(); |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|