/**
  * Generate docbook
  *
  * @return string
  */
 public function generate()
 {
     $baseId = $this->parser->getId();
     $dom = new DOMDocument('1.0', 'utf-8');
     $dom->formatOutput = true;
     $root = $dom->createElement('section');
     $root->setAttribute('xmlns', 'http://docbook.org/ns/docbook');
     $root->setAttribute('version', '5.0');
     $root->setAttribute('xml:id', $baseId);
     $info = $dom->createElement('info');
     $title = $dom->createElement('title', $this->parser->getName());
     $info->appendChild($title);
     $root->appendChild($info);
     $overview = $dom->createElement('section');
     $overview->setAttribute('xml:id', $baseId . '.intro');
     $info = $dom->createElement('info');
     $title = $dom->createElement('title', 'Overview');
     $info->appendChild($title);
     $overview->appendChild($info);
     $root->appendChild($overview);
     $quickstart = $dom->createElement('section');
     $quickstart->setAttribute('xml:id', $baseId . '.quick-start');
     $info = $dom->createElement('info');
     $title = $dom->createElement('title', 'Quick Start');
     $info->appendChild($title);
     $quickstart->appendChild($info);
     $root->appendChild($quickstart);
     $options = $dom->createElement('section');
     $options->setAttribute('xml:id', $baseId . '.options');
     $info = $dom->createElement('info');
     $title = $dom->createElement('title', 'Configuration Options');
     $info->appendChild($title);
     $options->appendChild($info);
     $varlist = $dom->createElement('variablelist');
     $title = $dom->createElement('title');
     $varlist->appendChild($title);
     $options->appendChild($varlist);
     $root->appendChild($options);
     $methods = $dom->createElement('section');
     $methods->setAttribute('xml:id', $baseId . '.methods');
     $info = $dom->createElement('info');
     $title = $dom->createElement('title', 'Available Methods');
     $info->appendChild($title);
     $methods->appendChild($info);
     $varlist = $dom->createElement('variablelist');
     foreach ($this->parser->getMethods() as $method) {
         $entry = $dom->createElement('varlistentry');
         $entry->setAttribute('xml:id', $method->getId());
         $term = $dom->createElement('term', $method->getName());
         $item1 = $dom->createElement('listitem');
         $synop = $dom->createElement('methodsynopsis');
         $mname = $dom->createElement('methodname', $method->getName());
         $mparam = $dom->createElement('methodparam');
         $fparam = $dom->createElement('funcparams', $method->getPrototype());
         $mparam->appendChild($fparam);
         $synop->appendChild($mname);
         $synop->appendChild($mparam);
         $item1->appendChild($synop);
         $item2 = $dom->createElement('listitem');
         $item2->appendChild($dom->createElement('para', $method->getShortDescription()));
         $item2->appendChild($dom->createElement('para', $method->getLongDescription()));
         $item2->appendChild($dom->createElement('para', 'Returns ' . $method->getReturnType()));
         $entry->appendChild($term);
         $entry->appendChild($item1);
         $entry->appendChild($item2);
         $varlist->appendChild($entry);
     }
     $methods->appendChild($varlist);
     $root->appendChild($methods);
     $examples = $dom->createElement('section');
     $examples->setAttribute('xml:id', $baseId . '.examples');
     $info = $dom->createElement('info');
     $title = $dom->createElement('title', 'Examples');
     $info->appendChild($title);
     $examples->appendChild($info);
     $root->appendChild($examples);
     $dom->appendChild($root);
     return $dom->saveXML();
 }
Exemple #2
0
if (isset($opts->o)) {
    $docbookPath = dirname($opts->o);
    $docbookFile = basename($opts->o);
}

$parser    = new ClassParser(new ReflectionClass($class));
$generator = new SkeletonGenerator($parser);
$xml       = $generator->generate();

// Normalize per CS
$xml = strtr($xml, array(
    '  '              => '    ',              // 4 space tabs
    '</info>'         => "</info>\n",         // Extra newline between blocks
    '</section>'      => "</section>\n",
    '</term>'         => "</term>\n",
    '</varlistentry>' => "</varlistentry>\n",
));

// Strip extra whitespace at end of document
$xml = str_replace("</section>\n\n</section>\n", "</section>\n</section>", $xml);

// Write file
if (!$docbookFile) {
    // Auto-generate filename based on class ID
    $docbookFile = $parser->getId() . '.xml';
}
$path = $docbookPath . DIRECTORY_SEPARATOR . $docbookFile;
file_put_contents($path, $xml);

echo "[DONE] Wrote Docbook XML skeleton to $path\n";
Exemple #3
0
 public function testIdShouldBeNormalizedNamespacedClass()
 {
     $id = $this->parser->getId();
     $this->assertEquals('zend-test.doc-book.test-asset.parsed-class', $id);
 }