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.23 2007/06/16 11:13:27 aidan 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.23 $
  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.  
  54.         // Single
  55.         if (!function_exists($function)) {
  56.             $file sprintf('PHP/Compat/Function/%s.php'$function);
  57.             if ((@include_once $file!== false{
  58.                 return true;
  59.             }
  60.         }
  61.  
  62.         return false;
  63.     }
  64.  
  65.  
  66.     /**
  67.      * Load a constant, or array of constants
  68.      *
  69.      * @param   string|array   $constant   The constant or constants to load
  70.      * @return  bool|array     TRUE if loaded, FALSE if not
  71.      */
  72.     function loadConstant($constant)
  73.     {
  74.         // Multiple
  75.         if (is_array($constant)) {
  76.             $res = array();
  77.             foreach ($constant as $singleconst{
  78.                 $res[$singleconstPHP_Compat::loadConstant($singleconst);
  79.             }
  80.  
  81.             return $res;
  82.         }
  83.  
  84.         // Single
  85.         $file sprintf('PHP/Compat/Constant/%s.php'$constant);
  86.         if ((@include_once $file!== false{
  87.             return true;
  88.         }
  89.  
  90.         return false;
  91.     }
  92.  
  93.  
  94.     /**
  95.      * Load an environment
  96.      *
  97.      * @param   string          $environment   The environment to load
  98.      * @param   string          $setting       Turn the environment on or off
  99.      * @return  bool            TRUE if loaded, FALSE if not
  100.      */
  101.     function loadEnvironment($environment$setting)
  102.     {
  103.         // Load environment
  104.         $file sprintf('PHP/Compat/Environment/%s_%s.php'$environment$setting);
  105.         if ((@include_once $file!== false{
  106.             return true;
  107.         }
  108.  
  109.         return false;
  110.     }
  111.  
  112.  
  113.     /**
  114.      * Load components for a PHP version
  115.      *
  116.      * @param   string      $version        PHP Version to load
  117.      * @return  array       An associative array of component names loaded
  118.      */
  119.     function loadVersion($version = null)
  120.     {
  121.         // Include list of components
  122.         require 'PHP/Compat/Components.php';
  123.  
  124.         // Include version_compare to work with older versions
  125.         PHP_Compat::loadFunction('version_compare');
  126.  
  127.         // Init
  128.         $phpversion phpversion();
  129.         $methods = array(
  130.             'function' => 'loadFunction',
  131.             'constant' => 'loadConstant');
  132.         $res = array();
  133.  
  134.         // Iterate each component
  135.         foreach ($components as $type => $slice{
  136.             foreach ($slice as $component => $compversion{
  137.                 if (($version === null &&
  138.                         1 === version_compare($compversion$phpversion)) ||    // C > PHP
  139.                        (0 === version_compare($compversion$version||        // C = S
  140.                         1 === version_compare($compversion$phpversion))) {    // C > PHP
  141.  
  142.                     $res[$type][$component=
  143.                         call_user_func(array('PHP_Compat'$methods[$type])$component);
  144.                 }
  145.             }
  146.         }
  147.  
  148.         return $res;
  149.     }
  150. }

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