1: <?php
2:
3: /**
4: * This file is part of the Nette Framework (https://nette.org)
5: * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
6: * @package Nette\Forms
7: */
8:
9:
10:
11: /**
12: * A user group of form controls.
13: *
14: * @author David Grudl
15: *
16: * @property-read array $controls
17: * @property-read array $options
18: * @package Nette\Forms
19: */
20: class FormGroup extends Object
21: {
22: /** @var SplObjectStorage */
23: protected $controls;
24:
25: /** @var array user options */
26: private $options = array();
27:
28:
29: public function __construct()
30: {
31: $this->controls = new SplObjectStorage;
32: }
33:
34:
35: /**
36: * @return self
37: */
38: public function add()
39: {
40: foreach (func_get_args() as $num => $item) {
41: if ($item instanceof IFormControl) {
42: $this->controls->attach($item);
43:
44: } elseif ($item instanceof Traversable || is_array($item)) {
45: foreach ($item as $control) {
46: $this->controls->attach($control);
47: }
48:
49: } else {
50: throw new InvalidArgumentException("Only IFormControl items are allowed, the #$num parameter is invalid.");
51: }
52: }
53: return $this;
54: }
55:
56:
57: /**
58: * @return array IFormControl
59: */
60: public function getControls()
61: {
62: return iterator_to_array($this->controls);
63: }
64:
65:
66: /**
67: * Sets user-specific option.
68: * Options recognized by DefaultFormRenderer
69: * - 'label' - textual or Html object label
70: * - 'visual' - indicates visual group
71: * - 'container' - container as Html object
72: * - 'description' - textual or Html object description
73: * - 'embedNext' - describes how render next group
74: *
75: * @param string key
76: * @param mixed value
77: * @return self
78: */
79: public function setOption($key, $value)
80: {
81: if ($value === NULL) {
82: unset($this->options[$key]);
83:
84: } else {
85: $this->options[$key] = $value;
86: }
87: return $this;
88: }
89:
90:
91: /**
92: * Returns user-specific option.
93: * @param string key
94: * @param mixed default value
95: * @return mixed
96: */
97: public function getOption($key, $default = NULL)
98: {
99: return isset($this->options[$key]) ? $this->options[$key] : $default;
100: }
101:
102:
103: /**
104: * Returns user-specific options.
105: * @return array
106: */
107: public function getOptions()
108: {
109: return $this->options;
110: }
111:
112: }
113: