wikimedia/scoped-callback
最新稳定版本:v5.0.0
Composer 安装命令:
composer require wikimedia/scoped-callback
包简介
Make a callback run when a dummy object leaves the scope.
README 文档
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
统计信息
- 总下载量: 792.73k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 1
- 依赖项目数: 7
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2016-09-29