* Note: `default()` method should not be used, because a "false" value is an absent value, which will use the default value, and force the value to "true"
16
* To define a default value for the view, use `value()` instead
17
*
18
* <code>
19
* $builder->boolean('enable')->value(true);
20
* </code>
21
*
22
* @see BooleanElement
23
* @see FormBuilderInterface::boolean()
24
*
25
* @extends AbstractElementBuilder<BooleanElement>
26
*/
27
class BooleanElementBuilder extends AbstractElementBuilder
28
{
29
/**
30
* @var string
31
*/
32
private $httpValue = '1';
33
34
/**
35
* Define the HTTP value used for represent the true value
36
*
37
* @param string $httpValue A non-empty string value. The default value is "1"
38
*
39
* @return $this
40
*
41
* @see ElementInterface::httpValue()
42
*/
43
2
public function httpValue(string $httpValue): self
44
{
45
2
if (empty($httpValue)) {
46
1
throw new InvalidArgumentException('The httpValue must be a non-empty string');
47
}
48
49
1
$this->httpValue = $httpValue;
50
51
1
return $this;
52
}
53
54
/**
55
* {@inheritdoc}
56
*/
57
11
protected function createElement(ValueValidatorInterface $validator, TransformerInterface $transformer): ElementInterface
58
{
59
11
return new BooleanElement($validator, $transformer, $this->httpValue);