/** * Useful -for example- for building xPath strings * * @param string $separator * @return string */ public final function getPathWithSeparator($separator = '/') { if ($this->parent) { return $this->parent->getPathWithSeparator($separator) . $separator . $this->getName(); } else { return $separator . $this->getName(); } }
private function namedCompositeToArray(DataTree $tree) { $result = []; $msgName = $tree->getName(); $result[$msgName] = []; foreach ($tree->getChildren() as $child) { $childName = $child->getName(); if (array_key_exists($childName, $result[$msgName])) { $nodeToMove = $result[$msgName][$childName]; $result[$msgName][$childName] = []; $result[$msgName][$childName][] = $nodeToMove; $leafContent = $this->toArray($child); $result[$msgName][$childName][] = $leafContent[$childName]; } else { $result[$msgName] = array_merge($result[$msgName], $this->toArray($child)); } } return $result; }