src/Node/Node.php
public function addChild(NodeInterface $child, bool $setParent = true): NodeInterface
    {
        if (!$this->supportsChild($child)) {
            throw ChildTypeNotSupportedException::create($this, $child);
        }

        $this->_children[$child->getId()] = $child;

        if ($setParent) {
            $child->addParent($this, false);
        }

        /** @var NodeInterface $parent */
        foreach ($this->getAllParentsAndCurrentNode() as $parent) {
            $child->addSubscriber($parent);
        }

        $this->notifySubscribers(
            self::EVENT_ADD_CHILD,
            ['parent' => $this, 'child' => $child]
        );

        return $this;
    }
public function addChild(NodeInterface $child, bool $setParent = true): NodeInterface
    {
        if (!$this->supportsChild($child)) {
            throw ChildTypeNotSupportedException::create($this, $child);
        }

        $this->_children[$child->getId()] = $child;

        if ($setParent) {
            $child->addParent($this, false);
        }

        /** @var NodeInterface $parent */
        foreach ($this->getAllParentsAndCurrentNode() as $parent) {
            $child->addSubscriber($parent);
        }

        $this->notifySubscribers(
            self::EVENT_ADD_CHILD,
            ['parent' => $this, 'child' => $child]
        );

        return $this;
    }
public function addChild ( NodeInterface $ child , bool $ setParent = true ) : NodeInterface { if ( ! $ this -> supportsChild ( $ child ) ) { throw ChildTypeNotSupportedException :: create ( $ this , $ child ) ; } $ this -> _children [ $ child -> getId ( ) ] = $ child ; if ( $ setParent ) { $ child -> addParent ( $ this , false ) ; } /** @var NodeInterface $parent */ foreach ( $ this -> getAllParentsAndCurrentNode ( ) as $ parent ) { $ child -> addSubscriber ( $ parent ) ; } $ this -> notifySubscribers ( self :: EVENT_ADD_CHILD , [ 'parent' => $ this , 'child' => $ child ] ) ; return $ this ; }
Adds a child to this node.

@param NodeInterface $child - Child.
@param bool $setChildParent - Set child's parent.

@throws ChildTypeNotSupportedException

@return NodeInterface
Adds a child to this node .