PHP_CompatInfo::parseDir

PHP_CompatInfo::parseDir() – Parse a directory

Synopsis

require_once 'PHP/CompatInfo.php';

array PHP_CompatInfo::parseDir ( 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

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.

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

$pci = new PHP_CompatInfo();

$input   'PHP_CompatInfo/tests/parseDir/';
$options = array('recurse_dir' => true,
                 
'file_ext'    => array('php''php5')
                );

$res $pci->parseDir($input$options);

#var_export($res); // no need since PCI 1.8.0
?>

We get such result.

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

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