/** * Renders input $node as php source code. * * @param string $varName Variable name (optional). * @return string PHP code. */ public static function render(Leaf $node, $varName = '') { // Validate variable name $varName = $varName ? $varName : $node->getID(); $varName = self::checkVariableName($varName); // Object kind $source = '$' . $varName . ' = new \\' . get_class($node) . "([\n" . " 'kind' => '{$node->getKind()}'"; // Object attributes if ($node->hasAttr()) { $source .= ",\n" . self::renderArray($node->getAttr(), 'attr', 1); } // Object child nodes if ($node->hasChildNodes()) { $source = rtrim($source); $source .= "\n" . self::renderChildNodes($node->getChildNodes(), 'child', 1); } // Content $source = rtrim($source); if ($node->hasCont()) { $content = wordwrap($node->getCont(), 90, "\n"); $source .= ",\n 'cont' => '{$content}'"; } // Closing brackets; $source .= "\n]); \n"; return $source; }
public function testShowID() { $newline = PHP_SAPI == 'cli' ? "\n" : "<br/>"; $expected = self::$l->getID() . " | parent: NULL" . $newline; $this->assertEquals($expected, self::$l->showID()); }