Rev Author Line No. Line
139 root 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.19 2005/05/10 12:05:36 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.19 $
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 // Recursiveness
45 if (is_array($function)) {
46 $res = array();
47 foreach ($function as $singlefunc) {
48 $res[$singlefunc] = PHP_Compat::loadFunction($singlefunc);
49 }
50  
51 return $res;
52 }
53  
54 // Load function
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 // Recursiveness
75 if (is_array($constant)) {
76 $res = array();
77 foreach ($constant as $singleconst) {
78 $res[$singleconst] = PHP_Compat::loadConstant($singleconst);
79 }
80  
81 return $res;
82 }
83  
84 // Load constant
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 components for a PHP version
96 *
97 * @param string $version PHP Version to load
98 * @return array An associative array of component names loaded
99 */
100 function loadVersion($version = null)
101 {
102 // Include list of components
103 require 'PHP/Compat/Components.php';
104  
105 // Include version_compare to work with older versions
106 PHP_Compat::loadFunction('version_compare');
107  
108 // Init
109 $phpversion = phpversion();
110 $methods = array(
111 'function' => 'loadFunction',
112 'constant' => 'loadConstant');
113 $res = array();
114  
115 // Iterate each component
116 foreach ($components as $type => $slice) {
117 foreach ($slice as $component => $compversion) {
118 if (($version === null &&
119 1 === version_compare($compversion, $phpversion)) || // C > PHP
120 (0 === version_compare($compversion, $version) || // C = S
121 1 === version_compare($compversion, $phpversion))) { // C > PHP
122  
123 $res[$type][$component] =
124 call_user_func(array('PHP_Compat', $methods[$type]), $component);
125 }
126 }
127 }
128  
129 return $res;
130 }
131 }
132  
130 kaklik 133 ?>