From: Sam Reed Date: Sat, 23 Jan 2010 22:31:37 +0000 (+0000) Subject: Refactor array_intersect_key from ApiResult.php to GlobalFunctions.php X-Git-Tag: 1.31.0-rc.0~38128 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/comptes/journal.php?a=commitdiff_plain;h=d71b682cc69bd5f3aafb52d6861b750fb0e22a39;p=lhc%2Fweb%2Fwiklou.git Refactor array_intersect_key from ApiResult.php to GlobalFunctions.php --- diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index b8916c2fe7..219df38678 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -190,6 +190,37 @@ if ( !function_exists( 'array_diff_key' ) ) { } } +if ( !function_exists( 'array_intersect_key' ) ) { + /** + * Exists in 5.1.0+ + * Define our own array_intersect_key function + */ + function array_intersect_key( $isec, $keys ) { + $argc = func_num_args(); + + if ( $argc > 2 ) { + for ( $i = 1; $isec && $i < $argc; $i++ ) { + $arr = func_get_arg( $i ); + + foreach ( array_keys( $isec ) as $key ) { + if ( !isset( $arr[$key] ) ) + unset( $isec[$key] ); + } + } + + return $isec; + } else { + $res = array(); + foreach ( array_keys( $isec ) as $key ) { + if ( isset( $keys[$key] ) ) + $res[$key] = $isec[$key]; + } + + return $res; + } + } +} + // Support for Wietse Venema's taint feature if ( !function_exists( 'istainted' ) ) { function istainted( $var ) { diff --git a/includes/api/ApiResult.php b/includes/api/ApiResult.php index 58cfd7d27d..e2355db3c8 100644 --- a/includes/api/ApiResult.php +++ b/includes/api/ApiResult.php @@ -315,31 +315,3 @@ class ApiResult extends ApiBase { return __CLASS__ . ': $Id$'; } } - -/* For compatibility with PHP versions < 5.1.0, define our own array_intersect_key function. */ -if ( !function_exists( 'array_intersect_key' ) ) { - function array_intersect_key( $isec, $keys ) { - $argc = func_num_args(); - - if ( $argc > 2 ) { - for ( $i = 1; $isec && $i < $argc; $i++ ) { - $arr = func_get_arg( $i ); - - foreach ( array_keys( $isec ) as $key ) { - if ( !isset( $arr[$key] ) ) - unset( $isec[$key] ); - } - } - - return $isec; - } else { - $res = array(); - foreach ( array_keys( $isec ) as $key ) { - if ( isset( $keys[$key] ) ) - $res[$key] = $isec[$key]; - } - - return $res; - } - } -}