4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Form
;
14 use Symfony\Component\Form\Exception\BadMethodCallException
;
17 * @author Bernhard Schussek <bschussek@gmail.com>
19 class FormView
implements \ArrayAccess
, \IteratorAggregate
, \Countable
22 * The variables assigned to this view.
40 public $children = array();
43 * Is the form attached to this renderer rendered?
45 * Rendering happens when either the widget or the row method was called.
46 * Row implicitly includes widget, however certain rendering mechanisms
47 * have to skip widget rendering when a row is rendered.
51 private $rendered = false;
53 public function __construct(FormView
$parent = null)
55 $this->parent
= $parent;
59 * Returns whether the view was already rendered.
61 * @return Boolean Whether this view's widget is rendered.
63 public function isRendered()
65 $hasChildren = 0 < count($this->children
);
67 if (true === $this->rendered
|| !$hasChildren) {
68 return $this->rendered
;
72 foreach ($this->children
as $child) {
73 if (!$child->isRendered()) {
78 return $this->rendered
= true;
85 * Marks the view as rendered.
87 * @return FormView The view object.
89 public function setRendered()
91 $this->rendered
= true;
97 * Returns a child by name (implements \ArrayAccess).
99 * @param string $name The child name
101 * @return FormView The child view
103 public function offsetGet($name)
105 return $this->children
[$name];
109 * Returns whether the given child exists (implements \ArrayAccess).
111 * @param string $name The child name
113 * @return Boolean Whether the child view exists
115 public function offsetExists($name)
117 return isset($this->children
[$name]);
121 * Implements \ArrayAccess.
123 * @throws BadMethodCallException always as setting a child by name is not allowed
125 public function offsetSet($name, $value)
127 throw new BadMethodCallException('Not supported');
131 * Removes a child (implements \ArrayAccess).
133 * @param string $name The child name
135 public function offsetUnset($name)
137 unset($this->children
[$name]);
141 * Returns an iterator to iterate over children (implements \IteratorAggregate)
143 * @return \ArrayIterator The iterator
145 public function getIterator()
147 return new \
ArrayIterator($this->children
);
151 * Implements \Countable.
153 * @return integer The number of children views
155 public function count()
157 return count($this->children
);