PEAR logo

PHP_CompatInfo : The Definitive Guide

Name

PHP_CompatInfo::parseDir — Parse a directory

Synopsis

    require_once 'PHP/CompatInfo.php';
   
array PHP_CompatInfo::parseDir( $dir,  
  $options = array());  
string   $dir;
array   $options = array();

Description

Parse a directory recursively for its compatibility info

Parameter

string $dir

Path of folder to parse

array $options

An array of options where:

  • file_ext Contains an array of file extensions to parse for PHP code. Default: php, php4, inc, phtml

  • recurse_dir Boolean on whether to recursively find files

  • debug Contains a boolean to control whether extra ouput is shown.

  • ignore_functions Contains an array of functions to ignore when calculating the version needed.

  • ignore_constants Contains an array of constants to ignore when calculating the version needed.

  • ignore_files Contains an array of files to ignore. File names are case insensitive.

  • ignore_dirs Contains an array of directories to ignore. Directory names are case insensitive.

  • ignore_extensions Contains an array of php extensions to ignore when calculating the version needed.

  • ignore_versions Contains an array of php versions to ignore when calculating the version needed.

  • ignore_functions_match Contains an array of function patterns to ignore when calculating the version needed.

  • ignore_extensions_match Contains an array of extension patterns to ignore when calculating the version needed.

  • ignore_constants_match Contains an array of constant patterns to ignore when calculating the version needed.

Throws

throws no exceptions thrown

See

see PHP_CompatInfo::parseFolder , PHP_CompatInfo::parseData

Since

since version 0.8.0 (2004-04-22)

Note

This function can not be called statically.

Return value

array - a hash which contains information keys: ignored_functions, ignored_extensions, ignored_constants, max_version, version, extensions, constants, tokens, cond_code

Example

Suppose we have these dirs/files to parse :

PHP_CompatInfo/tests/parseDir/
  PHP5/tokens.php5
  PHP5/upload_error.php
  extensions.php
  phpinfo.php
   

See package distribution to know in details content of this scripts.

  1. <?php
  2. require_once 'PHP/CompatInfo.php';
  3.  
  4. $pci = new PHP_CompatInfo();
  5.  
  6. $input   = 'PHP_CompatInfo/tests/parseDir/';
  7. $options = array('recurse_dir' => true,
  8.                  'file_ext'    => array('php', 'php5')
  9.                 );
  10.  
  11. $res = $pci->parseDir($input, $options);
  12.  
  13. var_export($res);
  14. ?>

We get such result.

array (
  'ignored_files' =>
  array (
  ),
  'ignored_functions' =>
  array (
  ),
  'ignored_extensions' =>
  array (
  ),
  'ignored_constants' =>
  array (
  ),
  'max_version' => '',
  'version' => '5.2.0',
  'extensions' =>
  array (
    0 => 'xdebug',
    1 => 'gd',
    2 => 'sapi_apache',
    3 => 'sapi_cgi',
    4 => 'sqlite',
  ),
  'constants' =>
  array (
    0 => 'UPLOAD_ERR_INI_SIZE',
    1 => 'UPLOAD_ERR_FORM_SIZE',
    2 => 'UPLOAD_ERR_PARTIAL',
    3 => 'UPLOAD_ERR_NO_FILE',
    4 => 'UPLOAD_ERR_NO_TMP_DIR',
    5 => 'UPLOAD_ERR_CANT_WRITE',
    6 => 'UPLOAD_ERR_EXTENSION',
    7 => 'UPLOAD_ERR_OK',
  ),
  'tokens' =>
  array (
    0 => 'abstract',
    1 => 'protected',
    2 => 'interface',
    3 => 'public',
    4 => 'implements',
    5 => 'private',
    6 => 'clone',
    7 => 'instanceof',
    8 => 'try',
    9 => 'throw',
    10 => 'catch',
    11 => 'final',
  ),
  'cond_code' =>
  array (
    0 => 2,
    1 =>
    array (
      0 =>
      array (
      ),
      1 =>
      array (
      ),
      2 =>
      array (
      ),
    ),
  ),
  'PHP_CompatInfo/tests/parseDir/extensions.php' =>
  array (
    'ignored_functions' =>
    array (
    ),
    'ignored_extensions' =>
    array (
    ),
    'ignored_constants' =>
    array (
    ),
    'max_version' => '',
    'version' => '4.3.2',
    'extensions' =>
    array (
      0 => 'xdebug',
      1 => 'gd',
      2 => 'sapi_apache',
      3 => 'sapi_cgi',
      4 => 'sqlite',
    ),
    'constants' =>
    array (
    ),
    'tokens' =>
    array (
    ),
    'cond_code' =>
    array (
      0 => 2,
      1 =>
      array (
        0 =>
        array (
        ),
        1 =>
        array (
        ),
        2 =>
        array (
        ),
      ),
    ),
  ),
  'PHP_CompatInfo/tests/parseDir/phpinfo.php' =>
  array (
    'ignored_functions' =>
    array (
    ),
    'ignored_extensions' =>
    array (
    ),
    'ignored_constants' =>
    array (
    ),
    'max_version' => '',
    'version' => '4.0.0',
    'extensions' =>
    array (
    ),
    'constants' =>
    array (
    ),
    'tokens' =>
    array (
    ),
    'cond_code' =>
    array (
      0 => 0,
      1 =>
      array (
        0 =>
        array (
        ),
        1 =>
        array (
        ),
        2 =>
        array (
        ),
      ),
    ),
  ),
  'PHP_CompatInfo/tests/parseDir/PHP5/tokens.php5' =>
  array (
    'ignored_functions' =>
    array (
    ),
    'ignored_extensions' =>
    array (
    ),
    'ignored_constants' =>
    array (
    ),
    'max_version' => '',
    'version' => '5.0.0',
    'extensions' =>
    array (
    ),
    'constants' =>
    array (
    ),
    'tokens' =>
    array (
      0 => 'abstract',
      1 => 'protected',
      2 => 'interface',
      3 => 'public',
      4 => 'implements',
      5 => 'private',
      6 => 'clone',
      7 => 'instanceof',
      8 => 'try',
      9 => 'throw',
      10 => 'catch',
      11 => 'final',
    ),
    'cond_code' =>
    array (
      0 => 0,
      1 =>
      array (
        0 =>
        array (
        ),
        1 =>
        array (
        ),
        2 =>
        array (
        ),
      ),
    ),
  ),
  'PHP_CompatInfo/tests/parseDir/PHP5/upload_error.php' =>
  array (
    'ignored_functions' =>
    array (
    ),
    'ignored_extensions' =>
    array (
    ),
    'ignored_constants' =>
    array (
    ),
    'max_version' => '',
    'version' => '5.2.0',
    'extensions' =>
    array (
    ),
    'constants' =>
    array (
      0 => 'UPLOAD_ERR_INI_SIZE',
      1 => 'UPLOAD_ERR_FORM_SIZE',
      2 => 'UPLOAD_ERR_PARTIAL',
      3 => 'UPLOAD_ERR_NO_FILE',
      4 => 'UPLOAD_ERR_NO_TMP_DIR',
      5 => 'UPLOAD_ERR_CANT_WRITE',
      6 => 'UPLOAD_ERR_EXTENSION',
      7 => 'UPLOAD_ERR_OK',
    ),
    'tokens' =>
    array (
      0 => 'throw',
    ),
    'cond_code' =>
    array (
      0 => 0,
      1 =>
      array (
        0 =>
        array (
        ),
        1 =>
        array (
        ),
        2 =>
        array (
        ),
      ),
    ),
  ),
)
   

We have global result, then follow by each file parsed in sub-directories.

PHP_CompatInfo : The Definitive Guide v 1.8.0 : August 1, 2008