private function compileNode(Node $node) : string
    {
        if ($node->isLeaf()) {
            // Don't compile a leaf that is a tag because that means it doesn't have any content
            if ($node->isTag()) {
                return '';
            }

            return $node->getValue() ?: '';
        } else {
            $output = '';

            foreach ($node->getChildren() as $childNode) {
                if ($node->isTag()) {
                    if (!isset($this->elements[$node->getValue()])) {
                        throw new InvalidArgumentException("No style registered for element \"{$node->getValue()}\"");
                    }

                    $style = $this->elements[$node->getValue()];
                    $output .= $style->format($this->compileNode($childNode));
                } else {
                    $output .= $this->compileNode($childNode);
                }
            }

            return $output;
        }
    }
private function compileNode(Node $node) : string
    {
        if ($node->isLeaf()) {
            // Don't compile a leaf that is a tag because that means it doesn't have any content
            if ($node->isTag()) {
                return '';
            }

            return $node->getValue() ?: '';
        } else {
            $output = '';

            foreach ($node->getChildren() as $childNode) {
                if ($node->isTag()) {
                    if (!isset($this->elements[$node->getValue()])) {
                        throw new InvalidArgumentException("No style registered for element \"{$node->getValue()}\"");
                    }

                    $style = $this->elements[$node->getValue()];
                    $output .= $style->format($this->compileNode($childNode));
                } else {
                    $output .= $this->compileNode($childNode);
                }
            }

            return $output;
        }
    }
private function compileNode ( Node $ node ) : string { if ( $ node -> isLeaf ( ) ) { // Don't compile a leaf that is a tag because that means it doesn't have any content if ( $ node -> isTag ( ) ) { return '' ; } return $ node -> getValue ( ) ? : '' ; } else { $ output = '' ; foreach ( $ node -> getChildren ( ) as $ childNode ) { if ( $ node -> isTag ( ) ) { if ( ! isset ( $ this -> elements [ $ node -> getValue ( ) ] ) ) { throw new InvalidArgumentException ( "No style registered for element \"{$node->getValue()}\"" ) ; } $ style = $ this -> elements [ $ node -> getValue ( ) ] ; $ output .= $ style -> format ( $ this -> compileNode ( $ childNode ) ) ; } else { $ output .= $ this -> compileNode ( $ childNode ) ; } } return $ output ; } }
Recursively compiles a node and its children

@param Node $node The node to compile
@return string The compiled node
@throws RuntimeException Thrown if there was an error compiling the node
@throws InvalidArgumentException Thrown if there is no matching element for a particular tag
Recursively compiles a node and its children