Use wikimedia/scoped-callback
The ScopedCallback class was moved into a separate library. This updates all callers to use the namespaced version, and provides a backwards-compatibility class wrapper under the old name. Bug: T146258 Change-Id: I2dd0a66fe2f510f26bdfef6b0a975c1beb3fd93c Depends-On: Iea0c40bdd7776372ccf72db8f088a2abaa4d3721
This commit is contained in:
parent
5b66e4504d
commit
5320f0835e
9 changed files with 42 additions and 83 deletions
|
|
@ -1235,7 +1235,7 @@ $wgAutoloadLocalClasses = [
|
|||
'SamplingStatsdClient' => __DIR__ . '/includes/libs/stats/SamplingStatsdClient.php',
|
||||
'Sanitizer' => __DIR__ . '/includes/Sanitizer.php',
|
||||
'SavepointPostgres' => __DIR__ . '/includes/libs/rdbms/database/utils/SavepointPostgres.php',
|
||||
'ScopedCallback' => __DIR__ . '/includes/libs/ScopedCallback.php',
|
||||
'ScopedCallback' => __DIR__ . '/includes/compat/ScopedCallback.php',
|
||||
'ScopedLock' => __DIR__ . '/includes/libs/lockmanager/ScopedLock.php',
|
||||
'SearchApi' => __DIR__ . '/includes/api/SearchApi.php',
|
||||
'SearchDatabase' => __DIR__ . '/includes/search/SearchDatabase.php',
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@
|
|||
"wikimedia/php-session-serializer": "1.0.3",
|
||||
"wikimedia/relpath": "1.0.3",
|
||||
"wikimedia/running-stat": "1.1.0",
|
||||
"wikimedia/scoped-callback": "1.0.0",
|
||||
"wikimedia/utfnormal": "1.0.3",
|
||||
"wikimedia/wrappedstring": "2.2.0",
|
||||
"zordius/lightncandy": "0.23"
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ if ( !defined( 'MEDIAWIKI' ) ) {
|
|||
use Liuggio\StatsdClient\Sender\SocketSender;
|
||||
use MediaWiki\Logger\LoggerFactory;
|
||||
use MediaWiki\Session\SessionManager;
|
||||
use Wikimedia\ScopedCallback;
|
||||
|
||||
// Hide compatibility functions from Doxygen
|
||||
/// @cond
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
*
|
||||
* @file
|
||||
*/
|
||||
use Wikimedia\ScopedCallback;
|
||||
|
||||
/**
|
||||
* Gives access to properties of a page.
|
||||
|
|
|
|||
29
includes/compat/ScopedCallback.php
Normal file
29
includes/compat/ScopedCallback.php
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
/**
|
||||
* Compatibility class for pre-namespace, pre-library class name
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
* http://www.gnu.org/copyleft/gpl.html
|
||||
*
|
||||
* @file
|
||||
*/
|
||||
|
||||
/**
|
||||
* @deprecated since 1.28 use Wikimedia\ScopedCallback
|
||||
*
|
||||
* @since 1.21
|
||||
*/
|
||||
class ScopedCallback extends Wikimedia\ScopedCallback {
|
||||
}
|
||||
|
|
@ -1,77 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* This file deals with RAII style scoped callbacks.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
* http://www.gnu.org/copyleft/gpl.html
|
||||
*
|
||||
* @file
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class for asserting that a callback happens when a dummy object leaves scope
|
||||
*
|
||||
* @since 1.21
|
||||
*/
|
||||
class ScopedCallback {
|
||||
/** @var callable */
|
||||
protected $callback;
|
||||
/** @var array */
|
||||
protected $params;
|
||||
|
||||
/**
|
||||
* @param callable|null $callback
|
||||
* @param array $params Callback arguments (since 1.25)
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __construct( $callback, array $params = [] ) {
|
||||
if ( $callback !== null && !is_callable( $callback ) ) {
|
||||
throw new InvalidArgumentException( "Provided callback is not valid." );
|
||||
}
|
||||
$this->callback = $callback;
|
||||
$this->params = $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger a scoped callback and destroy it.
|
||||
* This is the same is just setting it to null.
|
||||
*
|
||||
* @param ScopedCallback $sc
|
||||
*/
|
||||
public static function consume( ScopedCallback &$sc = null ) {
|
||||
$sc = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy a scoped callback without triggering it
|
||||
*
|
||||
* @param ScopedCallback $sc
|
||||
*/
|
||||
public static function cancel( ScopedCallback &$sc = null ) {
|
||||
if ( $sc ) {
|
||||
$sc->callback = null;
|
||||
}
|
||||
$sc = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger the callback when this leaves scope
|
||||
*/
|
||||
function __destruct() {
|
||||
if ( $this->callback !== null ) {
|
||||
call_user_func_array( $this->callback, $this->params );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -21,6 +21,7 @@
|
|||
* @ingroup Profiler
|
||||
* @author Aaron Schulz
|
||||
*/
|
||||
use Wikimedia\ScopedCallback;
|
||||
|
||||
/**
|
||||
* Custom PHP profiler for parser/DB type section names that xhprof/xdebug can't handle
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Wikimedia\ScopedCallback;
|
||||
|
||||
/**
|
||||
* @author Matthias Mullie <mmullie@wikimedia.org>
|
||||
* @group BagOStuff
|
||||
|
|
@ -251,20 +254,20 @@ class BagOStuffTest extends MediaWikiTestCase {
|
|||
$value1 = $this->cache->getScopedLock( $key, 0 );
|
||||
$value2 = $this->cache->getScopedLock( $key, 0 );
|
||||
|
||||
$this->assertType( 'ScopedCallback', $value1, 'First call returned lock' );
|
||||
$this->assertType( ScopedCallback::class, $value1, 'First call returned lock' );
|
||||
$this->assertNull( $value2, 'Duplicate call returned no lock' );
|
||||
|
||||
unset( $value1 );
|
||||
|
||||
$value3 = $this->cache->getScopedLock( $key, 0 );
|
||||
$this->assertType( 'ScopedCallback', $value3, 'Lock returned callback after release' );
|
||||
$this->assertType( ScopedCallback::class, $value3, 'Lock returned callback after release' );
|
||||
unset( $value3 );
|
||||
|
||||
$value1 = $this->cache->getScopedLock( $key, 0, 5, 'reentry' );
|
||||
$value2 = $this->cache->getScopedLock( $key, 0, 5, 'reentry' );
|
||||
|
||||
$this->assertType( 'ScopedCallback', $value1, 'First reentrant call returned lock' );
|
||||
$this->assertType( 'ScopedCallback', $value1, 'Second reentrant call returned lock' );
|
||||
$this->assertType( ScopedCallback::class, $value1, 'First reentrant call returned lock' );
|
||||
$this->assertType( ScopedCallback::class, $value1, 'Second reentrant call returned lock' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ class TestUtils {
|
|||
/**
|
||||
* Override the singleton for unit testing
|
||||
* @param SessionManager|null $manager
|
||||
* @return \\ScopedCallback|null
|
||||
* @return \\Wikimedia\ScopedCallback|null
|
||||
*/
|
||||
public static function setSessionManagerSingleton( SessionManager $manager = null ) {
|
||||
session_write_close();
|
||||
|
|
|
|||
Loading…
Reference in a new issue