-
Notifications
You must be signed in to change notification settings - Fork 352
/
ChoiceListItem.php
134 lines (121 loc) · 2.97 KB
/
ChoiceListItem.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
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
namespace Oro\Bundle\FormBundle\Form\Type;
/**
* Allows to provide additional attributes for 'option' element of 'choice' form type
*
* @deprecated since 1.8. Use the 'choice_attr' option of ChoiceType
*/
class ChoiceListItem
{
/**
* @var string
*/
private $label;
/**
* @var array
*/
private $attributes;
/**
* Constructor
*
* @param string $label A string is used as a label of the choice
* @param array $attributes Additional attributes of the choice
*/
public function __construct($label = null, array $attributes = array())
{
$this->label = $label;
$this->attributes = $attributes;
}
/**
* Returns a label of the choice
*
* @return string
*/
public function getLabel()
{
return $this->label;
}
/**
* Sets a label of the choice
*
* @param string $label
*/
public function setLabel($label)
{
$this->label = $label;
}
/**
* Returns additional attributes of the choice.
*
* @return array An array of key-value combinations.
*/
public function getAttributes()
{
return $this->attributes;
}
/**
* Returns additional attributes of the choice.
* This method is just an alias for getAttributes and it intended to use in Twig, for example choice.attr
*
* @return array An array of key-value combinations.
*/
public function getAttr()
{
return $this->attributes;
}
/**
* Returns whether the attribute with the given name exists.
*
* @param string $name The attribute name.
*
* @return Boolean Whether the attribute exists.
*/
public function hasAttribute($name)
{
return array_key_exists($name, $this->attributes);
}
/**
* Returns the value of the given attribute.
*
* @param string $name The attribute name.
* @param mixed $default The value returned if the attribute does not exist.
*
* @return mixed The attribute value.
*/
public function getAttribute($name, $default = null)
{
return array_key_exists($name, $this->attributes) ? $this->attributes[$name] : $default;
}
/**
* Sets the value for an attribute.
*
* @param string $name The name of the attribute
* @param string $value The value of the attribute
*
* @return self The configuration object.
*/
public function setAttribute($name, $value)
{
$this->attributes[$name] = $value;
}
/**
* Sets the attributes.
*
* @param array $attributes The attributes.
*
* @return self The configuration object.
*/
public function setAttributes(array $attributes)
{
$this->attributes = $attributes;
}
/**
* Returns a label of the choice
*
* @return string
*/
public function __toString()
{
return (string)$this->label;
}
}