Source for file Converter.inc
Documentation is available at Converter.inc
* Base class for all Converters
* phpDocumentor :: automatic documentation generator
* Copyright (c) 2001-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 2001-2006 Gregory Beaver
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @version CVS: $Id: Converter.inc,v 1.39 2007/12/19 02:16:49 ashnazg Exp $
* @link http://www.phpdoc.org
* @link http://pear.php.net/PhpDocumentor
* @see parserDocBlock, parserInclude, parserPage, parserClass
* @see parserDefine, parserFunction, parserMethod, parserVar
include_once("phpDocumentor/Smarty-2.6.0/libs/Smarty.class.php");
* Base class for all output converters.
* The Converter marks the final stage in phpDocumentor. phpDocumentor works
* <pre>Parsing => Intermediate Parsing organization => Conversion to output</pre>
* A Converter takes output from the {@link phpDocumentor_IntermediateParser} and
* converts it to output. With version 1.2, phpDocumentor includes a variety
* <li>{@link HTMLframesConverter}</li>
* <li>{@link HTMLSmartyConverter}</li>
* <li>{@link PDFdefaultConverter}</li>
* <li>{@link CHMdefaultConverter}</li>
* <li>{@link CSVdia2codeConverter}</li>
* <li>{@link XMLDocBookConverter}</li>
* The converter takes output directly from {@link phpDocumentor_IntermediateParser}
* and using {@link walk()} or {@link walk_everything} (depending on the value of
* {@link $sort_absolutely_everything}) it "walks" over an array of phpDocumentor elements.}}}
* @author Greg Beaver <cellog@php.net>
* @version $Id: Converter.inc,v 1.39 2007/12/19 02:16:49 ashnazg Exp $
* This converter knows about the new root tree processing
* In order to fix PEAR Bug #6389
* output format of this converter
* in Child converters, this will match the first part of the -o command-line
* as in -o HTML:frames:default "HTML"
* @tutorial phpDocumentor.howto.pkg#using.command-line.output
* package name currently being converted
* subpackage name currently being converted
* set to a classname if currently parsing a class, false if not
* the workhorse of linking.
* This array is an array of link objects of format:
* [package][subpackage][eltype][elname] = descendant of {@link abstractLink}
* eltype can be page|function|define|class|method|var
* if eltype is method or var, the array format is:
* [package][subpackage][eltype][class][elname]
* @see functionLink, pageLink, classLink, defineLink, methodLink, varLink, globalLink
* the workhorse of linking, with allowance for support of multiple
* elements in different files.
* This array is an array of link objects of format:
* [package][subpackage][eltype][file][elname] = descendant of {@link abstractLink}
* eltype can be function|define|class|method|var
* if eltype is method or var, the array format is:
* [package][subpackage][eltype][file][class][elname]
* @see functionLink, pageLink, classLink, defineLink, methodLink, varLink, globalLink
var $linkswithfile = array();
* set to value of -po commandline
* @tutorial phpDocumentor.howto.pkg#using.command-line.packageoutput
* name of current page being converted
* path of current page being converted
* template for the procedural page currently being processed
* template for the class currently being processed
* current procedural page being processed
* alphabetical index of all elements sorted by package, subpackage, page,
* @var array Format: array(package => array(subpackage => array('page'|'class' => array(path|classname => array(element, element,...)))))
* @uses $sort_absolutely_everything if true, then $package_elements is used,
* otherwise, the {@link ParserData::$classelements} and
* {@link ParserData::$pageelements} variables are used
* alphabetical index of all elements
* @var array Format: array(first letter of element name => array({@link parserElement} or {@link parserPage},...))
* @see formatIndex(), HTMLframesConverter::formatIndex()
* alphabetized index of procedural pages by package
* @var array Format: array(package => array(subpackage => array({@link pageLink} 1,{@link pageLink} 2,...)
* alphabetized index of defines by package
* @var array Format: array(package => array(subpackage => array({@link defineLink} 1,{@link defineLink} 2,...)
* alphabetized index of classes by package
* @var array Format: array(package => array(subpackage => array({@link classLink} 1,{@link classLink} 2,...)
* alphabetized index of global variables by package
* @var array Format: array(package => array(subpackage => array({@link globalLink} 1,{@link globalLink} 2,...)
* alphabetized index of functions by package
* @var array Format: array(package => array(subpackage => array({@link functionLink} 1,{@link functionLink} 2,...)
* alphabetical index of all elements, indexed by package/subpackage
* @var array Format: array(first letter of element name => array({@link parserElement} or {@link parserPage},...))
* @see formatPkgIndex(), HTMLframesConverter::formatPkgIndex()
* alphabetical index of all elements on a page by package/subpackage
* The page itself has a link under ###main
* @var array Format: array(package => array(subpackage => array(path => array({@link abstractLink} descendant 1, ...)))
* This determines whether the {@link $page_contents} array should be sorted by element type as well as alphabetically by name
* @see sortPageContentsByElementType()
* This is used if the content must be passed in the order it should be read, i.e. by package, procedural then classes
* This fixes bug 637921, and is used by {@link PDFdefaultConverter}
* alphabetical index of all methods and vars in a class by package/subpackage
* The class itself has a link under ###main
* array({@link abstractLink} descendant 1, ...
* controls processing of elements marked private with @access private
* defaults to false. Set with command-line --parseprivate or -pp
* controls display of progress information while parsing.
* defaults to false. Set to true for cron jobs or other situations where no visual output is necessary
* directory that output is sent to. -t command-line sets this.
* @tutorial phpDocumentor.howto.pkg#using.command-line.target
* Directory that the template is in, relative to phpDocumentor root directory
* Directory that the smarty templates are in
* Name of the template, from last part of -o
* @tutorial phpDocumentor.howto.pkg#using.command-line.output
* full path of the current file being converted
* All class information, organized by path, and by package
* Flag used to help converters determine whether to do special source highlighting
* Every package that contains classes may have parent or child classes
* in other packages. In other words, this code is legal:
* class two extends one {}
* In this case, package one is a parent of package two
* @see phpDocumentor_IntermediateParser::$package_parents
* Packages associated with categories
* Used by the XML:DocBook/peardoc2 converter, and available to others, to
* group many packages into categories
* @see phpDocumentor_IntermediateParser::$packagecategories
* All packages encountered in parsing
* @see phpDocumentor_IntermediateParser::$all_packages
* A list of files that have had source code generated
* Controls which of the one-element-only indexes are generated.
* Generation of these indexes for large packages is time-consuming. This is an optimization feature. An
* example of how to use this is in {@link HTMLframesConverter::$leftindex}, and in {@link HTMLframesConverter::formatLeftIndex()}.
* These indexes are intended for use as navigational aids through documentation, but can be used for anything by converters.
* @see $class_elements, $page_elements, $function_elements, $define_elements, $global_elements
var $leftindex = array('classes' => true, 'pages' => true, 'functions' => true, 'defines' => true, 'globals' => true);
* @see phpDocumentor_IntermediateParser::$title
var $title = 'Generated Documentation';
* Options for each template, parsed from the options.ini file in the template base directory
* @tutorial phpDocumentor/tutorials.pkg#conversion.ppage
* Tutorials and Extended Documentation parsed from a tutorials/package[/subpackage] directory
* @tutorial tutorials.pkg
var $tutorials = array();
* tree-format structure of tutorials and their child tutorials, if any
var $tutorial_tree = false;
* list of tutorials that have already been processed. Used by @link _setupTutorialTree()
var $processed_tutorials;
* List of all @todo tags and a link to the element with the @todo
* Format: array(package => array(link to element, array(todo {@link parserTag},...)),...)
* @tutorial tags.todo.pkg
* Directory where compiled templates go - will be deleted on exit
var $_compiledDir = array();
* Initialize Converter data structures
* @param array {@link $all_packages} value
* @param array {@link $package_parents} value
* @param Classes {@link $classes} value
* @param ProceduralPages {@link $proceduralpages} value
* @param array {@link $package_output} value
* @param boolean {@link $parseprivate} value
* @param boolean {@link $quietmode} value
* @param string {@link $targetDir} value
* @param string {@link $templateDir} value
* @param string (@link $title} value
function Converter(&$allp, &$packp, &$classes, &$procpages, $po, $pp, $qm, $targetDir, $template, $title)
$this->package = $GLOBALS['phpDocumentor_DefaultPackageName'];
$this->proceduralpages = &$procpages;
$this->setTargetdir($targetDir);
* Called by IntermediateParser after creation
function setTutorials($tutorials)
$this->tutorials = $tutorials;
* @param pkg|cls|procthe tutorial type to search for
* @param string package name
* @param string subpackage name, if any
* @return false|parserTutorialif the tutorial exists, return it
function hasTutorial($type, $name, $package, $subpackage = '')
if (isset ($this->tutorials[$package][$subpackage][$type][$name . '.' . $type]))
return $this->tutorials[$package][$subpackage][$type][$name . '.' . $type];
* Called by {@link walk()} while converting, when the last class element
* A Converter can use this method in any way it pleases. HTMLframesConverter
* uses it to complete the template for the class and to output its
* @see HTMLframesConverter::endClass()
* Called by {@link walk()} while converting, when the last procedural page
* element has been parsed.
* A Converter can use this method in any way it pleases. HTMLframesConverter
* uses it to complete the template for the procedural page and to output its
* @see HTMLframesConverter::endClass()
* Called by {@link walk()} while converting.
* This method is intended to be the place that {@link $pkg_elements} is
* @see HTMLframesConverter::formatPkgIndex()
* Called by {@link walk()} while converting.
* This method is intended to be the place that {@link $elements} is
* @see HTMLframesConverter::formatIndex()
* Called by {@link walk()} while converting.
* This method is intended to be the place that any of
* {@link $class_elements, $function_elements, $page_elements},
* {@link $define_elements}, and {@link $global_elements} is formatted for
* output, depending on the value of {@link $leftindex}
* @see HTMLframesConverter::formatLeftIndex()
* Called by {@link parserSourceInlineTag::stringConvert()} to allow
* converters to format the source code the way they'd like.
* default returns it unchanged (html with xhtml tags)
* @param string output from highlight_string() - use this function to
* reformat the returned data for Converter-specific output
* @deprecated in favor of tokenizer-based highlighting. This will be
* Initialize highlight caching
$this->_highlightCache = array(false, false);
$this->_appendHighlight = '';
return $this->_highlightCache;
$test = ($this->_highlightCache[0] === $type && $this->_highlightCache[1] == $token);
$this->_appendHighlight = '';
$this->_highlightCache = array($type, $token);
* Return the close text for the current token
$hc = $this->_highlightCache;
$this->_highlightCache = array(false, false);
* Used to allow converters to format the source code the way they'd like.
* default returns it unchanged. Mainly used by the {@link HighlightParser}
* The method takes information from options.ini, the template options
* file, specifically the [highlightSourceTokens] and [highlightSource]
* sections, and uses them to enclose tokens.
* @param integer token value from {@link PHP_MANUAL#tokenizer tokenizer constants}
* @param string contents of token
* @param boolean whether the contents are preformatted or need modification
- <
|