Source for file Xml.php
Documentation is available at Xml.php
* Copyright (c) 2008, Laurent Laville <pear@laurent-laville.org>
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the authors nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* @package PHP_CompatInfo
* @author Laurent Laville <pear@laurent-laville.org>
* @license http://www.opensource.org/licenses/bsd-license.php BSD
* @version CVS: $Id: Xml.php,v 1.11 2008/07/22 20:26:19 farell Exp $
* @link http://pear.php.net/package/PHP_CompatInfo
* @since File available since Release 1.8.0b2
require_once 'XML/Util.php';
* Array renderer for PHP_CompatInfo component.
* The PHP_CompatInfo_Renderer_Xml class is a concrete implementation
* of PHP_CompatInfo_Renderer abstract class. It simply display results as
* @package PHP_CompatInfo
* @author Laurent Laville <pear@laurent-laville.org>
* @license http://www.opensource.org/licenses/bsd-license.php BSD
* @version Release: 1.8.0
* @link http://pear.php.net/package/PHP_CompatInfo
* @since Class available since Release 1.8.0b2
* Xml Renderer Class constructor (ZE1) for PHP4
* @param object &$parser Instance of the parser (model of MVC pattern)
* @param array $conf A hash containing any additional configuration
* @since version 1.8.0b2 (2008-06-03)
* Xml 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
* @since version 1.8.0b2 (2008-06-03)
$defaults = array ('use-beautifier' => 'auto');
* Display final results, when data source parsing is over.
* @since version 1.8.0b2 (2008-06-03)
$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 .= XML_Util ::createStartElement ('pci',
array ('version' => '1.8.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 == 'file') {
// parsing a directory or a list of files, chunks of code
if ($options['is_string'] == false ) {
if ($dataType == 'directory') {
$tag = array ('qname' => 'dir',
'content' => dirname($dataSource[0 ]));
$tag = array ('qname' => 'file',
'content' => $dataSource[0 ]);
$msg .= XML_Util ::createTagFromArray ($tag);
// print global <version> tag
if (empty ($this->parseData['max_version'])) {
$attr = array ('max' => $this->parseData['max_version']);
$tag = array ('qname' => 'version',
$msg .= XML_Util ::createTagFromArray ($tag);
// print global <conditions> tag group
$msg .= $this->_printTagList ($this->parseData['cond_code'],
// print global <extensions> tag group
$msg .= $this->_printTagList ($this->parseData['extensions'],
// print global <constants> tag group
$msg .= $this->_printTagList ($this->parseData['constants'],
// print global <tokens> tag group
$msg .= $this->_printTagList ($this->parseData['tokens'],
// print global <ignored> tag group
$msg .= XML_Util ::createStartElement ('ignored');
// 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');
unset ($this->parseData['ignored_functions']);
unset ($this->parseData['ignored_extensions']);
unset ($this->parseData['ignored_constants']);
if ($v & 4 || $options['debug'] == true ) {
// print local <functions> tag group
$msg .= $this->_printTagList ($this->parseData, 'function');
foreach ($entries as $k) {
if ($dataType == 'file') {
$files = array ($dataSource[0 ] => $this->parseData);
// ... or a chunk of code (string)
if ($this->args['summarize'] === false
if ($options['is_string'] == false ) {
// print <files> tag group
$msg .= XML_Util ::createStartElement ('files',
array ('count' => count($files)));
foreach ($files as $file => $this->parseData) {
if ($options['is_string'] == true ) {
$msg .= XML_Util ::createStartElement ('string',
// print local <file> tag
$msg .= XML_Util ::createStartElement ('file',
// print local <version> tag
if (empty ($this->parseData['max_version'])) {
$attr = array ('max' => $this->parseData['max_version']);
$tag = array ('qname' => 'version',
$msg .= XML_Util ::createTagFromArray ($tag);
// print local <conditions> tag group
$msg .= $this->_printTagList ($this->parseData['cond_code'],
// print local <extensions> tag group
$msg .= $this->_printTagList ($this->parseData['extensions'],
// print local <constants> tag group
$msg .= $this->_printTagList ($this->parseData['constants'],
// print local <tokens> tag group
$msg .= $this->_printTagList ($this->parseData['tokens'],
// print local <ignored> tag group
$msg .= XML_Util ::createStartElement ('ignored');
// with children groups <functions>, <extensions>, <constants>
'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');
// extra information only if verbose mode >= 4
if ($v & 4 || $options['debug'] == true ) {
unset ($this->parseData['ignored_functions']);
unset ($this->parseData['ignored_extensions']);
unset ($this->parseData['ignored_constants']);
// print local <functions> tag group
$msg .= $this->_printTagList ($this->parseData, 'function');
if ($options['is_string'] == true ) {
$msg .= XML_Util ::createEndElement ('string');
$msg .= XML_Util ::createEndElement ('file');
if ($options['is_string'] == false ) {
$msg .= XML_Util ::createEndElement ('files');
$msg .= XML_Util ::createEndElement ('pci');
// try to see if we can improve XML render
$beautifier = 'XML/Beautifier.php';
include_once $beautifier;
$opt = isset ($this->conf['beautifier'])
? $this->conf['beautifier'] : $def;
$fmt = new XML_Beautifier ($opt);
$msg = $fmt->formatString ($msg);
* Print a group of same tag in the XML report.
* Groups list are : extension(s), constant(s), token(s)
* @param array $dataSrc Data source
* @param string $tagName Name of the XML tag
* @since version 1.7.0b4 (2008-04-03)
function _printTagList ($dataSrc, $tagName)
if ($tagName == 'function') {
foreach ($dataSrc as $version => $functions) {
$attributes = array ('count' => $c);
} elseif ($tagName == 'condition') {
if ($this->_parser->options ['debug'] === true ) {
foreach ($dataSrc[1 ] as $cond => $elements) {
$attributes = array ('count' => $c, 'level' => $dataSrc[0 ]);
$attributes = array ('level' => $dataSrc[0 ]);
$attributes = array ('count' => count($dataSrc));
$msg .= XML_Util ::createStartElement ($tagName. 's', $attributes);
if ($tagName == 'function') {
foreach ($dataSrc as $version => $functions) {
foreach ($functions as $data) {
$attr = array ('version' => $version);
if (!empty ($data['extension'])) {
$attr['extension'] = $data['extension'];
$attr['pecl'] = $data['pecl'] === true ?
$tag = array ('qname' => $tagName,
'content' => $data['function']);
$msg .= XML_Util ::createTagFromArray ($tag);
} elseif ($tagName == 'condition') {
if ($this->_parser->options ['debug'] == true ) {
foreach ($dataSrc[1 ] as $cond => $elements) {
$cond = ($cond == 0 ) ? 1 : ($cond * 2 );
foreach ($elements as $data) {
$tag = array ('qname' => $tagName,
'attributes' => array ('level' => $cond),
$msg .= XML_Util ::createTagFromArray ($tag);
foreach ($dataSrc as $data) {
$tag = array ('qname' => $tagName,
$msg .= XML_Util ::createTagFromArray ($tag);
$msg .= XML_Util ::createEndElement ($tagName. 's');
Documentation generated on Fri, 01 Aug 2008 11:30:35 -0400 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.
|