class Node { private $name; function __construct($name) { $this->name = $name; } } abstract class Tree { // создает узел (если $parentNode == NULL - корень) abstract protected function createNode(Node $node,$parentNode=NULL); // удаляет узел и все дочерние узлы abstract protected function deleteNode(Node $node); // делает один узел дочерним по отношению к другому abstract protected function attachNode(Node $node,Node $parent); // получает узел по названию abstract protected function getNode($nodeName); // преобразует дерево со всеми элементами в ассоциативный массив abstract protected function export(); } Please help me with the implementation of the Composite pattern (linker)
$tree = new TreeComposite(); $tree->createNode(new Node('country')); $tree->createNode(new Node('UK'),$tree->getNode('country')); $tree->createNode(new Node('RU'),$tree->getNode('country')); $tree->createNode(new Node('msk'),$tree->getNode('RU')); $tree->createNode(new Node('sub'),$tree->getNode('RU'));