first commit
This commit is contained in:
55
lib/compat/array_key_exists.php
Normal file
55
lib/compat/array_key_exists.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2004 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 3.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Aidan Lister <aidan@php.net> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: array_key_exists.php,v 1.1 2005/07/11 16:34:35 ggiunta Exp $
|
||||
|
||||
|
||||
/**
|
||||
* Replace array_key_exists()
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_Compat
|
||||
* @link http://php.net/function.array_key_exists
|
||||
* @author Aidan Lister <aidan@php.net>
|
||||
* @version $Revision: 1.1 $
|
||||
* @since PHP 4.1.0
|
||||
* @require PHP 4.0.0 (user_error)
|
||||
*/
|
||||
if (!function_exists('array_key_exists')) {
|
||||
function array_key_exists($key, $search)
|
||||
{
|
||||
if (!is_scalar($key)) {
|
||||
user_error('array_key_exists() The first argument should be either a string or an integer',
|
||||
E_USER_WARNING);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_object($search)) {
|
||||
$search = get_object_vars($search);
|
||||
}
|
||||
|
||||
if (!is_array($search)) {
|
||||
user_error('array_key_exists() The second argument should be either an array or an object',
|
||||
E_USER_WARNING);
|
||||
return false;
|
||||
}
|
||||
|
||||
return in_array($key, array_keys($search));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
47
lib/compat/is_a.php
Normal file
47
lib/compat/is_a.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2004 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 3.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Aidan Lister <aidan@php.net> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: is_a.php,v 1.2 2005/11/21 10:57:23 ggiunta Exp $
|
||||
|
||||
|
||||
/**
|
||||
* Replace function is_a()
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_Compat
|
||||
* @link http://php.net/function.is_a
|
||||
* @author Aidan Lister <aidan@php.net>
|
||||
* @version $Revision: 1.2 $
|
||||
* @since PHP 4.2.0
|
||||
* @require PHP 4.0.0 (user_error) (is_subclass_of)
|
||||
*/
|
||||
if (!function_exists('is_a')) {
|
||||
function is_a($object, $class)
|
||||
{
|
||||
if (!is_object($object)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (get_class($object) == strtolower($class)) {
|
||||
return true;
|
||||
} else {
|
||||
return is_subclass_of($object, $class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
53
lib/compat/is_callable.php
Normal file
53
lib/compat/is_callable.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* Replace function is_callable()
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_Compat
|
||||
* @link http://php.net/function.is_callable
|
||||
* @author Gaetano Giunta <giunta.gaetano@sea-aeroportimilano.it>
|
||||
* @version $Id: is_callable.php,v 1.3 2006/08/21 14:03:15 ggiunta Exp $
|
||||
* @since PHP 4.0.6
|
||||
* @require PHP 4.0.0 (true, false, etc...)
|
||||
* @todo add the 3rd parameter syntax...
|
||||
*/
|
||||
if (!function_exists('is_callable')) {
|
||||
function is_callable($var, $syntax_only=false)
|
||||
{
|
||||
if ($syntax_only)
|
||||
{
|
||||
/* from The Manual:
|
||||
* If the syntax_only argument is TRUE the function only verifies
|
||||
* that var might be a function or method. It will only reject simple
|
||||
* variables that are not strings, or an array that does not have a
|
||||
* valid structure to be used as a callback. The valid ones are
|
||||
* supposed to have only 2 entries, the first of which is an object
|
||||
* or a string, and the second a string
|
||||
*/
|
||||
return (is_string($var) || (is_array($var) && count($var) == 2 && is_string(end($var)) && (is_string(reset($var)) || is_object(reset($var)))));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (is_string($var))
|
||||
{
|
||||
return function_exists($var);
|
||||
}
|
||||
else if (is_array($var) && count($var) == 2 && is_string($method = end($var)))
|
||||
{
|
||||
$obj = reset($var);
|
||||
if (is_string($obj))
|
||||
{
|
||||
$methods = get_class_methods($obj);
|
||||
return (bool)(is_array($methods) && in_array(strtolower($method), $methods));
|
||||
}
|
||||
else if (is_object($obj))
|
||||
{
|
||||
return method_exists($obj, $method);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
38
lib/compat/is_scalar.php
Normal file
38
lib/compat/is_scalar.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2004 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 3.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: is_scalar.php,v 1.2 2005/11/21 10:57:23 ggiunta Exp $
|
||||
|
||||
|
||||
/**
|
||||
* Replace is_scalar()
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_Compat
|
||||
* @link http://php.net/function.is_scalar
|
||||
* @author Gaetano Giunta
|
||||
* @version $Revision: 1.2 $
|
||||
* @since PHP 4.0.5
|
||||
* @require PHP 4 (is_bool)
|
||||
*/
|
||||
if (!function_exists('is_scalar')) {
|
||||
function is_scalar($val)
|
||||
{
|
||||
// Check input
|
||||
return (is_bool($val) || is_int($val) || is_float($val) || is_string($val));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
105
lib/compat/var_export.php
Normal file
105
lib/compat/var_export.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2004 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 3.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Aidan Lister <aidan@php.net> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: var_export.php,v 1.2 2005/11/21 10:57:23 ggiunta Exp $
|
||||
|
||||
|
||||
/**
|
||||
* Replace var_export()
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_Compat
|
||||
* @link http://php.net/function.var_export
|
||||
* @author Aidan Lister <aidan@php.net>
|
||||
* @version $Revision: 1.2 $
|
||||
* @since PHP 4.2.0
|
||||
* @require PHP 4.0.0 (user_error)
|
||||
*/
|
||||
if (!function_exists('var_export')) {
|
||||
function var_export($array, $return = false, $lvl=0)
|
||||
{
|
||||
// Common output variables
|
||||
$indent = ' ';
|
||||
$doublearrow = ' => ';
|
||||
$lineend = ",\n";
|
||||
$stringdelim = '\'';
|
||||
|
||||
// Check the export isn't a simple string / int
|
||||
if (is_string($array)) {
|
||||
$out = $stringdelim . str_replace('\'', '\\\'', str_replace('\\', '\\\\', $array)) . $stringdelim;
|
||||
} elseif (is_int($array) || is_float($array)) {
|
||||
$out = (string)$array;
|
||||
} elseif (is_bool($array)) {
|
||||
$out = $array ? 'true' : 'false';
|
||||
} elseif (is_null($array)) {
|
||||
$out = 'NULL';
|
||||
} elseif (is_resource($array)) {
|
||||
$out = 'resource';
|
||||
} else {
|
||||
// Begin the array export
|
||||
// Start the string
|
||||
$out = "array (\n";
|
||||
|
||||
// Loop through each value in array
|
||||
foreach ($array as $key => $value) {
|
||||
// If the key is a string, delimit it
|
||||
if (is_string($key)) {
|
||||
$key = str_replace('\'', '\\\'', str_replace('\\', '\\\\', $key));
|
||||
$key = $stringdelim . $key . $stringdelim;
|
||||
}
|
||||
|
||||
$val = var_export($value, true, $lvl+1);
|
||||
// Delimit value
|
||||
/*if (is_array($value)) {
|
||||
// We have an array, so do some recursion
|
||||
// Do some basic recursion while increasing the indent
|
||||
$recur_array = explode($newline, var_export($value, true));
|
||||
$temp_array = array();
|
||||
foreach ($recur_array as $recur_line) {
|
||||
$temp_array[] = $indent . $recur_line;
|
||||
}
|
||||
$recur_array = implode($newline, $temp_array);
|
||||
$value = $newline . $recur_array;
|
||||
} elseif (is_null($value)) {
|
||||
$value = 'NULL';
|
||||
} else {
|
||||
$value = str_replace($find, $replace, $value);
|
||||
$value = $stringdelim . $value . $stringdelim;
|
||||
}*/
|
||||
|
||||
// Piece together the line
|
||||
for ($i = 0; $i < $lvl; $i++)
|
||||
$out .= $indent;
|
||||
$out .= $key . $doublearrow . $val . $lineend;
|
||||
}
|
||||
|
||||
// End our string
|
||||
for ($i = 0; $i < $lvl; $i++)
|
||||
$out .= $indent;
|
||||
$out .= ")";
|
||||
}
|
||||
|
||||
// Decide method of output
|
||||
if ($return === true) {
|
||||
return $out;
|
||||
} else {
|
||||
echo $out;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
179
lib/compat/version_compare.php
Normal file
179
lib/compat/version_compare.php
Normal file
@@ -0,0 +1,179 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2004 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 3.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Philippe Jausions <Philippe.Jausions@11abacus.com> |
|
||||
// | Aidan Lister <aidan@php.net> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: version_compare.php,v 1.1 2005/07/11 16:34:36 ggiunta Exp $
|
||||
|
||||
|
||||
/**
|
||||
* Replace version_compare()
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_Compat
|
||||
* @link http://php.net/function.version_compare
|
||||
* @author Philippe Jausions <Philippe.Jausions@11abacus.com>
|
||||
* @author Aidan Lister <aidan@php.net>
|
||||
* @version $Revision: 1.1 $
|
||||
* @since PHP 4.1.0
|
||||
* @require PHP 4.0.0 (user_error)
|
||||
*/
|
||||
if (!function_exists('version_compare')) {
|
||||
function version_compare($version1, $version2, $operator = '<')
|
||||
{
|
||||
// Check input
|
||||
if (!is_scalar($version1)) {
|
||||
user_error('version_compare() expects parameter 1 to be string, ' .
|
||||
gettype($version1) . ' given', E_USER_WARNING);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!is_scalar($version2)) {
|
||||
user_error('version_compare() expects parameter 2 to be string, ' .
|
||||
gettype($version2) . ' given', E_USER_WARNING);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!is_scalar($operator)) {
|
||||
user_error('version_compare() expects parameter 3 to be string, ' .
|
||||
gettype($operator) . ' given', E_USER_WARNING);
|
||||
return;
|
||||
}
|
||||
|
||||
// Standardise versions
|
||||
$v1 = explode('.',
|
||||
str_replace('..', '.',
|
||||
preg_replace('/([^0-9\.]+)/', '.$1.',
|
||||
str_replace(array('-', '_', '+'), '.',
|
||||
trim($version1)))));
|
||||
|
||||
$v2 = explode('.',
|
||||
str_replace('..', '.',
|
||||
preg_replace('/([^0-9\.]+)/', '.$1.',
|
||||
str_replace(array('-', '_', '+'), '.',
|
||||
trim($version2)))));
|
||||
|
||||
// Replace empty entries at the start of the array
|
||||
while (empty($v1[0]) && array_shift($v1)) {}
|
||||
while (empty($v2[0]) && array_shift($v2)) {}
|
||||
|
||||
// Release state order
|
||||
// '#' stands for any number
|
||||
$versions = array(
|
||||
'dev' => 0,
|
||||
'alpha' => 1,
|
||||
'a' => 1,
|
||||
'beta' => 2,
|
||||
'b' => 2,
|
||||
'RC' => 3,
|
||||
'#' => 4,
|
||||
'p' => 5,
|
||||
'pl' => 5);
|
||||
|
||||
// Loop through each segment in the version string
|
||||
$compare = 0;
|
||||
for ($i = 0, $x = min(count($v1), count($v2)); $i < $x; $i++) {
|
||||
if ($v1[$i] == $v2[$i]) {
|
||||
continue;
|
||||
}
|
||||
$i1 = $v1[$i];
|
||||
$i2 = $v2[$i];
|
||||
if (is_numeric($i1) && is_numeric($i2)) {
|
||||
$compare = ($i1 < $i2) ? -1 : 1;
|
||||
break;
|
||||
}
|
||||
// We use the position of '#' in the versions list
|
||||
// for numbers... (so take care of # in original string)
|
||||
if ($i1 == '#') {
|
||||
$i1 = '';
|
||||
} elseif (is_numeric($i1)) {
|
||||
$i1 = '#';
|
||||
}
|
||||
if ($i2 == '#') {
|
||||
$i2 = '';
|
||||
} elseif (is_numeric($i2)) {
|
||||
$i2 = '#';
|
||||
}
|
||||
if (isset($versions[$i1]) && isset($versions[$i2])) {
|
||||
$compare = ($versions[$i1] < $versions[$i2]) ? -1 : 1;
|
||||
} elseif (isset($versions[$i1])) {
|
||||
$compare = 1;
|
||||
} elseif (isset($versions[$i2])) {
|
||||
$compare = -1;
|
||||
} else {
|
||||
$compare = 0;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// If previous loop didn't find anything, compare the "extra" segments
|
||||
if ($compare == 0) {
|
||||
if (count($v2) > count($v1)) {
|
||||
if (isset($versions[$v2[$i]])) {
|
||||
$compare = ($versions[$v2[$i]] < 4) ? 1 : -1;
|
||||
} else {
|
||||
$compare = -1;
|
||||
}
|
||||
} elseif (count($v2) < count($v1)) {
|
||||
if (isset($versions[$v1[$i]])) {
|
||||
$compare = ($versions[$v1[$i]] < 4) ? -1 : 1;
|
||||
} else {
|
||||
$compare = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Compare the versions
|
||||
if (func_num_args() > 2) {
|
||||
switch ($operator) {
|
||||
case '>':
|
||||
case 'gt':
|
||||
return (bool) ($compare > 0);
|
||||
break;
|
||||
case '>=':
|
||||
case 'ge':
|
||||
return (bool) ($compare >= 0);
|
||||
break;
|
||||
case '<=':
|
||||
case 'le':
|
||||
return (bool) ($compare <= 0);
|
||||
break;
|
||||
case '==':
|
||||
case '=':
|
||||
case 'eq':
|
||||
return (bool) ($compare == 0);
|
||||
break;
|
||||
case '<>':
|
||||
case '!=':
|
||||
case 'ne':
|
||||
return (bool) ($compare != 0);
|
||||
break;
|
||||
case '':
|
||||
case '<':
|
||||
case 'lt':
|
||||
return (bool) ($compare < 0);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return $compare;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user