c2ec1c97c9
A poor man's formatter since I didn't like any of the other ones I found. The original C++ source sometimes put newlines and sometimes not.
Codemods:
codemod '([;{}])([^\n])' '\1\n\2'
codemod -m '\s*<\?php\s+' '<?php\n\n'
codemod '\t' ' '
I hand-fixed all the failing tests
32 linhas
867 B
PHP
32 linhas
867 B
PHP
<?php
|
|
|
|
class books extends domDocument {
|
|
function addBook($title, $author) {
|
|
$titleElement = $this->createElement('title');
|
|
$titleElement->appendChild($this->createTextNode($title));
|
|
$authorElement = $this->createElement('author');
|
|
$authorElement->appendChild($this->createTextNode($author));
|
|
$bookElement = $this->createElement('book');
|
|
$bookElement->appendChild($titleElement);
|
|
$bookElement->appendChild($authorElement);
|
|
$this->documentElement->appendChild($bookElement);
|
|
}
|
|
}
|
|
|
|
$dom = new books;
|
|
|
|
$xml = <<<EOM
|
|
<?xml version='1.0' ?>
|
|
<books>
|
|
<book>
|
|
<title>The Grapes of Wrath</title>
|
|
<author>John Steinbeck</author>
|
|
</book> <book>
|
|
<title>The Pearl</title> <author>John Steinbeck</author>
|
|
</book></books>
|
|
EOM;
|
|
|
|
$dom->loadXML($xml);
|
|
$dom->addBook('PHP de Luxe', 'Richard Samar, Christian Stocker');
|
|
print $dom->saveXML();
|