/** * Adds a child to the class at the given index * * @param AbstractPattern $child Child to add * @param int $index Index * * @return AbstractContainer */ public function addChildAt(AbstractPattern $child, $index = null) { $child->setParent($this); if ($index === null) { $this->_children[] = $child; } elseif (isset($this->_children[$index])) { array_splice($this->_children, $index, 0, array($child)); } else { $this->_children[$index] = $child; ksort($this->_children); } return $this; }