/** * Singleton. * * This avoids instantiating multiple Text_Wiki instances where a number * of objects are required in one call, e.g. to save memory in a * CMS invironment where several parsers are required in a single page. * * $single = & singleton(); * * or * * $single = & singleton('Parser', array('Prefilter', 'Delimiter', 'Code', 'Function', * 'Html', 'Raw', 'Include', 'Embed', 'Anchor', 'Heading', 'Toc', 'Horiz', * 'Break', 'Blockquote', 'List', 'Deflist', 'Table', 'Image', 'Phplookup', * 'Center', 'Newline', 'Paragraph', 'Url', 'Freelink', 'Interwiki', 'Wikilink', * 'Colortext', 'Strong', 'Bold', 'Emphasis', 'Italic', 'Underline', 'Tt', * 'Superscript', 'Subscript', 'Revise', 'Tighten')); * * Call using a subset of this list. The order of passing rulesets in the * $rules array is important! * * After calling this, call $single->setParseConf(), setRenderConf() or setFormatConf() * as usual for a constructed object of this class. * * The internal static array of singleton objects has no index on the parser * rules, the only index is on the parser name. So if you call this multiple * times with different rules but the same parser name, you will get the same * static parser object each time. * * @access public * @static * @since Method available since Release 1.1.0 * @param string $parser The parser to be used (defaults to 'Default'). * @param array $rules The set of rules to instantiate the object. This * will only be used when the first call to singleton is made, if included * in further calls it will be effectively ignored. * @return &object a reference to the Text_Wiki unique instantiation. */ function &singleton($parser = 'Default', $rules = null) { static $only = array(); if (!isset($only[$parser])) { $ret =& Text_Wiki::factory($parser, $rules); if (Text_Wiki::isError($ret)) { return $ret; } $only[$parser] =& $ret; } return $only[$parser]; }