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')); 
  • one
    what is the actual question? - Redr01d
  • question on the getNode method ($ nodeName) As far as I understand, you need to recursively search for a key ($ nodeName) in the $ tree-> nodes array, or should there be other logic? - Kirill
  • Well, if you have a multidimensional array there without an external index, then you will need to iterate over the array to get the desired id. But how does this relate to composite? - Redr01d

0