type = $type; $this->children = $children; $this->position = $position; } public function toDebugString() { return implode( "\n", $this->toDebugStringInner() ); } private function toDebugStringInner() { if ( $this->type == self::ATOM ) { return [ "ATOM({$this->children->type} {$this->children->value})" ]; } $align = function ( $line ) { return ' ' . $line; }; $lines = [ "{$this->type}" ]; foreach ( $this->children as $subnode ) { if ( $subnode instanceof AFPTreeNode ) { $sublines = array_map( $align, $subnode->toDebugStringInner() ); } elseif ( is_string( $subnode ) ) { $sublines = [ " {$subnode}" ]; } else { throw new AFPException( "Each node parameter has to be either a node or a string" ); } $lines = array_merge( $lines, $sublines ); } return $lines; } }