setId($this->nextChildId(), $this->getId(), $this->getPath()); $this->children[] = $comp; return $comp; } function remove(FormositeComponent $comp) { $index = array_search($comp, $this->children, true); if ($index === false) { return false; } array_splice($this->children, $index, 1); return true; } function __clone() { $kids = array(); foreach ($this->children as $child) { $kids[] = clone($child); } $this->children = $kids; } function number() { $total = 1; foreach ($this->children as $child) { $total += $child->number(); } return $total; } function nextChildId() { $nb = sizeof($this->children) + 1; return $nb; } function getId() { return $this->id; } function getPath() { return $this->path; } function accept(FormositeVisitor $visitor, $level = 1) { $visitor->visit($this, $level); foreach ($this->children as $child) { $child->accept($visitor, $level + 1); } } /** * Sortie standard */ public function output($level = 0) { $pad = $this->pad($level); echo "{$pad} [niv. {$level}] "; if (!is_null($this->id)) { echo "{$this->id}\n
"; } foreach ($this->children as $child) { $child->output($level + 1); } } } ?>