wikimedia / scoped-callback
Class for asserting that a callback happens when a dummy object leaves scope
Installs: 225 691
Dependents: 5
Suggesters: 0
Security: 0
Stars: 2
Watchers: 10
Forks: 0
Open Issues: 0
Requires
- php: >=5.6.99
Requires (Dev)
- jakub-onderka/php-console-highlighter: 0.3.2
- jakub-onderka/php-parallel-lint: 1.0.0
- mediawiki/mediawiki-codesniffer: 22.0.0
- mediawiki/minus-x: 0.3.1
- ockcyp/covers-validator: 0.5.1 || 0.6.1
- phpunit/phpunit: 4.8.36 || ^6.5
This package is auto-updated.
Last update: 2021-01-31 00:33:22 UTC
README
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