Outputting Results

Outputting Results -- how to use the renderer system

Overview

PHP_CompatInfo can use different kind of renderers and provides a default one (Array) which print a complete parsable string representation of results.

There are 6 renderers available with PHP_CompatInfo 1.8.0

If none of them match your need, you can also write your own renderers.

Basic usage

The main steps of using any available renderer are quite similar:

<?php
require_once 'PHP/CompatInfo.php';

// data source to parse: file, directory, string, ...
$datasource = '/tmp/HTML_CSS-1.5.1';

// parser options depending of data source
$options    = array();

// kind of renderer: array, csv, html, null, text, xml, ...
$driverType    = 'array';  // case insensitive

// specific renderer hash options
$driverOptions = array();

$pci = new PHP_CompatInfo($driverType, $driverOptions);
$r = $pci->parseData($datasource, $options);
?>

注意 To keep compatibility with previous versions, you can find the result similar to var_export (Array renderer) in $r (in our example). All parse functions (parseDir, parseFile, parseArray, parseString) have the same behavior.

PHP_CompatInfo class constructor expect to receive two parameters: first one identify the kind of renderer (array, csv, html, null, text, xml), while second is private and specific to each renderer. Allows to customize a bit the renderer without to rewrite a new one (explore all options before beginning to write your own version).

Configuration options

Before to have a look on each driver specific options, take a short pause on common options of all renderers.

重要項目 All renderers can be run in both interfaces (web and cli), this is why we can find a hash named args in the driver array options (second parameter of PHP_CompatInfo class constructor). This hash replace corresponding arguments you should have (otherwise) to specify on the Command-Line.

Array renderer options

Array renderer used two drivers to show dump of results. Default is PHP (var_export function). The other one is PEAR::Var_Dump. You can use this last one only if package is installed on your system.

While there are no specific options for PHP driver, you can use all options of PEAR::Var_Dump to beautify the dump of results. See example docs/examples/pci180_parsefile.php in the package distribution.

First key of hash (options) allow to choose the Var_Dump renderer (display_mode) you want.

注意

Only display_mode = Text is allowed if you run PHP_CompatInfo on CLI.

Second key of hash (rendererOptions) allow to give specific options to the Var_Dump renderer identified by display_mode directive.

注意 Var_Dump package exists for two major versions of PHP.

Var_Dump PHP 4 on default PEAR channel (branch 1.0)

Var_Dump PHP 5 on PEAR channel Toolbox (branch 1.2)

Csv renderer options

Csv renderer can be customized only in one way: change delimiters characters

Html renderer options

Html renderer have only one specific option :

See also the docs/examples/pci180_parsedir_tohtml.php example in the package distribution, howto define your own html renderer.

Text renderer options

Text renderer have only one specific option :

See the Command-Line Parser section, and -t | --tab switch to learn more about optimized values depending of output-level

Xml renderer options

Xml renderer have only two specific options :

ティップ Use no value if you have PEAR::XML_Beautifier installed, and you don't want to have XML beautified.

See also the docs/examples/pci180_parsedata_toxml.php, and docs/examples/pci180_parsestring_toxml.php examples in the package distribution.