PHP_Compat
[ class tree: PHP_Compat ] [ index: PHP_Compat ] [ all elements ]

Source for file Compat.php

Documentation is available at Compat.php

  1. <?php
  2. // $Id: Compat.php,v 1.22 2007/04/17 10:09:55 arpad Exp $
  3.  
  4.  
  5. /**
  6.  * Provides missing functionality in the form of constants and functions
  7.  *   for older versions of PHP
  8.  *
  9.  * Optionally, you may simply include the file.
  10.  *   e.g. require_once 'PHP/Compat/Function/scandir.php';
  11.  *
  12.  * @category    PHP
  13.  * @package     PHP_Compat
  14.  * @license     LGPL - http://www.gnu.org/licenses/lgpl.html
  15.  * @copyright   2004-2007 Aidan Lister <aidan@php.net>, Arpad Ray <arpad@php.net>
  16.  * @version     $Revision: 1.22 $
  17.  * @author      Aidan Lister <aidan@php.net>
  18.  * @static
  19.  */
  20. class PHP_Compat
  21. {
  22.     /**
  23.      * Load a function, or array of functions
  24.      *
  25.      * @param   string|array   $function   The function or functions to load
  26.      * @return  bool|array     TRUE if loaded, FALSE if not
  27.      */
  28.     function loadFunction($function)
  29.     {
  30.         // Multiple
  31.         if (is_array($function)) {
  32.             $res = array();
  33.             foreach ($function as $singlefunc{
  34.                 $res[$singlefuncPHP_Compat::loadFunction($singlefunc);
  35.             }
  36.  
  37.             return $res;
  38.         }
  39.  
  40.         // Check for packages which can modify the function table at runtime
  41.         $symbolfuncs = array('rename_function''runkit_rename_function');
  42.         foreach ($symbolfuncs as $symbolfunc{
  43.             $renamedfunction 'php_compat_renamed' $function;
  44.             if (function_exists($symbolfunc&&
  45.                 function_exists($function&&
  46.                 !function_exists($renamedfunction)) {
  47.                     
  48.                 // Rename the core function
  49.                 rename_function($function$renamedfunction);
  50.                 break;
  51.         }
  52.  
  53.         // Single
  54.         if (!function_exists($function)) {
  55.             $file sprintf('PHP/Compat/Function/%s.php'$function);
  56.             if ((@include_once $file!== false{
  57.                 return true;
  58.             }
  59.         }
  60.  
  61.         return false;
  62.     }
  63.  
  64.  
  65.     /**
  66.      * Load a constant, or array of constants
  67.      *
  68.      * @param   string|array    $constant   The constant or constants to load
  69.      * @return  bool|array      TRUE if loaded, FALSE if not
  70.      */
  71.     function loadConstant($constant)
  72.     {
  73.         // Multiple
  74.         if (is_array($constant)) {
  75.             $res = array();
  76.             foreach ($constant as $singleconst{
  77.                 $res[$singleconstPHP_Compat::loadConstant($singleconst);
  78.             }
  79.  
  80.             return $res;
  81.         }
  82.  
  83.         // Single
  84.         $file sprintf('PHP/Compat/Constant/%s.php'$constant);
  85.         if ((@include_once $file!== false{
  86.             return true;
  87.         }
  88.  
  89.         return false;
  90.     }
  91.  
  92.  
  93.     /**
  94.      * Load an environment
  95.      *
  96.      * @param   string          $environment   The environment to load
  97.      * @param   string          $setting       Turn the environment on or off
  98.      * @return  bool            TRUE if loaded, FALSE if not
  99.      */
  100.     function loadEnvironment($environment$setting)
  101.     {
  102.         // Load environment
  103.         $file sprintf('PHP/Compat/Environment/%s_%s.php'$environment$setting);
  104.         if ((@include_once $file!== false{
  105.             return true;
  106.         }
  107.  
  108.         return false;
  109.     }
  110.  
  111.  
  112.     /**
  113.      * Load components for a PHP version
  114.      *
  115.      * @param   string      $version        PHP Version to load
  116.      * @return  array       An associative array of component names loaded
  117.      */
  118.     function loadVersion($version = null)
  119.     {
  120.         // Include list of components
  121.         require 'PHP/Compat/Components.php';
  122.  
  123.         // Include version_compare to work with older versions
  124.         PHP_Compat::loadFunction('version_compare');
  125.  
  126.         // Init
  127.         $phpversion phpversion();
  128.         $methods = array(
  129.             'function' => 'loadFunction',
  130.             'constant' => 'loadConstant');
  131.         $res = array();
  132.  
  133.         // Iterate each component
  134.         foreach ($components as $type => $slice{
  135.             foreach ($slice as $component => $compversion{
  136.                 if (($version === null &&
  137.                         1 === version_compare($compversion$phpversion)) ||    // C > PHP
  138.                        (0 === version_compare($compversion$version||        // C = S
  139.                         1 === version_compare($compversion$phpversion))) {    // C > PHP
  140.                     
  141.                     $res[$type][$component=
  142.                         call_user_func(array('PHP_Compat'$methods[$type])$component);
  143.                 }
  144.             }
  145.         }
  146.  
  147.         return $res;
  148.     }
  149. }

Documentation generated on Mon, 11 Mar 2019 15:01:54 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.