Deprecate MWFunction::call and ::callArray
These functions existed to work around a bug (fixed in PHP 5.3) and a missing feature (added in PHP 5.2) in older versions of PHP; therefore, they are no longer necessary. Change-Id: Ifebbe3d449fc57fd83f8350c28f467605c1a07b7
This commit is contained in:
parent
73f35bbb02
commit
052f1fcf30
6 changed files with 13 additions and 81 deletions
|
|
@ -1351,7 +1351,7 @@ function wfMessage( $key /*...*/) {
|
|||
*/
|
||||
function wfMessageFallback( /*...*/ ) {
|
||||
$args = func_get_args();
|
||||
return MWFunction::callArray( 'Message::newFallbackSequence', $args );
|
||||
return call_user_func_array( 'Message::newFallbackSequence', $args );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -23,48 +23,24 @@
|
|||
class MWFunction {
|
||||
|
||||
/**
|
||||
* @param $callback
|
||||
* @return array
|
||||
* @throws MWException
|
||||
*/
|
||||
protected static function cleanCallback( $callback ) {
|
||||
if ( is_string( $callback ) ) {
|
||||
if ( strpos( $callback, '::' ) !== false ) {
|
||||
// PHP 5.1 cannot use call_user_func( 'Class::Method' )
|
||||
// It can only handle only call_user_func( array( 'Class', 'Method' ) )
|
||||
$callback = explode( '::', $callback, 2 );
|
||||
}
|
||||
}
|
||||
|
||||
if ( count( $callback ) == 2 && $callback[0] == 'self' || $callback[0] == 'parent' ) {
|
||||
throw new MWException( 'MWFunction cannot call self::method() or parent::method()' );
|
||||
}
|
||||
|
||||
// Run autoloader (workaround for call_user_func_array bug: http://bugs.php.net/bug.php?id=51329)
|
||||
is_callable( $callback );
|
||||
|
||||
return $callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since 1.22; use call_user_func()
|
||||
* @param $callback
|
||||
* @return mixed
|
||||
*/
|
||||
public static function call( $callback ) {
|
||||
$callback = self::cleanCallback( $callback );
|
||||
|
||||
wfDeprecated( __METHOD__, '1.22' );
|
||||
$args = func_get_args();
|
||||
|
||||
return call_user_func_array( 'call_user_func', $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since 1.22; use call_user_func_array()
|
||||
* @param $callback
|
||||
* @param $argsarams
|
||||
* @return mixed
|
||||
*/
|
||||
public static function callArray( $callback, $argsarams ) {
|
||||
$callback = self::cleanCallback( $callback );
|
||||
wfDeprecated( __METHOD__, '1.22' );
|
||||
return call_user_func_array( $callback, $argsarams );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ if ( is_readable( "$IP/vendor/autoload.php" ) ) {
|
|||
|
||||
if ( defined( 'MW_CONFIG_CALLBACK' ) ) {
|
||||
# Use a callback function to configure MediaWiki
|
||||
MWFunction::call( MW_CONFIG_CALLBACK );
|
||||
call_user_func( MW_CONFIG_CALLBACK );
|
||||
} else {
|
||||
if ( !defined( 'MW_CONFIG_FILE' ) ) {
|
||||
define( 'MW_CONFIG_FILE', "$IP/LocalSettings.php" );
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ if ( is_readable( "$IP/vendor/autoload.php" ) ) {
|
|||
|
||||
if ( defined( 'MW_CONFIG_CALLBACK' ) ) {
|
||||
# Use a callback function to configure MediaWiki
|
||||
MWFunction::call( MW_CONFIG_CALLBACK );
|
||||
call_user_func( MW_CONFIG_CALLBACK );
|
||||
} else {
|
||||
if ( file_exists( "$IP/../wmf-config/wikimedia-mode" ) ) {
|
||||
// Load settings, using wikimedia-mode if needed
|
||||
|
|
|
|||
|
|
@ -266,8 +266,8 @@ class GlobalTest extends MediaWikiTestCase {
|
|||
array_unshift( $param_set, $sampleUTF );
|
||||
|
||||
$this->assertEquals(
|
||||
MWFunction::callArray( 'mb_substr', $param_set ),
|
||||
MWFunction::callArray( 'Fallback::mb_substr', $param_set ),
|
||||
call_user_func_array( 'mb_substr', $param_set ),
|
||||
call_user_func_array( 'Fallback::mb_substr', $param_set ),
|
||||
'Fallback mb_substr with params ' . implode( ', ', $old_param_set )
|
||||
);
|
||||
}
|
||||
|
|
@ -294,14 +294,14 @@ class GlobalTest extends MediaWikiTestCase {
|
|||
array_unshift( $param_set, $sampleUTF );
|
||||
|
||||
$this->assertEquals(
|
||||
MWFunction::callArray( 'mb_strpos', $param_set ),
|
||||
MWFunction::callArray( 'Fallback::mb_strpos', $param_set ),
|
||||
call_user_func_array( 'mb_strpos', $param_set ),
|
||||
call_user_func_array( 'Fallback::mb_strpos', $param_set ),
|
||||
'Fallback mb_strpos with params ' . implode( ', ', $old_param_set )
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
MWFunction::callArray( 'mb_strrpos', $param_set ),
|
||||
MWFunction::callArray( 'Fallback::mb_strrpos', $param_set ),
|
||||
call_user_func_array( 'mb_strrpos', $param_set ),
|
||||
call_user_func_array( 'Fallback::mb_strrpos', $param_set ),
|
||||
'Fallback mb_strrpos with params ' . implode( ', ', $old_param_set )
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,26 +1,6 @@
|
|||
<?php
|
||||
|
||||
class MWFunctionTest extends MediaWikiTestCase {
|
||||
function testCallUserFuncWorkarounds() {
|
||||
$this->assertEquals(
|
||||
call_user_func( array( 'MWFunctionTest', 'someMethod' ) ),
|
||||
MWFunction::call( 'MWFunctionTest::someMethod' )
|
||||
);
|
||||
$this->assertEquals(
|
||||
call_user_func( array( 'MWFunctionTest', 'someMethod' ), 'foo', 'bar', 'baz' ),
|
||||
MWFunction::call( 'MWFunctionTest::someMethod', 'foo', 'bar', 'baz' )
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
call_user_func_array( array( 'MWFunctionTest', 'someMethod' ), array() ),
|
||||
MWFunction::callArray( 'MWFunctionTest::someMethod', array() )
|
||||
);
|
||||
$this->assertEquals(
|
||||
call_user_func_array( array( 'MWFunctionTest', 'someMethod' ), array( 'foo', 'bar', 'baz' ) ),
|
||||
MWFunction::callArray( 'MWFunctionTest::someMethod', array( 'foo', 'bar', 'baz' ) )
|
||||
);
|
||||
}
|
||||
|
||||
function testNewObjFunction() {
|
||||
$arg1 = 'Foo';
|
||||
$arg2 = 'Bar';
|
||||
|
|
@ -34,30 +14,6 @@ class MWFunctionTest extends MediaWikiTestCase {
|
|||
MWFunction::newObj( 'MWBlankClass', $args )->args,
|
||||
$newObject->args
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
MWFunction::newObj( 'MWBlankClass', $args, true )->args,
|
||||
$newObject->args,
|
||||
'Works even with PHP version < 5.1.3'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException MWException
|
||||
*/
|
||||
function testCallingParentFails() {
|
||||
MWFunction::call( 'parent::foo' );
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException MWException
|
||||
*/
|
||||
function testCallingSelfFails() {
|
||||
MWFunction::call( 'self::foo' );
|
||||
}
|
||||
|
||||
public static function someMethod() {
|
||||
return func_get_args();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue