• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nette / forms / 21851967935

10 Feb 2026 04:40AM UTC coverage: 93.076% (+0.2%) from 92.892%
21851967935

push

github

dg
netteForms: restructured package, includes UMD and ESM (BC break)

2070 of 2224 relevant lines covered (93.08%)

0.93 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.88
/src/Forms/ControlGroup.php
1
<?php
2

3
/**
4
 * This file is part of the Nette Framework (https://nette.org)
5
 * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6
 */
7

8
declare(strict_types=1);
9

10
namespace Nette\Forms;
11

12
use Nette;
13

14

15
/**
16
 * A user group of form controls.
17
 */
18
class ControlGroup
19
{
20
        /** @var \WeakMap<Control, null> */
21
        protected \WeakMap $controls;
22

23
        /** @var array<string, mixed> */
24
        private array $options = [];
25

26

27
        public function __construct()
28
        {
29
                $this->controls = new \WeakMap;
1✔
30
        }
1✔
31

32

33
        /** @param Control|Container|iterable<Control|Container> ...$items */
34
        public function add(Control|Container|iterable ...$items): static
1✔
35
        {
36
                foreach ($items as $item) {
1✔
37
                        if ($item instanceof Control) {
1✔
38
                                $this->controls[$item] = null;
1✔
39

40
                        } elseif ($item instanceof Container) {
1✔
41
                                foreach ($item->getComponents() as $component) {
1✔
42
                                        $this->add($component);
1✔
43
                                }
44
                        } elseif (is_iterable($item)) {
×
45
                                $this->add(...$item);
×
46

47
                        } else {
48
                                $type = get_debug_type($item);
×
49
                                throw new Nette\InvalidArgumentException("Control or Container items expected, $type given.");
×
50
                        }
51
                }
52

53
                return $this;
1✔
54
        }
55

56

57
        public function remove(Control $control): void
1✔
58
        {
59
                unset($this->controls[$control]);
1✔
60
        }
1✔
61

62

63
        public function removeOrphans(): void
64
        {
65
                foreach ($this->controls as $control => $foo) {
1✔
66
                        if (!$control->getForm(false)) {
1✔
67
                                unset($this->controls[$control]);
1✔
68
                        }
69
                }
70
        }
1✔
71

72

73
        /** @return Control[] */
74
        public function getControls(): array
75
        {
76
                $res = [];
1✔
77
                foreach ($this->controls as $control => $foo) {
1✔
78
                        $res[] = $control;
1✔
79
                }
80
                return $res;
1✔
81
        }
82

83

84
        /**
85
         * Sets user-specific option.
86
         * Options recognized by DefaultFormRenderer
87
         * - 'label' - textual or Nette\HtmlStringable object label
88
         * - 'visual' - indicates visual group
89
         * - 'container' - container as Html object
90
         * - 'description' - textual or Nette\HtmlStringable object description
91
         * - 'embedNext' - describes how render next group
92
         */
93
        public function setOption(string $key, mixed $value): static
1✔
94
        {
95
                if ($value === null) {
1✔
96
                        unset($this->options[$key]);
1✔
97

98
                } else {
99
                        $this->options[$key] = $value;
1✔
100
                }
101

102
                return $this;
1✔
103
        }
104

105

106
        /**
107
         * Returns user-specific option.
108
         */
109
        public function getOption(string $key): mixed
1✔
110
        {
111
                return $this->options[$key] ?? null;
1✔
112
        }
113

114

115
        /**
116
         * Returns user-specific options.
117
         * @return array<string, mixed>
118
         */
119
        public function getOptions(): array
120
        {
121
                return $this->options;
1✔
122
        }
123
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc