src/NodeCollection.php
public function add($item, $prepend = false)
    {
        if (!$item instanceof ChildNodeInterface) {
            $details = is_object($item) ? get_class($item) : gettype($item);
            throw new InvalidArgumentException(
                "NodeCollection accepts only objects implementing ChildNodeInterface, $details given."
            );
        }
        $old = $item->parent();
        if ($old === $this->parentNode) {
            return $this;
        } elseif ($old !== null) {
            $item->detach();
        }
        $this->checkUnlocked($item);
        parent::add($item, $prepend);
        $item->internalSetParent($this->parentNode);

        return $this;
    }
public function add($item, $prepend = false)
    {
        if (!$item instanceof ChildNodeInterface) {
            $details = is_object($item) ? get_class($item) : gettype($item);
            throw new InvalidArgumentException(
                "NodeCollection accepts only objects implementing ChildNodeInterface, $details given."
            );
        }
        $old = $item->parent();
        if ($old === $this->parentNode) {
            return $this;
        } elseif ($old !== null) {
            $item->detach();
        }
        $this->checkUnlocked($item);
        parent::add($item, $prepend);
        $item->internalSetParent($this->parentNode);

        return $this;
    }
public function add ( $ item , $ prepend = false ) { if ( ! $ item instanceof ChildNodeInterface ) { $ details = is_object ( $ item ) ? get_class ( $ item ) : gettype ( $ item ) ; throw new InvalidArgumentException ( "NodeCollection accepts only objects implementing ChildNodeInterface, $details given." ) ; } $ old = $ item -> parent ( ) ; if ( $ old === $ this -> parentNode ) { return $ this ; } elseif ( $ old !== null ) { $ item -> detach ( ) ; } $ this -> checkUnlocked ( $ item ) ; parent :: add ( $ item , $ prepend ) ; $ item -> internalSetParent ( $ this -> parentNode ) ; return $ this ; }
Adds component to collection.

If component is already in collection, it will not be added twice.

@param ChildNodeInterface $item
@param bool               $prepend Pass true to add component to the beginning of an array.

@return $this
Adds component to collection .