Outputting Results
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
-
Array, PHP_CompatInfo_Renderer_Array. It is similar to PHP var_export May be beautify if PEAR::Var_Dump is installed on your system.
-
Csv, PHP_CompatInfo_Renderer_Csv. Print a comma separate values of results.
-
Html, PHP_CompatInfo_Renderer_Html. Print a pretty nice table with a customizable style sheet (inline or to a separate file)
-
Null, PHP_CompatInfo_Renderer_Null. The solution to suppress display on standard output.
-
Text, PHP_CompatInfo_Renderer_Text. This renderer is usefull only with the command-line parser mode (CLI).
-
Xml, PHP_CompatInfo_Renderer_Xml. Print an XML representation of results. May be beautify if PEAR::XML_Beautifier is installed on your system.
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.
-
silent mode : When parsing more than one source file, PHP_CompatInfo can display status of long process. With simple wait text messages, or a progress bar if PEAR::Console_ProgressBar is available (installed on your system).
The default mode silent On, is turn off when you specify a progress bar or a progress text with --progress or -p switches on CLI with the pci script.
If you run the web interface, you have to turn it on manually. For example:
<?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
// Turn Off the silent mode, and display simple wait text messages
$driverOptions = array('silent' => false, 'progress' => 'text');
$pci = new PHP_CompatInfo($driverType, $driverOptions);
$r = $pci->parseData($datasource, $options);
?>See also the
docs/examples/parseDir_withCustomProgressBar.php
example in the package distribution, to customize a progress bar for the CLI and pci script usage. -
output-level allow to choose what information (condition code level, extensions, constants, tokens, version) will be shown or hidden.
Default value is 31: that means we show all details. See the Command-Line Parser section, and -o | --output-level switch to learn more about values and corresponding behaviors.
-
summarize mode, is usefull when you parse more than one file, and don't want to see intermediate result of each file, but only the final one.
Default is turn off.
-
verbose level, give details deep you want to have: from 0 (no extra information) to 7 (full details).
Default level is 0. See the Command-Line Parser section, and -v | --verbose switch to learn more about values and corresponding behaviors.
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
-
fields-values-separated-by identify the delimiter of values when there is a list given (extensions, constants, tokens). Default is ,
-
fields-terminated-by identify the delimiter of fields (those given by the output-level directive). Default is ;
-
fields-enclosed-by identify the protect field character if content have one or more restrictive character as given by previous options. Default is "
-
lines-terminated-by identify the end-of-line character. Usefull if you want to generate a file for another platform than those who have produced the results. Default is PHP_EOL constant
Html renderer options
Html renderer have only one specific option :
-
tdwidth that give size of each column (in em css unit), even if there are not shown (see output-level value). Default is 18,4,2,7,13
That means: File is 18 em width, Version is 4 em width, C (cond_code) is 2 em width, Extensions is 7 em width, and Constants/Tokens is 13 em width.
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 :
-
colwidth that give size of file (f), extensions (e), and constants/tokens (c) column (in character unit), even if there are not shown (see output-level value). Default is f = 29, e = 12, c = 20)
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-beautifier tell if we use the PEAR::XML_Beautifier package to beautify XML output. Default is auto (use only if available)
-
beautifier is a hash for the PEAR::XML_Beautifier package options. Default is empty array (use all XML_Beautifier package default 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.