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. // +----------------------------------------------------------------------+
  3. // | PHP Version 4                                                        |
  4. // +----------------------------------------------------------------------+
  5. // | Copyright (c) 1997-2004 The PHP Group                                |
  6. // +----------------------------------------------------------------------+
  7. // | This source file is subject to version 3.0 of the PHP license,       |
  8. // | that is bundled with this package in the file LICENSE, and is        |
  9. // | available at through the world-wide-web at                           |
  10. // | http://www.php.net/license/3_0.txt.                                  |
  11. // | If you did not receive a copy of the PHP license and are unable to   |
  12. // | obtain it through the world-wide-web, please send a note to          |
  13. // | license@php.net so we can mail you a copy immediately.               |
  14. // +----------------------------------------------------------------------+
  15. // | Authors: Aidan Lister <aidan@php.net>                                |
  16. // +----------------------------------------------------------------------+
  17. //
  18. // $Id: Compat.php,v 1.17 2004/11/23 09:25:40 aidan Exp $
  19.  
  20.  
  21. /**
  22.  * Provides missing functionality in the form of constants and functions
  23.  *   for older versions of PHP
  24.  *
  25.  * Optionally, you may simply include the file.
  26.  *   e.g. require_once 'PHP/Compat/Function/scandir.php';
  27.  *
  28.  * @category    PHP
  29.  * @package     PHP_Compat
  30.  * @version     $Revision: 1.17 $
  31.  * @author      Aidan Lister <aidan@php.net>
  32.  * @static
  33.  */
  34. class PHP_Compat
  35. {
  36.     /**
  37.      * Load a function, or array of functions
  38.      *
  39.      * @param   string|array   $function The function or functions to load
  40.      * @return  bool|array     TRUE if loaded, FALSE if not
  41.      */
  42.     function loadFunction($function)
  43.     {
  44.         if (is_array($function)) {
  45.             $res = array();
  46.             foreach ($function as $singlefunc{
  47.                 $res[$singlefuncPHP_Compat::loadFunction($singlefunc);
  48.             }
  49.  
  50.             return $res;
  51.         }
  52.  
  53.         if (!function_exists($function)) {
  54.             $file sprintf('PHP/Compat/Function/%s.php'$function);
  55.             if ((@include_once $file!== false{
  56.                 return true;
  57.             }
  58.         }
  59.  
  60.         return false;
  61.     }
  62.  
  63.  
  64.     /**
  65.      * Load a constant, or array of constants
  66.      *
  67.      * @param   string|array   $constant The constant or constants to load
  68.      * @return  bool|array     TRUE if loaded, FALSE if not
  69.      */
  70.     function loadConstant($constant)
  71.     {
  72.         if (is_array($constant)) {
  73.             $res = array();
  74.             foreach ($constant as $singleconst{
  75.                 $res[$singleconstPHP_Compat::loadConstant($singleconst);
  76.             }
  77.  
  78.             return $res;
  79.         }
  80.  
  81.         $file sprintf('PHP/Compat/Constant/%s.php'$constant);
  82.         if ((@include_once $file!== false{
  83.             return true;
  84.         }
  85.  
  86.         return false;
  87.     }
  88.  
  89.  
  90.     /**
  91.      * Load components for a PHP version
  92.      *
  93.      * @param   string      $version    PHP Version to load
  94.      * @return  array       An associative array of component names loaded
  95.      */
  96.     function loadVersion($version = null)
  97.     {
  98.         require_once 'Compat/Components.php';
  99.         PHP_Compat::loadFunction('version_compare');
  100.         $phpversion phpversion();
  101.  
  102.         $res = array();
  103.         foreach ($components as $type => $slice{
  104.             $loadfunc 'load' $type;
  105.             foreach ($slice as $component => $compversion{
  106.                 $vc version_compare($version$compversion);
  107.                 $vp version_compare($phpversion$compversion);
  108.  
  109.                 if ($version === null || ($vc === 0 && $vp === -1)) {
  110.                     $res[$componentPHP_Compat::$loadfunc($component);
  111.                 }
  112.             }
  113.         }
  114.  
  115.         return $res;
  116.     }
  117. }
  118.  
  119. ?>

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