-
-
Notifications
You must be signed in to change notification settings - Fork 269
/
ObjectMultiCheckbox.php
74 lines (59 loc) · 1.64 KB
/
ObjectMultiCheckbox.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
<?php
declare(strict_types=1);
namespace DoctrineModule\Form\Element;
use Laminas\Form\Element\MultiCheckbox;
use Laminas\Stdlib\ArrayUtils;
use Traversable;
use function array_map;
use function is_array;
/** @psalm-import-type ValueOptionSpec from MultiCheckbox */
class ObjectMultiCheckbox extends MultiCheckbox
{
use GetProxy;
/**
* @param iterable<mixed> $options
*
* @return $this
*/
public function setOptions(iterable $options): self
{
$this->getProxy()->setOptions($options);
return parent::setOptions($options);
}
/** @return $this */
public function setOption(string $key, mixed $value): self
{
$this->getProxy()->setOptions([$key => $value]);
return parent::setOption($key, $value);
}
/**
* {@inheritDoc}
*/
public function setValue($value)
{
if ($value instanceof Traversable) {
$value = ArrayUtils::iteratorToArray($value);
} elseif ($value === null) {
return parent::setValue([]);
} elseif (! is_array($value)) {
$value = (array) $value;
}
return parent::setValue(array_map([$this->getProxy(), 'getValue'], $value));
}
/**
* {@inheritDoc}
*
* @return ValueOptionSpec
*/
public function getValueOptions(): array
{
if (! empty($this->valueOptions)) {
return $this->valueOptions;
}
$proxyValueOptions = $this->getProxy()->getValueOptions();
if (! empty($proxyValueOptions)) {
$this->setValueOptions($proxyValueOptions);
}
return $this->valueOptions;
}
}