/** * Create required instance of the Output 'driver'. * * Creates a concrete instance of the renderer depending of $type * * @param object &$parser A concrete instance of the parser * @param string $type (optional) Type of instance required, case insensitive * @param array $conf (optional) A hash containing any additional * configuration information that a subclass might need. * * @return object PHP_CompatInfo_Renderer A concrete PHP_CompatInfo_Renderer * instance, or null on error. * @access public * @since version 1.8.0b2 (2008-06-03) */ function &factory(&$parser, $type = 'array', $conf = array()) { $class = 'PHP_CompatInfo_Renderer_' . ucfirst(strtolower($type)); $file = str_replace('_', '/', $class) . '.php'; /** * Attempt to include our version of the named class, but don't treat * a failure as fatal. The caller may have already included their own * version of the named class. */ if (!PHP_CompatInfo_Renderer::_classExists($class)) { include_once $file; } // If the class exists, return a new instance of it. if (PHP_CompatInfo_Renderer::_classExists($class)) { $instance =& new $class($parser, $conf); } else { $instance = null; } return $instance; }
/** * Null Renderer Class constructor (ZE2) for PHP5+ * * @param object &$parser Instance of the parser (model of MVC pattern) * @param array $conf A hash containing any additional configuration * * @access public * @since version 1.8.0b2 (2008-06-03) */ function __construct(&$parser, $conf) { parent::PHP_CompatInfo_Renderer($parser, $conf); }
/** * Display final results * * Display final results, when data source parsing is over. * * @access public * @return void * @since version 1.8.0b2 (2008-06-03) */ function display() { if ($this->parseData === false) { // invalid data source return; } $version = isset($this->conf['xml']['version']) ? $this->conf['xml']['version'] : '1.0'; $encoding = isset($this->conf['xml']['encoding']) ? $this->conf['xml']['encoding'] : 'UTF-8'; $standalone = isset($this->conf['xml']['standalone']) ? $this->conf['xml']['standalone'] : null; $msg = XML_Util::getXMLDeclaration($version, $encoding, $standalone); $msg .= PHP_EOL; $msg .= XML_Util::createStartElement('pci', array('version' => '1.9.0')); $o = $this->args['output-level']; $v = $this->args['verbose']; $dataSource = $this->_parser->dataSource['dataSource']; $dataType = $this->_parser->dataSource['dataType']; $options = $this->_parser->options; if ($dataType == 'directory' || $dataType == 'array' || $dataType == 'file') { // parsing a directory or a list of files, chunks of code if ($options['is_string'] == false) { if ($dataType == 'directory') { // print <dir> tag $tag = array('qname' => 'dir', 'content' => dirname($dataSource[0])); } else { // print <file> tag $tag = array('qname' => 'file', 'content' => $dataSource[0]); } $msg .= XML_Util::createTagFromArray($tag); $msg .= PHP_EOL; } // print global <version> tag if ($o & 16) { if (empty($this->parseData['max_version'])) { $attr = array(); } else { $attr = array('max' => $this->parseData['max_version']); } $tag = array('qname' => 'version', 'attributes' => $attr, 'content' => $this->parseData['version']); $msg .= XML_Util::createTagFromArray($tag); $msg .= PHP_EOL; } // print global <conditions> tag group if ($o & 1) { $msg .= $this->_printTagList($this->parseData['cond_code'], 'condition'); } // print global <extensions> tag group if ($o & 2) { $msg .= $this->_printTagList($this->parseData['extensions'], 'extension'); } // print global <constants> tag group if ($o & 4) { $msg .= $this->_printTagList($this->parseData['constants'], 'constant'); } // print global <tokens> tag group if ($o & 8) { $msg .= $this->_printTagList($this->parseData['tokens'], 'token'); } // print global <ignored> tag group $msg .= XML_Util::createStartElement('ignored'); $msg .= PHP_EOL; // with children groups <files>, <functions>, <extensions>, <constants> $ignored = array('file' => $this->parseData['ignored_files'], 'function' => $this->parseData['ignored_functions'], 'extension' => $this->parseData['ignored_extensions'], 'constant' => $this->parseData['ignored_constants']); foreach ($ignored as $tag => $data) { $msg .= $this->_printTagList($data, $tag); } $msg .= XML_Util::createEndElement('ignored'); $msg .= PHP_EOL; // remove summary data unset($this->parseData['ignored_files']); unset($this->parseData['ignored_functions']); unset($this->parseData['ignored_extensions']); unset($this->parseData['ignored_constants']); unset($this->parseData['max_version']); unset($this->parseData['version']); unset($this->parseData['classes']); unset($this->parseData['functions']); unset($this->parseData['extensions']); unset($this->parseData['constants']); unset($this->parseData['tokens']); unset($this->parseData['cond_code']); if ($v & 4 || $options['debug'] == true) { // print local <functions> tag group $msg .= $this->_printTagList($this->parseData, 'function'); $entries = array_keys($this->parseData); foreach ($entries as $k) { if (is_numeric($k[0])) { unset($this->parseData[$k]); } } } if ($dataType == 'file') { // parsing a single file $files = array($dataSource[0] => $this->parseData); } else { $files = $this->parseData; } } else { // ... or a chunk of code (string) $files = array($this->parseData); } if ($this->args['summarize'] === false && count($files) > 1) { if ($options['is_string'] == false) { // print <files> tag group $msg .= XML_Util::createStartElement('files', array('count' => count($files))); $msg .= PHP_EOL; } foreach ($files as $file => $this->parseData) { if ($options['is_string'] == true) { $msg .= XML_Util::createStartElement('string', array('name' => $file)); } else { // print local <file> tag $msg .= XML_Util::createStartElement('file', array('name' => $file)); } $msg .= PHP_EOL; // print local <version> tag if ($o & 16) { if (empty($this->parseData['max_version'])) { $attr = array(); } else { $attr = array('max' => $this->parseData['max_version']); } $tag = array('qname' => 'version', 'attributes' => $attr, 'content' => $this->parseData['version']); $msg .= XML_Util::createTagFromArray($tag); $msg .= PHP_EOL; } // print local <conditions> tag group if ($o & 1) { $msg .= $this->_printTagList($this->parseData['cond_code'], 'condition'); } // print local <extensions> tag group if ($o & 2) { $msg .= $this->_printTagList($this->parseData['extensions'], 'extension'); } // print local <constants> tag group if ($o & 4) { $msg .= $this->_printTagList($this->parseData['constants'], 'constant'); } // print local <tokens> tag group if ($o & 8) { $msg .= $this->_printTagList($this->parseData['tokens'], 'token'); } // print local <ignored> tag group $msg .= XML_Util::createStartElement('ignored'); $msg .= PHP_EOL; // with children groups <functions>, <extensions>, <constants> $ignored = array('function' => $this->parseData['ignored_functions'], 'extension' => $this->parseData['ignored_extensions'], 'constant' => $this->parseData['ignored_constants']); foreach ($ignored as $tag => $data) { $msg .= $this->_printTagList($data, $tag); } $msg .= XML_Util::createEndElement('ignored'); $msg .= PHP_EOL; // extra information only if verbose mode >= 4 if ($v & 4 || $options['debug'] == true) { unset($this->parseData['ignored_files']); unset($this->parseData['ignored_functions']); unset($this->parseData['ignored_extensions']); unset($this->parseData['ignored_constants']); unset($this->parseData['max_version']); unset($this->parseData['version']); unset($this->parseData['classes']); unset($this->parseData['functions']); unset($this->parseData['extensions']); unset($this->parseData['constants']); unset($this->parseData['tokens']); unset($this->parseData['cond_code']); // print local <functions> tag group $msg .= $this->_printTagList($this->parseData, 'function'); } if ($options['is_string'] == true) { $msg .= XML_Util::createEndElement('string'); } else { $msg .= XML_Util::createEndElement('file'); } $msg .= PHP_EOL; } if ($options['is_string'] == false) { $msg .= XML_Util::createEndElement('files'); $msg .= PHP_EOL; } } $msg .= XML_Util::createEndElement('pci'); $msg .= PHP_EOL; if (strtolower($this->conf['use-beautifier']) != 'no') { // try to see if we can improve XML render $beautifier = 'XML/Beautifier.php'; if (PHP_CompatInfo_Renderer::isIncludable($beautifier)) { include_once $beautifier; $def = array(); $opt = isset($this->conf['beautifier']) ? $this->conf['beautifier'] : $def; $fmt = new XML_Beautifier($opt); $msg = $fmt->formatString($msg); } } echo $msg; }
/** * Set up driver to be used * * Set up driver to be used, dependant on specified type. * * @param string $type Name the type of driver (html, text...) * @param array $conf A hash containing any additional configuration * * @access public * @return void * @since version 1.8.0b2 (2008-06-03) */ function setOutputDriver($type, $conf = array()) { $this->renderer =& PHP_CompatInfo_Renderer::factory($this, $type, $conf); }
/** * Csv Renderer Class constructor (ZE2) for PHP5+ * * @param object &$parser Instance of the parser (model of MVC pattern) * @param array $conf A hash containing any additional configuration * * @access public * @since version 1.8.0b4 (2008-06-18) */ function __construct(&$parser, $conf) { $defaults = array('fields-values-separated-by' => ',', 'fields-terminated-by' => ';', 'fields-enclosed-by' => '"', 'lines-terminated-by' => PHP_EOL); $conf = array_merge($defaults, $conf); parent::PHP_CompatInfo_Renderer($parser, $conf); }
/** * Array Renderer Class constructor (ZE2) for PHP5+ * * @param object &$parser Instance of the parser (model of MVC pattern) * @param array $conf A hash containing any additional configuration * * @access public * @since version 1.8.0b2 (2008-06-03) */ function __construct(&$parser, $conf) { parent::PHP_CompatInfo_Renderer($parser, $conf); $driver = 'PEAR::Var_Dump'; if (isset($conf[$driver])) { $var_dump = 'Var_Dump.php'; if (PHP_CompatInfo_Renderer::isIncludable($var_dump)) { include_once $var_dump; $class_options = $conf['PEAR::Var_Dump']; if (isset($class_options['options'])) { $options = $class_options['options']; } else { $options = array(); } if (isset($class_options['rendererOptions'])) { $rendererOptions = $class_options['rendererOptions']; } else { $rendererOptions = array(); } if (php_sapi_name() == 'cli') { // prevent wrong display on command line interface $options['display_mode'] = 'Text'; } Var_Dump::displayInit($options, $rendererOptions); $this->driver = $driver; } } if (!isset($this->driver)) { // if optional driver not defined, then use default PHP::var_export $this->driver = 'PHP'; } }
/** * Text Renderer Class constructor (ZE2) for PHP5+ * * @param object &$parser Instance of the parser (model of MVC pattern) * @param array $conf A hash containing any additional configuration * * @access public * @since version 1.8.0b3 (2008-06-07) */ function __construct(&$parser, $conf) { $defaults = array('colwidth' => array('f' => 29, 'e' => 12, 'c' => 20)); $conf = array_merge($defaults, $conf); parent::PHP_CompatInfo_Renderer($parser, $conf); }
/** * Html Renderer Class constructor (ZE2) for PHP5+ * * @param object &$parser Instance of the parser (model of MVC pattern) * @param array $conf A hash containing any additional configuration * * @access public * @since version 1.8.0b4 (2008-06-18) */ function __construct(&$parser, $conf) { $defaults = array('tdwidth' => array(18, 4, 2, 7, 13)); $conf = array_merge($defaults, $conf); parent::PHP_CompatInfo_Renderer($parser, $conf); }