'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',
"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"
use Liuggio\StatsdClient\Sender\SocketSender;
use MediaWiki\Logger\LoggerFactory;
use MediaWiki\Session\SessionManager;
+use Wikimedia\ScopedCallback;
// Hide compatibility functions from Doxygen
/// @cond
*
* @file
*/
+use Wikimedia\ScopedCallback;
/**
* Gives access to properties of a page.
--- /dev/null
+<?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 {
+}
+++ /dev/null
-<?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 );
- }
- }
-}
* @ingroup Profiler
* @author Aaron Schulz
*/
+use Wikimedia\ScopedCallback;
/**
* Custom PHP profiler for parser/DB type section names that xhprof/xdebug can't handle
<?php
+
+use Wikimedia\ScopedCallback;
+
/**
* @author Matthias Mullie <mmullie@wikimedia.org>
* @group BagOStuff
$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' );
}
/**
/**
* 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();