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: namespace Nette\Forms;
9:
10: use Nette;
11:
12:
13: /**
14: * A user group of form controls.
15: */
16: class ControlGroup extends Nette\Object
17: {
18: /** @var \SplObjectStorage */
19: protected $controls;
20:
21: /** @var array user options */
22: private $options = array();
23:
24:
25: public function __construct()
26: {
27: $this->controls = new \SplObjectStorage;
28: }
29:
30:
31: /**
32: * @return static
33: */
34: public function add()
35: {
36: foreach (func_get_args() as $num => $item) {
37: if ($item instanceof IControl) {
38: $this->controls->attach($item);
39:
40: } elseif ($item instanceof \Traversable || is_array($item)) {
41: call_user_func_array(array($this, 'add'), is_array($item) ? $item : iterator_to_array($item));
42:
43: } else {
44: $type = is_object($item) ? get_class($item) : gettype($item);
45: throw new Nette\InvalidArgumentException("IControl items expected, $type given.");
46: }
47: }
48: return $this;
49: }
50:
51:
52: /**
53: * @return IControl[]
54: */
55: public function getControls()
56: {
57: return iterator_to_array($this->controls);
58: }
59:
60:
61: /**
62: * Sets user-specific option.
63: * Options recognized by DefaultFormRenderer
64: * - 'label' - textual or Html object label
65: * - 'visual' - indicates visual group
66: * - 'container' - container as Html object
67: * - 'description' - textual or Html object description
68: * - 'embedNext' - describes how render next group
69: *
70: * @param string key
71: * @param mixed value
72: * @return static
73: */
74: public function setOption($key, $value)
75: {
76: if ($value === NULL) {
77: unset($this->options[$key]);
78:
79: } else {
80: $this->options[$key] = $value;
81: }
82: return $this;
83: }
84:
85:
86: /**
87: * Returns user-specific option.
88: * @param string key
89: * @param mixed default value
90: * @return mixed
91: */
92: public function getOption($key, $default = NULL)
93: {
94: return isset($this->options[$key]) ? $this->options[$key] : $default;
95: }
96:
97:
98: /**
99: * Returns user-specific options.
100: * @return array
101: */
102: public function getOptions()
103: {
104: return $this->options;
105: }
106:
107: }
108: