Source for file XMLDocBookpeardoc2Converter.inc
Documentation is available at XMLDocBookpeardoc2Converter.inc
* Outputs documentation in XML DocBook format, in the version expected by
* pear.php.net's documentation team
* phpDocumentor :: automatic documentation generator
* Copyright (c) 2002-2006 Gregory Beaver
* This library is free software; you can redistribute it
* and/or modify it under the terms of the GNU Lesser General
* Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* @author Greg Beaver <cellog@php.net>
* @copyright 2002-2006 Gregory Beaver
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @version CVS: $Id: XMLDocBookpeardoc2Converter.inc,v 1.8 2007/04/24 21:32:15 ashnazg Exp $
* @link http://www.phpdoc.org
* @link http://pear.php.net/PhpDocumentor
* This Converter takes output from the {@link Parser} and converts it to DocBook
* output for PEAR documentation.
* This Converter differs from the parent DocBook Converter in that it does not
* recognize the possibility of procedural pages or of functions! All functions
* must be defined as static methods for namespace purposes. In addition, all
* constants and global variables for a package are grouped together as per
* peardoc2 requirements. Include statements are not documented. If you want
* to document a normal project, don't use the peardoc2 converter, use the
* @author Greg Beaver <cellog@php.net>
* @version $Id: XMLDocBookpeardoc2Converter.inc,v 1.8 2007/04/24 21:32:15 ashnazg Exp $
* This converter knows about the new root tree processing
* In order to fix PEAR Bug #6389
* XMLDocBookConverter wants elements sorted by type as well as alphabetically
* @see Converter::$sort_page_contents_by_type
var $name = 'DocBook/peardoc2';
* indexes of elements by package that need to be generated
var $leftindex = array('classes' => true, 'pages' => false, 'functions' => false, 'defines' => true, 'globals' => true);
* whether a @see is going to be in the {@link $base_dir}, or in a package/subpackage subdirectory of $base_dir
* name of current page being converted
* path of current page being converted
* name of current class being converted
* template for the procedural page currently being processed
* output directory for the current procedural page being processed
* Constants, used for constants.tpl
* Global Variables, used for globals.tpl
* target directory passed on the command-line.
* {@link $targetDir} is malleable, always adding package/ and package/subpackage/ subdirectories onto it.
* output directory for the current class being processed
* template for the class currently being processed
* array of converted package page names.
* Used to link to the package page in the left index
* @var array Format: array(package => 1)
* Contents of the packagename.xml file are stored in this template variable
* controls formatting of parser informative output
* "Converting /path/to/file.php... Procedural Page Elements... Classes..."
* Since HTMLdefaultConverter outputs files while converting, it needs to send a \n to start a new line. However, if there
* is more than one class, output is messy, with multiple \n's just between class file output. This variable prevents that
* contains all of the template procedural page element loop data needed for the current template
* contains all of the template class element loop data needed for the current template
* Pass elements by package, simplifies generation of package.xml/category.xml
* template options. Currently only 1 recognized option usepear
* usepear tells the getLink() function to return a package link to PEAR and PEAR_ERROR if possible, and to link directly
* to the fully-delimited link package#class.method or package#file.method in PEAR style, if possible, even if the
* package is not parsed. This will allow parsing of separate PEAR packages without parsing the entire thing at once!
* Used to re-format output so that it's easy for translators to handle
* @var XML_Beautifier|false
var $_beautifier = false;
* sets {@link $base_dir} to $targetDir
@include_once 'XML/Beautifier.php';
Converter::Converter($allp, $packp, $classes, $procpages,$po, $pp, $qm, $targetDir, $templateDir, $title);
require_once 'phpDocumentor/Converters/XML/DocBook/peardoc2/Beautifier.php';
$this->_beautifier->setOption('indent', ' ');
* do that stuff in $template_options
function &getLink($expr, $package = false, $packages = false)
return '<programlisting role="php"><![CDATA[
'. $sourcecode. ']]></programlisting>';
* Writes a file to target dir, beautify any .xml files first
* @param string file contents
* @param boolean true if the data is binary and not text
function writeFile($file,$data,$binary = false)
if ($this->_beautifier && substr($file, - 4) == '.xml') {
$ret = $this->_beautifier->formatString($data);
if (PEAR::isError($ret)) {
return parent::writeFile($file, $data, $binary);
* Used to convert the {@}example} inline tag in a docblock.
* By default, this just wraps ProgramExample
* @see XMLDocBookpeardoc2Converter::exampleProgramExample
* @param boolean true if this is to highlight a tutorial <programlisting>
$class = null/*false*/, $linenum = null/*false*/, $filesourcepath = null/*false*/)
return '<example><title>Example</title><programlisting role="php"><![CDATA[' .
$example . ']]></programlisting></example>';
$this->ProgramExample($example, $tutorial, $inlinesourceparse, $class, $linenum, $filesourcepath)
$this->_save_example = array($title, $source);
$source = $this->_save_example[1];
return '<para><example><title>' . $title . '</title>' . $source . '</example></para>';
return '<classname>'. $typename. '</classname>';
return '<function>'. $typename. '</function>';
return '<constant>'. $typename. '</constant>';
return '<varname>'. $typename. '</varname>';
* Writes out the template file of {@link $class_data} and unsets the template to save memory
* @see registerCurrentClass()
* @see parent::endClass()
* @todo move class summary into an array to be written out at the end
* of parsing each package
$this->writefile(strtolower($func[1] ). '.xml','<!-- $' . "Revision$ -->\n" . $func[0]->fetch('method.tpl'));
// code below is in packagename.xml handling, see Output()
/* $this->setTargetDir($this->base_dir . PATH_DELIMITER . strtolower($this->category) . PATH_DELIMITER . strtolower($this->class_dir));
$this->writefile(str_replace(array('_','.'),array('-','--'),strtolower($this->class)) . '.xml',$this->class_data->fetch('class.tpl'));*/
$this->packagexml->append('ids',$template_output);
* @param parserClass|false$element is false if this is the end of all conversion
if (!$element || $element->docblock->package != $this->package) // finished with package
'<!-- $' . "Revision$ -->\n" . $this->packagexml->fetch('package.tpl'));
$this->packagexml->assign('package',$element->docblock->package);
$this->packagexml->assign('package',$element->docblock->package);
* @return string <ulink url="'.$link.'">'.$text.'</ulink>
return '<ulink url="'. $link. '">'. $text. '</ulink>';
* Creates package/lang/categoryname/packagename.xml for each package
* This function takes an {@link abstractLink} descendant and returns an html link
* @param abstractLink a descendant of abstractlink should be passed, and never text
* @param string text to display in the link
* @param boolean this parameter is not used, and is deprecated
* @param boolean determines whether the returned text is enclosed in an <link> tag
function returnSee(&$element, $eltext = false, $local = true, $with_a = true)
if (!$element) return false;
$eltext = $element->title;
$eltext = '<classname>'. $element->name. '</classname>';
if ($element->type == 'var') $eltext .= '<varname>';
$eltext .= $element->class. '::';
if ($element->type == 'define')
if ($element->type == 'function')
$eltext .= $element->name;
if ($element->type == 'function' || $element->type == 'method') $eltext .= '</function>';
if ($element->type == 'var') $eltext .= '</varname>';
if ($element->type == 'define') $eltext .= '</constant>';
} elseif ($element->type == 'method')
$eltext = str_replace($element->name . '()', $element->name, $eltext);
if ($element->type == 'page' || $element->type == 'function' || $element->type == 'var')
{ // we ignore all procedural pages, instead, constant, function and
|