home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / PHP / CompatInfo.php < prev   
Encoding:
PHP Script  |  2008-07-02  |  49.6 KB  |  1,251 lines

  1. <?php
  2. /**
  3.  * Check Compatibility of chunk of PHP code
  4.  *
  5.  * PHP versions 4 and 5
  6.  *
  7.  * LICENSE: This source file is subject to version 3.01 of the PHP license
  8.  * that is available through the world-wide-web at the following URI:
  9.  * http://www.php.net/license/3_01.txt.  If you did not receive a copy of
  10.  * the PHP License and are unable to obtain it through the web, please
  11.  * send a note to license@php.net so we can mail you a copy immediately.
  12.  *
  13.  * @category PHP
  14.  * @package  PHP_CompatInfo
  15.  * @author   Davey Shafik <davey@php.net>
  16.  * @author   Laurent Laville <pear@laurent-laville.org>
  17.  * @license  http://www.php.net/license/3_01.txt  PHP License 3.01
  18.  * @version  CVS: $Id: CompatInfo.php,v 1.92 2008/04/17 20:34:02 farell Exp $
  19.  * @link     http://pear.php.net/package/PHP_CompatInfo
  20.  * @since    File available since Release 0.7.0
  21.  */
  22.  
  23. require_once 'File/Find.php';
  24.  
  25. /**
  26.  * An array of function init versions and extension
  27.  */
  28. require_once 'PHP/CompatInfo/func_array.php';
  29.  
  30. /**
  31.  * An array of constants and their init versions
  32.  */
  33. require_once 'PHP/CompatInfo/const_array.php';
  34.  
  35. /**
  36.  * Check Compatibility of chunk of PHP code
  37.  *
  38.  * @example docs/examples/checkConstants.php
  39.  *          Example that shows minimum version with Constants
  40.  * @example docs/examples/parseFile.php
  41.  *          Example on how to parse a file
  42.  * @example docs/examples/parseDir.php
  43.  *          Example on how to parse a directory
  44.  * @example docs/examples/parseArray.php
  45.  *          Example on using using parseArray() to parse a script
  46.  * @example docs/examples/parseString.php
  47.  *          Example on how to parse a string
  48.  * @example docs/examples/cliCustom.php
  49.  *          Example of using PHP_CompatInfo_Cli
  50.  *
  51.  * @category  PHP
  52.  * @package   PHP_CompatInfo
  53.  * @author    Davey Shafik <davey@php.net>
  54.  * @author    Laurent Laville <pear@laurent-laville.org>
  55.  * @copyright 2003 Davey Shafik and Synaptic Media. All Rights Reserved.
  56.  * @license   http://www.php.net/license/3_01.txt  PHP License 3.01
  57.  * @version   Release: 1.7.0
  58.  * @link      http://pear.php.net/package/PHP_CompatInfo
  59.  * @since     Class available since Release 0.7.0
  60.  */
  61.  
  62. class PHP_CompatInfo
  63. {
  64.     /**
  65.      * @var string Earliest version of PHP to use
  66.      * @since  0.7.0
  67.      */
  68.     var $latest_version = '3.0.0';
  69.  
  70.     /**
  71.      * @var string Last version of PHP to use
  72.      */
  73.     var $earliest_version = '';
  74.  
  75.     /**
  76.      * @var boolean Toggle parseDir recursion
  77.      * @since  0.7.0
  78.      */
  79.     var $recurse_dir = true;
  80.  
  81.     /**
  82.      * Parse a single file
  83.      *
  84.      * Parse a file for its compatibility info
  85.      *
  86.      * @param string $file    Path of File to parse
  87.      * @param array  $options An array of options where:
  88.      *  - 'debug'                   Contains a boolean to control whether
  89.      *                              extra ouput is shown.
  90.      *  - 'ignore_functions'        Contains an array of functions to ignore
  91.      *                              when calculating the version needed.
  92.      *  - 'ignore_constants'        Contains an array of constants to ignore
  93.      *                              when calculating the version needed.
  94.      *  - 'ignore_extensions'       Contains an array of php extensions to ignore
  95.      *                              when calculating the version needed.
  96.      *  - 'ignore_versions'         Contains an array of php versions to ignore
  97.      *                              when calculating the version needed.
  98.      *  - 'ignore_functions_match'  Contains an array of function patterns to ignore
  99.      *                              when calculating the version needed.
  100.      *  - 'ignore_extensions_match' Contains an array of extension patterns to ignore
  101.      *                              when calculating the version needed.
  102.      *  - 'ignore_constants_match'  Contains an array of constant patterns to ignore
  103.      *                              when calculating the version needed.
  104.      *
  105.      * @access public
  106.      * @return array
  107.      * @since  version 0.7.0 (2004-03-09)
  108.      */
  109.     function parseFile($file, $options = array())
  110.     {
  111.         if (is_string($file) && !file_exists($file)) {
  112.             // filter invalid input
  113.             return false;
  114.         }
  115.         $options = array_merge(array('debug' => false), $options);
  116.         $tokens  = $this->_tokenize($file);
  117.         $results = $this->_parseTokens($tokens, $options);
  118.         if ($options['debug'] === false) {
  119.             $results['cond_code'][1] = array();
  120.         }
  121.         return $results;
  122.     }
  123.  
  124.     /**
  125.      * Parse a string
  126.      *
  127.      * Parse a string for its compatibility info
  128.      *
  129.      * @param string $string  PHP Code to parses
  130.      * @param array  $options An array of options where:
  131.      *  - 'debug'                   Contains a boolean to control whether
  132.      *                              extra ouput is shown.
  133.      *  - 'ignore_functions'        Contains an array of functions to ignore
  134.      *                              when calculating the version needed.
  135.      *  - 'ignore_constants'        Contains an array of constants to ignore
  136.      *                              when calculating the version needed.
  137.      *  - 'ignore_extensions'       Contains an array of php extensions to ignore
  138.      *                              when calculating the version needed.
  139.      *  - 'ignore_versions'         Contains an array of php versions to ignore
  140.      *                              when calculating the version needed.
  141.      *  - 'ignore_functions_match'  Contains an array of function patterns to ignore
  142.      *                              when calculating the version needed.
  143.      *  - 'ignore_extensions_match' Contains an array of extension patterns to ignore
  144.      *                              when calculating the version needed.
  145.      *  - 'ignore_constants_match'  Contains an array of constant patterns to ignore
  146.      *                              when calculating the version needed.
  147.      *
  148.      * @access public
  149.      * @return array|false
  150.      * @since  version 0.7.0 (2004-03-09)
  151.      */
  152.     function parseString($string, $options = array())
  153.     {
  154.         if (!is_string($string)) {
  155.             // filter invalid input
  156.             return false;
  157.         }
  158.         $options = array_merge(array('debug' => false), $options);
  159.         $tokens  = $this->_tokenize($string, true);
  160.         $results = $this->_parseTokens($tokens, $options);
  161.         if ($options['debug'] === false) {
  162.             $results['cond_code'][1] = array();
  163.         }
  164.         return $results;
  165.     }
  166.  
  167.     /**
  168.      * Parse a directory
  169.      *
  170.      * Parse a directory recursively for its compatibility info
  171.      *
  172.      * @param string $dir     Path of folder to parse
  173.      * @param array  $options An array of options where:
  174.      *  - 'file_ext'                Contains an array of file extensions to parse
  175.      *                              for PHP code. Default: php, php4, inc, phtml
  176.      *  - 'recurse_dir'             Boolean on whether to recursively find files
  177.      *  - 'debug'                   Contains a boolean to control whether
  178.      *                              extra ouput is shown.
  179.      *  - 'ignore_functions'        Contains an array of functions to ignore
  180.      *                              when calculating the version needed.
  181.      *  - 'ignore_constants'        Contains an array of constants to ignore
  182.      *                              when calculating the version needed.
  183.      *  - 'ignore_files'            Contains an array of files to ignore.
  184.      *                              File names are case insensitive.
  185.      *  - 'ignore_dirs'             Contains an array of directories to ignore.
  186.      *                              Directory names are case insensitive.
  187.      *  - 'ignore_extensions'       Contains an array of php extensions to ignore
  188.      *                              when calculating the version needed.
  189.      *  - 'ignore_versions'         Contains an array of php versions to ignore
  190.      *                              when calculating the version needed.
  191.      *  - 'ignore_functions_match'  Contains an array of function patterns to ignore
  192.      *                              when calculating the version needed.
  193.      *  - 'ignore_extensions_match' Contains an array of extension patterns to ignore
  194.      *                              when calculating the version needed.
  195.      *  - 'ignore_constants_match'  Contains an array of constant patterns to ignore
  196.      *                              when calculating the version needed.
  197.      *
  198.      * @access public
  199.      * @return array|false
  200.      * @since  version 0.8.0 (2004-04-22)
  201.      * @see PHP_CompatInfo::_fileList()
  202.      */
  203.     function parseDir($dir, $options = array())
  204.     {
  205.         if (!is_dir($dir) || !is_readable($dir)) {
  206.             // filter invalid input
  207.             return false;
  208.         }
  209.  
  210.         $files_parsed       = array();
  211.         $latest_version     = $this->latest_version;
  212.         $earliest_version   = $this->earliest_version;
  213.         $extensions         = array();
  214.         $constants          = array();
  215.         $tokens             = array();
  216.         $ignored            = array();
  217.         $ignored_functions  = array();
  218.         $ignored_extensions = array();
  219.         $ignored_constants  = array();
  220.         $function_exists    = array();
  221.         $extension_loaded   = array();
  222.         $defined            = array();
  223.         $cond_code          = 0;
  224.         $default_options    = array(
  225.             'file_ext' => array('php', 'php4', 'inc', 'phtml'),
  226.             'recurse_dir' => true,
  227.             'debug' => false,
  228.             'ignore_files' => array(),
  229.             'ignore_dirs' => array()
  230.             );
  231.  
  232.         $options = array_merge($default_options, $options);
  233.  
  234.         if ($dir{strlen($dir)-1} == '/' || $dir{strlen($dir)-1} == '\\') {
  235.             $path = $dir;
  236.             $dir  = substr($dir, 0, -1);
  237.         } else {
  238.             $path = $dir . DIRECTORY_SEPARATOR;
  239.         }
  240.  
  241.         $options['file_ext']
  242.             = array_map('strtolower', $options['file_ext']);
  243.  
  244.         // use system directory separator rather than forward slash by default
  245.         $ff         = new File_Find();
  246.         $ff->dirsep = DIRECTORY_SEPARATOR;
  247.  
  248.         // get directory list that should be ignored from scope
  249.         $ignore_dirs = array();
  250.         if (count($options['ignore_dirs']) > 0) {
  251.             foreach ($options['ignore_dirs'] as $cond) {
  252.                 $cond        = str_replace('\\', "\\\\", $cond);
  253.                 $dirs        = $ff->search('`'.$cond.'`', $dir, 'perl',
  254.                                            true, 'directories');
  255.                 $ignore_dirs = array_merge($ignore_dirs, $dirs);
  256.             }
  257.         }
  258.  
  259.         // get file list that should be ignored from scope
  260.         $ignore_files = array();
  261.         if (count($options['ignore_files']) > 0) {
  262.             foreach ($options['ignore_files'] as $cond) {
  263.                 $cond         = str_replace('\\', "\\\\", $cond);
  264.                 $files        = $ff->search('`'.$cond.'`', $dir, 'perl',
  265.                                             true, 'files');
  266.                 $ignore_files = array_merge($ignore_files, $files);
  267.             }
  268.         }
  269.  
  270.         $files_filter = array();
  271.  
  272.         if ($options['recurse_dir'] === false) {
  273.             $files = File_Find::glob('`.*`', $dir, 'perl');
  274.  
  275.             foreach ($files as $f) {
  276.                 $file_info = pathinfo($f);
  277.                 $entry     = $path . $file_info['basename'];
  278.                 if (is_dir($entry)) {
  279.                     continue;
  280.                 } else {
  281.                     if (in_array($entry, $ignore_files)) {
  282.                         $ignored[] = $entry;
  283.                         continue;
  284.                     }
  285.                 }
  286.                 $files_filter[] = $entry;
  287.             }
  288.         } else {
  289.             list($directories, $files) = $ff->maptree($dir);
  290.  
  291.             foreach ($files as $entry) {
  292.                 $file_info = pathinfo($entry);
  293.                 if (in_array($file_info['dirname'], $ignore_dirs)) {
  294.                     $ignored[] = $entry;
  295.                     continue;
  296.                 }
  297.                 if (in_array($entry, $ignore_files)) {
  298.                     $ignored[] = $entry;
  299.                     continue;
  300.                 }
  301.                 $files_filter[] = $entry;
  302.             }
  303.         }
  304.  
  305.         foreach ($files_filter as $file) {
  306.             $file_info = pathinfo($file);
  307.             if (isset($file_info['extension'])
  308.                 && in_array(strtolower($file_info['extension']),
  309.                     $options['file_ext'])) {
  310.                 $tokens_list         = $this->_tokenize($file);
  311.                 $files_parsed[$file] = $this->_parseTokens($tokens_list, $options);
  312.             }
  313.         }
  314.         foreach ($files_parsed as $fn => $file) {
  315.             $cmp = version_compare($latest_version, $file['version']);
  316.             if ($cmp === -1) {
  317.                 $latest_version = $file['version'];
  318.             }
  319.             if ($file['max_version'] != '') {
  320.                 $cmp = version_compare($earliest_version, $file['max_version']);
  321.                 if ($earliest_version == '' || $cmp === 1) {
  322.                     $earliest_version = $file['max_version'];
  323.                 }
  324.             }
  325.             foreach ($file['extensions'] as $ext) {
  326.                 if (!in_array($ext, $extensions)) {
  327.                     $extensions[] = $ext;
  328.                 }
  329.             }
  330.             foreach ($file['constants'] as $const) {
  331.                 if (!in_array($const, $constants)) {
  332.                     $constants[] = $const;
  333.                 }
  334.             }
  335.             foreach ($file['tokens'] as $token) {
  336.                 if (!in_array($token, $tokens)) {
  337.                     $tokens[] = $token;
  338.                 }
  339.             }
  340.             foreach ($file['ignored_functions'] as $if) {
  341.                 if (!in_array($if, $ignored_functions)) {
  342.                     $ignored_functions[] = $if;
  343.                 }
  344.             }
  345.             foreach ($file['ignored_extensions'] as $ie) {
  346.                 if (!in_array($ie, $ignored_extensions)) {
  347.                     $ignored_extensions[] = $ie;
  348.                 }
  349.             }
  350.             foreach ($file['ignored_constants'] as $ic) {
  351.                 if (!in_array($ic, $ignored_constants)) {
  352.                     $ignored_constants[] = $ic;
  353.                 }
  354.             }
  355.             foreach ($file['cond_code'][1][0] as $ccf) {
  356.                 if (!in_array($ccf, $function_exists)) {
  357.                     $function_exists[] = $ccf;
  358.                 }
  359.             }
  360.             foreach ($file['cond_code'][1][1] as $cce) {
  361.                 if (!in_array($cce, $extension_loaded)) {
  362.                     $extension_loaded[] = $cce;
  363.                 }
  364.             }
  365.             foreach ($file['cond_code'][1][2] as $ccc) {
  366.                 if (!in_array($ccc, $defined)) {
  367.                     $defined[] = $ccc;
  368.                 }
  369.             }
  370.             if ($options['debug'] === false) {
  371.                 $files_parsed[$fn]['cond_code'][1][0] = array();
  372.                 $files_parsed[$fn]['cond_code'][1][1] = array();
  373.                 $files_parsed[$fn]['cond_code'][1][2] = array();
  374.             }
  375.         }
  376.  
  377.         if (count($files_parsed) == 0) {
  378.             return false;
  379.         }
  380.  
  381.         if (count($function_exists) > 0) {
  382.             $cond_code += 1;
  383.         }
  384.         if (count($extension_loaded) > 0) {
  385.             $cond_code += 2;
  386.         }
  387.         if (count($defined) > 0) {
  388.             $cond_code += 4;
  389.         }
  390.         if ($options['debug'] === false) {
  391.             $function_exists  = array();
  392.             $extension_loaded = array();
  393.             $defined          = array();
  394.         }
  395.         $cond_code = array($cond_code,
  396.                            array($function_exists, $extension_loaded, $defined));
  397.  
  398.         $main_info = array('ignored_files'      => $ignored,
  399.                            'ignored_functions'  => $ignored_functions,
  400.                            'ignored_extensions' => $ignored_extensions,
  401.                            'ignored_constants'  => $ignored_constants,
  402.                            'max_version'   => $earliest_version,
  403.                            'version'       => $latest_version,
  404.                            'extensions'    => $extensions,
  405.                            'constants'     => $constants,
  406.                            'tokens'        => $tokens,
  407.                            'cond_code'     => $cond_code);
  408.  
  409.         $files_parsed = array_merge($main_info, $files_parsed);
  410.         return $files_parsed;
  411.     }
  412.  
  413.     /**
  414.      * Alias of parseDir
  415.      *
  416.      * Alias of parseDir function
  417.      *
  418.      * @param string $folder  Path of folder to parse
  419.      * @param array  $options An array of options
  420.      *
  421.      * @uses   PHP_CompatInfo::parseDir()
  422.      * @access public
  423.      * @return array
  424.      * @since  version 0.7.0 (2004-03-09)
  425.      */
  426.     function parseFolder($folder, $options = array())
  427.     {
  428.         return $this->parseDir($folder, $options);
  429.     }
  430.  
  431.     /**
  432.      * Parse an Array of Files
  433.      *
  434.      * You can parse an array of Files or Strings, to parse
  435.      * strings, $options['is_string'] must be set to true
  436.      *
  437.      * @param array $files   Array of file names or code strings
  438.      * @param array $options An array of options where:
  439.      *  - 'file_ext'                Contains an array of file extensions to parse
  440.      *                              for PHP code. Default: php, php4, inc, phtml
  441.      *  - 'debug'                   Contains a boolean to control whether
  442.      *                              extra ouput is shown.
  443.      *  - 'ignore_functions'        Contains an array of functions to ignore
  444.      *                              when calculating the version needed.
  445.      *  - 'ignore_constants'        Contains an array of constants to ignore
  446.      *                              when calculating the version needed.
  447.      *  - 'ignore_files'            Contains an array of files to ignore.
  448.      *                              File names are case insensitive.
  449.      *  - 'is_string'               Contains a boolean which says if the array values
  450.      *                              are strings or file names.
  451.      *  - 'ignore_extensions'       Contains an array of php extensions to ignore
  452.      *                              when calculating the version needed.
  453.      *  - 'ignore_versions'         Contains an array of php versions to ignore
  454.      *                              when calculating the version needed.
  455.      *  - 'ignore_functions_match'  Contains an array of function patterns to ignore
  456.      *                              when calculating the version needed.
  457.      *  - 'ignore_extensions_match' Contains an array of extension patterns to ignore
  458.      *                              when calculating the version needed.
  459.      *  - 'ignore_constants_match'  Contains an array of constant patterns to ignore
  460.      *                              when calculating the version needed.
  461.      *
  462.      * @access public
  463.      * @return array|false
  464.      * @since  version 0.7.0 (2004-03-09)
  465.      */
  466.     function parseArray($files, $options = array())
  467.     {
  468.         $files_parsed       = array();
  469.         $latest_version     = $this->latest_version;
  470.         $earliest_version   = $this->earliest_version;
  471.         $extensions         = array();
  472.         $constants          = array();
  473.         $tokens             = array();
  474.         $ignored            = array();
  475.         $ignored_functions  = array();
  476.         $ignored_extensions = array();
  477.         $ignored_constants  = array();
  478.         $function_exists    = array();
  479.         $extension_loaded   = array();
  480.         $defined            = array();
  481.         $cond_code          = 0;
  482.  
  483.         $options = array_merge(array(
  484.             'file_ext' => array('php', 'php4', 'inc', 'phtml'),
  485.             'is_string' => false,
  486.             'debug' => false,
  487.             'ignore_files' => array()
  488.             ), $options);
  489.  
  490.         $options['ignore_files'] = array_map('strtolower', $options['ignore_files']);
  491.         foreach ($files as $file) {
  492.             if ($options['is_string'] === false) {
  493.                 $pathinfo = pathinfo($file);
  494.                 if (!in_array(strtolower($file), $options['ignore_files'])
  495.                     && in_array($pathinfo['extension'], $options['file_ext'])) {
  496.                     $tokens_list = $this->_tokenize($file, $options['is_string']);
  497.                     $files_parsed[$file]
  498.                             = $this->_parseTokens($tokens_list, $options);
  499.                 } else {
  500.                     $ignored[] = $file;
  501.                 }
  502.             } else {
  503.                 $token_list     = $this->_tokenize($file, $options['is_string']);
  504.                 $files_parsed[] = $this->_parseTokens($token_list, $options);
  505.             }
  506.         }
  507.  
  508.         foreach ($files_parsed as $i => $file) {
  509.             $cmp = version_compare($latest_version, $file['version']);
  510.             if ($cmp === -1) {
  511.                 $latest_version = $file['version'];
  512.             }
  513.             if ($file['max_version'] != '') {
  514.                 $cmp = version_compare($earliest_version, $file['max_version']);
  515.                 if ($earliest_version == '' || $cmp === 1) {
  516.                     $earliest_version = $file['max_version'];
  517.                 }
  518.             }
  519.             foreach ($file['extensions'] as $ext) {
  520.                 if (!in_array($ext, $extensions)) {
  521.                     $extensions[] = $ext;
  522.                 }
  523.             }
  524.             foreach ($file['constants'] as $const) {
  525.                 if (!in_array($const, $constants)) {
  526.                     $constants[] = $const;
  527.                 }
  528.             }
  529.             foreach ($file['tokens'] as $token) {
  530.                 if (!in_array($token, $tokens)) {
  531.                     $tokens[] = $token;
  532.                 }
  533.             }
  534.             foreach ($file['ignored_functions'] as $if) {
  535.                 if (!in_array($if, $ignored_functions)) {
  536.                     $ignored_functions[] = $if;
  537.                 }
  538.             }
  539.             foreach ($file['ignored_extensions'] as $ie) {
  540.                 if (!in_array($ie, $ignored_extensions)) {
  541.                     $ignored_extensions[] = $ie;
  542.                 }
  543.             }
  544.             foreach ($file['ignored_constants'] as $ic) {
  545.                 if (!in_array($ic, $ignored_constants)) {
  546.                     $ignored_constants[] = $ic;
  547.                 }
  548.             }
  549.             foreach ($file['cond_code'][1][0] as $ccf) {
  550.                 if (!in_array($ccf, $function_exists)) {
  551.                     $function_exists[] = $ccf;
  552.                 }
  553.             }
  554.             foreach ($file['cond_code'][1][1] as $cce) {
  555.                 if (!in_array($cce, $extension_loaded)) {
  556.                     $extension_loaded[] = $cce;
  557.                 }
  558.             }
  559.             foreach ($file['cond_code'][1][2] as $ccc) {
  560.                 if (!in_array($ccc, $defined)) {
  561.                     $defined[] = $ccc;
  562.                 }
  563.             }
  564.             if ($options['debug'] === false) {
  565.                 $files_parsed[$i]['cond_code'][1][0] = array();
  566.                 $files_parsed[$i]['cond_code'][1][1] = array();
  567.                 $files_parsed[$i]['cond_code'][1][2] = array();
  568.             }
  569.         }
  570.  
  571.         if (count($files_parsed) == 0) {
  572.             return false;
  573.         }
  574.  
  575.         if (count($function_exists) > 0) {
  576.             $cond_code += 1;
  577.         }
  578.         if (count($extension_loaded) > 0) {
  579.             $cond_code += 2;
  580.         }
  581.         if (count($defined) > 0) {
  582.             $cond_code += 4;
  583.         }
  584.         if ($options['debug'] === false) {
  585.             $function_exists  = array();
  586.             $extension_loaded = array();
  587.             $defined          = array();
  588.         }
  589.         $cond_code = array($cond_code,
  590.                            array($function_exists, $extension_loaded, $defined));
  591.  
  592.         $main_info = array('ignored_files'      => $ignored,
  593.                            'ignored_functions'  => $ignored_functions,
  594.                            'ignored_extensions' => $ignored_extensions,
  595.                            'ignored_constants'  => $ignored_constants,
  596.                            'max_version'   => $earliest_version,
  597.                            'version'       => $latest_version,
  598.                            'extensions'    => $extensions,
  599.                            'constants'     => $constants,
  600.                            'tokens'        => $tokens,
  601.                            'cond_code'     => $cond_code);
  602.  
  603.         $files_parsed = array_merge($main_info, $files_parsed);
  604.         return $files_parsed;
  605.     }
  606.  
  607.     /**
  608.      * Load components list
  609.      *
  610.      * Load components list for a PHP version or subset
  611.      *
  612.      * @param string         $min           PHP minimal version
  613.      * @param string|boolean $max           (optional) PHP maximal version
  614.      * @param boolean        $include_const (optional) include constants list
  615.      *                                                 in final result
  616.      *
  617.      * @return array         An array of php function/constant names to ignore
  618.      * @access public
  619.      * @static
  620.      * @since  version 1.2.0 (2006-08-23)
  621.      */
  622.     function loadVersion($min, $max = false, $include_const = false)
  623.     {
  624.         $keys = array();
  625.         foreach ($GLOBALS['_PHP_COMPATINFO_FUNCS'] as $func => $arr) {
  626.             if (isset($arr['pecl']) && $arr['pecl'] === true) {
  627.                 continue;
  628.             }
  629.             if (version_compare($arr['init'], $min) < 0) {
  630.                 continue;
  631.             }
  632.             if ($max) {
  633.                 $end = (isset($arr['end'])) ? $arr['end'] : $arr['init'];
  634.  
  635.                 if (version_compare($end, $max) < 1) {
  636.                     $keys[] = $func;
  637.                 }
  638.             } else {
  639.                 $keys[] = $func;
  640.             }
  641.         }
  642.  
  643.         if ($include_const === true) {
  644.             $keys = array('functions' => $keys, 'constants' => array());
  645.             foreach ($GLOBALS['_PHP_COMPATINFO_CONST'] as $const => $arr) {
  646.                 if (version_compare($arr['init'], $min) < 0) {
  647.                     continue;
  648.                 }
  649.                 if ($max) {
  650.                     $end = (isset($arr['end'])) ? $arr['end'] : $arr['init'];
  651.  
  652.                     if (version_compare($end, $max) < 1) {
  653.                         $keys['constants'][] = $arr['name'];
  654.                     }
  655.                 } else {
  656.                     $keys['constants'][] = $arr['name'];
  657.                 }
  658.             }
  659.         }
  660.         return $keys;
  661.     }
  662.  
  663.     /**
  664.      * Parse the given Tokens
  665.      *
  666.      * The tokens are those returned by
  667.      * token_get_all() which is nicely
  668.      * wrapped in PHP_CompatInfo::_tokenize
  669.      *
  670.      * @param array   $tokens  Array of PHP Tokens
  671.      * @param boolean $options Show Extra Output
  672.      *
  673.      * @access private
  674.      * @return array
  675.      * @since  version 0.7.0 (2004-03-09)
  676.      */
  677.     function _parseTokens($tokens, $options)
  678.     {
  679.         static $akeys;
  680.  
  681.         $functions          = array();
  682.         $functions_version  = array();
  683.         $latest_version     = $this->latest_version;
  684.         $earliest_version   = $this->earliest_version;
  685.         $extensions         = array();
  686.         $constants          = array();
  687.         $constant_names     = array();
  688.         $token_names        = array();
  689.         $udf                = array();
  690.         $ignore_functions   = array();
  691.         $ignored_functions  = array();
  692.         $ignore_extensions  = array();
  693.         $ignored_extensions = array();
  694.         $ignore_constants   = array();
  695.         $ignored_constants  = array();
  696.         $function_exists    = array();
  697.         $extension_loaded   = array();
  698.         $defined            = array();
  699.         $cond_code          = 0;
  700.  
  701.         if (isset($options['ignore_constants'])) {
  702.             $options['ignore_constants']
  703.                 = array_map('strtoupper', $options['ignore_constants']);
  704.         } else {
  705.             $options['ignore_constants'] = array();
  706.         }
  707.         if (isset($options['ignore_extensions'])) {
  708.             $options['ignore_extensions']
  709.                 = array_map('strtolower', $options['ignore_extensions']);
  710.         } else {
  711.             $options['ignore_extensions'] = array();
  712.         }
  713.         if (isset($options['ignore_versions'][0])) {
  714.             $min_ver = $options['ignore_versions'][0];
  715.         } else {
  716.             $min_ver = false;
  717.         }
  718.         if (isset($options['ignore_versions'][1])) {
  719.             $max_ver = $options['ignore_versions'][1];
  720.         } else {
  721.             $max_ver = false;
  722.         }
  723.  
  724.         if (isset($options['ignore_functions_match'])) {
  725.             list($ifm_compare, $ifm_patterns) = $options['ignore_functions_match'];
  726.         } else {
  727.             $ifm_compare = false;
  728.         }
  729.         if (isset($options['ignore_extensions_match'])) {
  730.             list($iem_compare, $iem_patterns) = $options['ignore_extensions_match'];
  731.         } else {
  732.             $iem_compare = false;
  733.         }
  734.         if (isset($options['ignore_constants_match'])) {
  735.             list($icm_compare, $icm_patterns) = $options['ignore_constants_match'];
  736.         } else {
  737.             $icm_compare = false;
  738.         }
  739.  
  740.         $token_count = sizeof($tokens);
  741.         $i           = 0;
  742.         $found_class = false;
  743.         while ($i < $token_count) {
  744.             if ($this->_isToken($tokens[$i], 'T_FUNCTION')) {
  745.                 $found_func = false;
  746.             } else {
  747.                 $found_func = true;
  748.             }
  749.             while ($found_func == false) {
  750.                 $i += 1;
  751.                 if ($this->_isToken($tokens[$i], 'T_STRING')) {
  752.                     $found_func = true;
  753.                     $func       = $tokens[$i][1];
  754.                     if ($found_class === false
  755.                         || in_array($func, $function_exists)) {
  756.                         $udf[] = $func;
  757.                     }
  758.                 }
  759.             }
  760.  
  761.             // Try to detect PHP method chaining implementation
  762.             if ($this->_isToken($tokens[$i], 'T_VARIABLE')
  763.                 && $this->_isToken($tokens[$i+1], 'T_OBJECT_OPERATOR')
  764.                 && $this->_isToken($tokens[$i+2], 'T_STRING')
  765.                 && $this->_isToken($tokens[$i+3], '(')) {
  766.  
  767.                 $i                   += 3;
  768.                 $php5_method_chaining = false;
  769.                 while ((!is_array($tokens[$i]) && $tokens[$i] == ';') === false) {
  770.                     $i += 1;
  771.                     if ((($this->_isToken($tokens[$i], ')'))
  772.                         || ($this->_isToken($tokens[$i], 'T_WHITESPACE')))
  773.                         && $this->_isToken($tokens[$i+1], 'T_OBJECT_OPERATOR')) {
  774.  
  775.                         $php5_method_chaining = true;
  776.                     }
  777.                 }
  778.             }
  779.  
  780.             // Compare "ignore_functions_match" pre-condition
  781.             if (is_string($ifm_compare)) {
  782.                 if (strcasecmp('preg_match', $ifm_compare) != 0) {
  783.                     // Try to catch function_exists() condition
  784.                     if ($this->_isToken($tokens[$i], 'T_STRING')
  785.                         && (strcasecmp($tokens[$i][1], $ifm_compare) == 0)) {
  786.  
  787.                         while ((!$this->_isToken($tokens[$i],
  788.                                                  'T_CONSTANT_ENCAPSED_STRING'))) {
  789.                             $i += 1;
  790.                         }
  791.                         $func = trim($tokens[$i][1], "'");
  792.  
  793.                         /**
  794.                          * try if function_exists()
  795.                          * match one or more pattern condition
  796.                          */
  797.                         foreach ($ifm_patterns as $pattern) {
  798.                             if (preg_match($pattern, $func) === 1) {
  799.                                 $ignore_functions[] = $func;
  800.                             }
  801.                         }
  802.                     }
  803.                 }
  804.             }
  805.  
  806.             // Compare "ignore_extensions_match" pre-condition
  807.             if (is_string($iem_compare)) {
  808.                 if (strcasecmp('preg_match', $iem_compare) != 0) {
  809.                     // Try to catch extension_loaded() condition
  810.                     if ($this->_isToken($tokens[$i], 'T_STRING')
  811.                         && (strcasecmp($tokens[$i][1], $iem_compare) == 0)) {
  812.  
  813.                         while ((!$this->_isToken($tokens[$i],
  814.                                                  'T_CONSTANT_ENCAPSED_STRING'))) {
  815.                             $i += 1;
  816.                         }
  817.                         $ext = trim($tokens[$i][1], "'");
  818.  
  819.                         /**
  820.                          * try if extension_loaded()
  821.                          * match one or more pattern condition
  822.                          */
  823.                         foreach ($iem_patterns as $pattern) {
  824.                             if (preg_match($pattern, $ext) === 1) {
  825.                                 $ignore_extensions[] = $ext;
  826.                             }
  827.                         }
  828.                     }
  829.                 }
  830.             }
  831.  
  832.             // Compare "ignore_constants_match" pre-condition
  833.             if (is_string($icm_compare)) {
  834.                 if (strcasecmp('preg_match', $icm_compare) != 0) {
  835.                     // Try to catch defined() condition
  836.                     if ($this->_isToken($tokens[$i], 'T_STRING')
  837.                         && (strcasecmp($tokens[$i][1], $icm_compare) == 0)) {
  838.  
  839.                         while ((!$this->_isToken($tokens[$i],
  840.                                                  'T_CONSTANT_ENCAPSED_STRING'))) {
  841.                             $i += 1;
  842.                         }
  843.                         $cst = trim($tokens[$i][1], "'");
  844.  
  845.                         /**
  846.                          * try if defined()
  847.                          * match one or more pattern condition
  848.                          */
  849.                         foreach ($icm_patterns as $pattern) {
  850.                             if (preg_match($pattern, $cst) === 1) {
  851.                                 $ignore_constants[] = $cst;
  852.                             }
  853.                         }
  854.                     }
  855.                 }
  856.             }
  857.  
  858.             if ($this->_isToken($tokens[$i], 'T_STRING')
  859.                 && (isset($tokens[$i+1]))
  860.                 && $this->_isToken($tokens[$i+1], '(')) {
  861.  
  862.                 $is_function = false;
  863.  
  864.                 if (isset($tokens[$i-1])
  865.                     && !$this->_isToken($tokens[$i-1], 'T_DOUBLE_COLON')
  866.                     && !$this->_isToken($tokens[$i-1], 'T_OBJECT_OPERATOR')) {
  867.  
  868.                     if (isset($tokens[$i-2])
  869.                         && $this->_isToken($tokens[$i-2], 'T_FUNCTION')) {
  870.                         // its a function declaration
  871.                     } else {
  872.                         $is_function = true;
  873.                     }
  874.                 }
  875.                 if ($is_function == true || !is_array($tokens[$i-1])) {
  876.                     $functions[] = strtolower($tokens[$i][1]);
  877.                 }
  878.             }
  879.  
  880.             // try to detect condition function_exists()
  881.             if ($this->_isToken($tokens[$i], 'T_STRING')
  882.                 && (strcasecmp($tokens[$i][1], 'function_exists') == 0)) {
  883.  
  884.                 $j = $i;
  885.                 while ((!$this->_isToken($tokens[$j],
  886.                                          'T_CONSTANT_ENCAPSED_STRING'))) {
  887.                     $j++;
  888.                 }
  889.                 $t_string          = $tokens[$j][1];
  890.                 $t_string          = trim($t_string, "'");
  891.                 $t_string          = trim($t_string, '"');
  892.                 $function_exists[] = $t_string;
  893.             }
  894.             // try to detect condition extension_loaded()
  895.             if ($this->_isToken($tokens[$i], 'T_STRING')
  896.                 && (strcasecmp($tokens[$i][1], 'extension_loaded') == 0)) {
  897.  
  898.                 $j = $i;
  899.                 while ((!$this->_isToken($tokens[$j],
  900.                                          'T_CONSTANT_ENCAPSED_STRING'))) {
  901.                     $j++;
  902.                 }
  903.                 $t_string           = $tokens[$j][1];
  904.                 $t_string           = trim($t_string, "'");
  905.                 $t_string           = trim($t_string, '"');
  906.                 $extension_loaded[] = $t_string;
  907.             }
  908.             // try to detect condition defined()
  909.             if ($this->_isToken($tokens[$i], 'T_STRING')
  910.                 && (strcasecmp($tokens[$i][1], 'defined') == 0)) {
  911.  
  912.                 $j = $i;
  913.                 while ((!$this->_isToken($tokens[$j],
  914.                                          'T_CONSTANT_ENCAPSED_STRING'))) {
  915.                     $j++;
  916.                 }
  917.                 $t_string  = $tokens[$j][1];
  918.                 $t_string  = trim($t_string, "'");
  919.                 $t_string  = trim($t_string, '"');
  920.                 $defined[] = $t_string;
  921.             }
  922.  
  923.             // try to detect beginning of a class
  924.             if ($this->_isToken($tokens[$i], 'T_CLASS')) {
  925.                 $found_class = true;
  926.             }
  927.  
  928.             if (is_array($tokens[$i])) {
  929.                 if (!isset($akeys)) {
  930.                     // build contents one time only (static variable)
  931.                     $akeys = array_keys($GLOBALS['_PHP_COMPATINFO_CONST']);
  932.                 }
  933.                 $const = strtoupper($tokens[$i][1]);
  934.                 $found = array_search($const, $akeys);
  935.                 if ($found !== false) {
  936.                     if ($this->_isToken($tokens[$i], 'T_ENCAPSED_AND_WHITESPACE')) {
  937.                         // PHP 5 constant tokens found into a string
  938.                     } else {
  939.                         // Compare "ignore_constants_match" free condition
  940.                         $icm_preg_match = false;
  941.                         if (is_string($icm_compare)) {
  942.                             if (strcasecmp('preg_match', $icm_compare) == 0) {
  943.                                 /**
  944.                                  * try if preg_match()
  945.                                  * match one or more pattern condition
  946.                                  */
  947.                                 foreach ($icm_patterns as $pattern) {
  948.                                     if (preg_match($pattern, $const) === 1) {
  949.                                         $icm_preg_match = true;
  950.                                         break;
  951.                                     }
  952.                                 }
  953.                             }
  954.                         }
  955.  
  956.                         $init = $GLOBALS['_PHP_COMPATINFO_CONST'][$const]['init'];
  957.                         if (!PHP_CompatInfo::_ignore($init, $min_ver, $max_ver)) {
  958.                             $constants[] = $const;
  959.                             if (in_array($const, $ignore_constants)
  960.                                 || in_array($const, $options['ignore_constants'])
  961.                                 || $icm_preg_match) {
  962.                                 $ignored_constants[] = $const;
  963.                             } else {
  964.                                 $latest_version = $init;
  965.                             }
  966.                         }
  967.                     }
  968.                 }
  969.             }
  970.             $i += 1;
  971.         }
  972.  
  973.         $functions = array_unique($functions);
  974.         if (isset($options['ignore_functions'])) {
  975.             $options['ignore_functions']
  976.                 = array_map('strtolower', $options['ignore_functions']);
  977.         } else {
  978.             $options['ignore_functions'] = array();
  979.         }
  980.         if (count($ignore_functions) > 0) {
  981.             $ignore_functions = array_map('strtolower', $ignore_functions);
  982.             $options['ignore_functions']
  983.                 = array_merge($options['ignore_functions'], $ignore_functions);
  984.             $options['ignore_functions']
  985.                 = array_unique($options['ignore_functions']);
  986.         }
  987.         if (count($ignore_extensions) > 0) {
  988.             $ignore_extensions = array_map('strtolower', $ignore_extensions);
  989.             $options['ignore_extensions']
  990.                 = array_merge($options['ignore_extensions'], $ignore_extensions);
  991.             $options['ignore_extensions']
  992.                 = array_unique($options['ignore_extensions']);
  993.         }
  994.  
  995.         foreach ($functions as $name) {
  996.             if (!isset($GLOBALS['_PHP_COMPATINFO_FUNCS'][$name])) {
  997.                 continue;  // skip this unknown function
  998.             }
  999.             $func = $GLOBALS['_PHP_COMPATINFO_FUNCS'][$name];
  1000.  
  1001.             // retrieve if available the extension name
  1002.             if ((isset($func['ext']))
  1003.                 && ($func['ext'] != 'ext_standard')
  1004.                 && ($func['ext'] != 'zend')) {
  1005.                 if ($func['pecl'] === false) {
  1006.                     $extension = substr($func['ext'], 4);
  1007.                     if ($extension{0} == '_') {
  1008.                         $extension = $func['ext'];
  1009.                     }
  1010.                 } else {
  1011.                     $extension = $func['ext'];
  1012.                 }
  1013.             } else {
  1014.                 $extension = false;
  1015.             }
  1016.  
  1017.             // Compare "ignore_functions_match" free condition
  1018.             $ifm_preg_match = false;
  1019.             if (is_string($ifm_compare)) {
  1020.                 if (strcasecmp('preg_match', $ifm_compare) == 0) {
  1021.                     /**
  1022.                      * try if preg_match()
  1023.                      * match one or more pattern condition
  1024.                      */
  1025.                     foreach ($ifm_patterns as $pattern) {
  1026.                         if (preg_match($pattern, $name) === 1) {
  1027.                             $ifm_preg_match = true;
  1028.                             break;
  1029.                         }
  1030.                     }
  1031.                 }
  1032.             }
  1033.  
  1034.             if ((!in_array($name, $udf))
  1035.                 && (!in_array($name, $options['ignore_functions']))
  1036.                 && ($ifm_preg_match === false)) {
  1037.  
  1038.                 if ($extension && !in_array($extension, $extensions)) {
  1039.                     $extensions[] = substr($func['ext'], 0, 4) == 'ext_'
  1040.                         ? $extension : $func['ext'];
  1041.                 }
  1042.  
  1043.                 // Compare "ignore_extensions_match" free condition
  1044.                 $iem_preg_match = false;
  1045.                 if (is_string($iem_compare)) {
  1046.                     if (strcasecmp('preg_match', $iem_compare) == 0) {
  1047.                         /**
  1048.                          * try if preg_match()
  1049.                          * match one or more pattern condition
  1050.                          */
  1051.                         foreach ($iem_patterns as $pattern) {
  1052.                             if (preg_match($pattern, $extension) === 1) {
  1053.                                 $iem_preg_match = true;
  1054.                                 break;
  1055.                             }
  1056.                         }
  1057.                     }
  1058.                 }
  1059.  
  1060.                 if ($extension
  1061.                     && (in_array($extension, $options['ignore_extensions'])
  1062.                         || $iem_preg_match)) {
  1063.                     if (!in_array($extension, $ignored_extensions)) {
  1064.                         // extension is ignored (only once)
  1065.                         $ignored_extensions[] = $extension;
  1066.                     }
  1067.                     // all extension functions are also ignored
  1068.                     $ignored_functions[] = $name;
  1069.                     continue;  // skip this extension function
  1070.                 }
  1071.  
  1072.                 if (PHP_CompatInfo::_ignore($func['init'], $min_ver, $max_ver)) {
  1073.                     continue;  // skip this function version
  1074.                 }
  1075.  
  1076.                 if ($options['debug'] == true) {
  1077.                     $functions_version[$func['init']][] = array(
  1078.                         'function' => $name,
  1079.                         'extension' => substr($func['ext'], 0, 4) == 'ext_'
  1080.                             ? $extension : $func['ext'],
  1081.                         'pecl' => $func['pecl']
  1082.                         );
  1083.                 }
  1084.                 if ($extension === false
  1085.                     || (isset($func['pecl']) && $func['pecl'] === false) ) {
  1086.                     $cmp = version_compare($latest_version, $func['init']);
  1087.                     if ($cmp === -1) {
  1088.                         $latest_version = $func['init'];
  1089.                     }
  1090.                     if (array_key_exists('end', $func)) {
  1091.                         $cmp = version_compare($earliest_version, $func['end']);
  1092.                         if ($earliest_version == '' || $cmp === 1) {
  1093.                             $earliest_version = $func['end'];
  1094.                         }
  1095.                     }
  1096.                 }
  1097.  
  1098.             } else {
  1099.                 // function is ignored
  1100.                 $ignored_functions[] = $name;
  1101.             }
  1102.         }
  1103.  
  1104.         $ignored_constants = array_unique($ignored_constants);
  1105.         $constants         = array_unique($constants);
  1106.         foreach ($constants as $constant) {
  1107.             $const = $GLOBALS['_PHP_COMPATINFO_CONST'][$constant];
  1108.             if (PHP_CompatInfo::_ignore($const['init'], $min_ver, $max_ver)) {
  1109.                 continue;  // skip this constant version
  1110.             }
  1111.             if (!in_array($constant, $ignored_constants)) {
  1112.                 $cmp = version_compare($latest_version, $const['init']);
  1113.                 if ($cmp === -1) {
  1114.                     $latest_version = $const['init'];
  1115.                 }
  1116.                 if (array_key_exists('end', $const)) {
  1117.                     $cmp = version_compare($earliest_version, $const['end']);
  1118.                     if ($earliest_version == '' || $cmp === 1) {
  1119.                         $earliest_version = $const['end'];
  1120.                     }
  1121.                 }
  1122.             }
  1123.             if (!in_array($const['name'], $constant_names)) {
  1124.                 // split PHP5 tokens and pure PHP constants
  1125.                 if ($const['name'] == strtolower($const['name'])) {
  1126.                     $token_names[] = $const['name'];
  1127.                 } else {
  1128.                     $constant_names[] = $const['name'];
  1129.                 }
  1130.             }
  1131.         }
  1132.  
  1133.         if (isset($php5_method_chaining)
  1134.             && $php5_method_chaining === true
  1135.             && version_compare($latest_version, '5.0.0') < 0) {
  1136.             // when PHP Method chaining is detected, only available for PHP 5
  1137.             $latest_version = '5.0.0';
  1138.         }
  1139.  
  1140.         ksort($functions_version);
  1141.  
  1142.         if (count($function_exists) > 0) {
  1143.             $cond_code += 1;
  1144.         }
  1145.         if (count($extension_loaded) > 0) {
  1146.             $cond_code += 2;
  1147.         }
  1148.         if (count($defined) > 0) {
  1149.             $cond_code += 4;
  1150.         }
  1151.         $cond_code = array($cond_code,
  1152.                            array($function_exists, $extension_loaded, $defined));
  1153.  
  1154.         $main_info = array('ignored_functions'  => $ignored_functions,
  1155.                            'ignored_extensions' => $ignored_extensions,
  1156.                            'ignored_constants'  => $ignored_constants,
  1157.                            'max_version' => $earliest_version,
  1158.                            'version'     => $latest_version,
  1159.                            'extensions'  => $extensions,
  1160.                            'constants'   => $constant_names,
  1161.                            'tokens'      => $token_names,
  1162.                            'cond_code'   => $cond_code);
  1163.  
  1164.         $functions_version = array_merge($main_info, $functions_version);
  1165.         return $functions_version;
  1166.     }
  1167.  
  1168.     /**
  1169.      * Checks if function which has $init version should be keep
  1170.      * or ignore (version is between $min_ver and $max_ver).
  1171.      *
  1172.      * @param string $init    version of current function
  1173.      * @param string $min_ver minimum version of function to ignore
  1174.      * @param string $max_ver maximum version of function to ignore
  1175.      *
  1176.      * @access private
  1177.      * @return boolean True to ignore function/constant, false otherwise
  1178.      * @since  version 1.4.0 (2006-09-27)
  1179.      * @static
  1180.      */
  1181.     function _ignore($init, $min_ver, $max_ver)
  1182.     {
  1183.         if ($min_ver) {
  1184.             $cmp = version_compare($init, $min_ver);
  1185.             if ($max_ver && $cmp >= 0) {
  1186.                 $cmp = version_compare($init, $max_ver);
  1187.                 if ($cmp < 1) {
  1188.                     return true;
  1189.                 }
  1190.             } elseif ($cmp === 0) {
  1191.                 return true;
  1192.             }
  1193.         }
  1194.         return false;
  1195.     }
  1196.  
  1197.     /**
  1198.      * Token a file or string
  1199.      *
  1200.      * @param string  $input     Filename or PHP code
  1201.      * @param boolean $is_string Whether or note the input is a string
  1202.      * @param boolean $debug     add token names for human read
  1203.      *
  1204.      * @access private
  1205.      * @return array
  1206.      * @since  version 0.7.0 (2004-03-09)
  1207.      */
  1208.     function _tokenize($input, $is_string = false, $debug = false)
  1209.     {
  1210.         if ($is_string === false) {
  1211.             $input = file_get_contents($input, true);
  1212.         }
  1213.         $tokens = token_get_all($input);
  1214.  
  1215.         if ($debug === true) {
  1216.             $r = array();
  1217.             foreach ($tokens as $token) {
  1218.                 if (is_array($token)) {
  1219.                     $token[] = token_name($token[0]);
  1220.                 } else {
  1221.                     $token = $token[0];
  1222.                 }
  1223.                 $r[] = $token;
  1224.             }
  1225.         } else {
  1226.             $r = $tokens;
  1227.         }
  1228.         return $r;
  1229.     }
  1230.  
  1231.     /**
  1232.      * Checks if the given token is of this symbolic name
  1233.      *
  1234.      * @param mixed  $token    Single PHP token to test
  1235.      * @param string $symbolic Symbolic name of the given token
  1236.      *
  1237.      * @access private
  1238.      * @return bool
  1239.      * @since  version 1.7.0b4 (2008-04-03)
  1240.      */
  1241.     function _isToken($token, $symbolic)
  1242.     {
  1243.         if (is_array($token)) {
  1244.             $t = token_name($token[0]);
  1245.         } else {
  1246.             $t = $token;
  1247.         }
  1248.         return ($t == $symbolic);
  1249.     }
  1250. }
  1251. ?>