Parsing two different data sources at once

Overview

This example show how to parse all files into a directory and also one other file outside this directory.

Dependencies

This example requires mandatory resources :

Source Code

The very basic script to parse the directory and file defined on line 14

  1. <?php
  2. require_once 'PHP/CompatInfo.php';
  3.  
  4. $driverType = 'array';
  5.  
  6. /*
  7.    Display wait messages or a progress bar (PEAR::Console_ProgressBar)
  8.    if available while parsing data source
  9.    Default behavior is:  silent = true (no wait system)
  10.    Use (progress => text) if you don't want a progress bar but only text messages
  11.  */
  12. $driverOptions = array('silent' => false, 'progress' => 'bar');
  13.  
  14. $source  = array('/tmp/Log-1.10.0/Log', '/tmp/File_Find-1.3.0/Find.php');
  15. $options = array();
  16.  
  17. $info = new PHP_CompatInfo($driverType, $driverOptions);
  18. $info->parseArray($source, $options);
  19. // You may also use the new unified method parseData(), parseArray() became an alias
  20. // $info->parseData($source, $options);
  21. ?>

Output

-  8/17 files [==============>----------------]  47.06% Elapsed Time: 00:00.61

array (
  'ignored_files' =>
  array (
  ),
  'ignored_functions' =>
  array (
  ),
  'ignored_extensions' =>
  array (
  ),
  'ignored_constants' =>
  array (
  ),
  'max_version' => '',
  'version' => '4.3.0',
  'extensions' =>
  array (
    0 => 'date',
    1 => 'hash',
    2 => 'pcre',
    3 => 'sqlite',
  ),
  'constants' =>
  array (
    0 => 'STDOUT',
    1 => '__FILE__',
  ),
  'tokens' =>
  array (
  ),
  'cond_code' =>
  array (
    0 => 4,
  ),
  '/tmp/Log-1.10.0/Log/composite.php' =>
  array (
    'ignored_functions' =>
    array (
    ),
    'ignored_extensions' =>
    array (
    ),
    'ignored_constants' =>
    array (
    ),
    'max_version' => '',
    'version' => '4.2.0',
    'extensions' =>
    array (
    ),
    'constants' =>
    array (
    ),
    'tokens' =>
    array (
    ),
    'cond_code' =>
    array (
      0 => 0,
    ),
  ),

[... more file details (hidden) ... ]

  '/tmp/File_Find-1.3.0/Find.php' =>
  array (
    'ignored_functions' =>
    array (
    ),
    'ignored_extensions' =>
    array (
    ),
    'ignored_constants' =>
    array (
    ),
    'max_version' => '',
    'version' => '4.3.0',
    'extensions' =>
    array (
      0 => 'pcre',
    ),
    'constants' =>
    array (
    ),
    'tokens' =>
    array (
    ),
    'cond_code' =>
    array (
      0 => 4,
    ),
  ),

Explains step by step

Because parsing a directory (with lot of file) can take a long time, we use the progress bar (message) wait behavior, common to all renderers, when running in CLI mode.

This progress bar is turn on at line 12

At line 18, we used the parseArray() method because we have two different data sources. We can also use now the new unified method parseData().

Final results (array dump) gave first the summary of all files parsed, then details for each file

We will see with next example (group 3) what this cond_code value means, and how to catch it well.