Пример #1
0
    public function testRetrievingMethodsShouldReturnClassMethodObjects()
    {
        $methods = $this->parser->getMethods();

        $this->assertEquals(count($this->class->getMethods(\ReflectionMethod::IS_PUBLIC)), count($methods));
        foreach ($methods as $method) {
            $this->assertInstanceOf('Zend\DocBook\ClassMethod', $method);
        }
    }
Пример #2
0
    public function testGeneratesEntriesForEachPublicMethod()
    {
        $docBook = $this->generator->generate();
        $dom     = new DOMDocument();
        $dom->loadXML($docBook);
        $xpath = new DOMXPath($dom);
        $xpath->registerNamespace('docbook', 'http://docbook.org/ns/docbook');

        $baseId  = 'zend-test.doc-book.test-asset.parsed-class.methods';
        $methods = $this->parser->getMethods();

        // Get list of varlistentry items
        $nodes = $xpath->query(
            '//docbook:section[@xml:id="' . $baseId . '"]/docbook:variablelist/docbook:varlistentry');

        $this->assertEquals(count($methods), $nodes->length);

        // Get varlistentry IDs, methodnames, and funcparams
        for ($i = 0; $i < $nodes->length; $i++) {
            $xml    = $dom->saveXML($nodes->item($i));
            $method = $methods[$i];

            $this->assertContains($method->getId(), $xml);

            $prototype = $method->getPrototype();
            if (empty($prototype)) {
                $this->assertContains('<funcparams/>', $xml);
            } else {
                $this->assertContains('<funcparams>' . $prototype . '</funcparams>', $xml, $xml);
            }
            $this->assertContains($method->getReturnType(), $xml);

            $short = $method->getShortDescription();
            if (empty($short)) {
                $this->assertContains('<para/>', $xml);
            } else {
                $this->assertContains($short, $xml);
            }

            $long = $method->getLongDescription();
            if (!empty($long)) {
                $this->assertContains($long, $xml);
            }
        }
    }
Пример #3
0
// Valid class name?
$class = $opts->c;
if (!class_exists($class) && !interface_exists($class)) {
    // Invalid class name == no execution
    printf("Invalid class '%s' provided' class not found\n\n", $class);
    echo $opts->getUsageMessage();
    exit(2);
}

// Was a specific filename provided for the generated output?
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);
Пример #4
0
 /**
  * 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();
 }