Clone this repo:
  1. b263e58 build: Updating mediawiki/mediawiki-codesniffer to 44.0.0 by libraryupgrader · 6 weeks ago master
  2. 3ddaea6 build: Updating composer dependencies by libraryupgrader · 5 months ago
  3. f624b4a build: Updating mediawiki/mediawiki-codesniffer to 43.0.0 by libraryupgrader · 6 months ago
  4. 7ae2a97 build: Updating mediawiki/mediawiki-phan-config to 0.14.0 by libraryupgrader · 7 months ago
  5. fc084c1 build: Upgrade phpunit to 9.6.16 by James D. Forrester · 8 months ago

Latest Stable Version License

ScopedCallback

The ScopedCallback class allows for running a function after the instance goes out of scope. It can be useful for making sure teardown or cleanup functions run even if exceptions are thrown. It also makes for a cleaner API for developers, by not requiring the callback to be called manually each time.

Additional documentation about the library can be found on MediaWiki.org.

Usage

use Wikimedia\ScopedCallback;
$sc = new ScopedCallback( [ $this, 'teardown' ] );
// Even if this throws an exception, the callback will run
// or it'll run at the end of the function
$this->fooBar();
// If you want to manually call the callback
ScopedCallback::consume( $sc );
// or
unset( $sc );
// If you want to prevent it from being called
ScopedCallback::cancel( $sc );

Running tests

composer install --prefer-dist
composer test