wikimedia / scoped-callback
在模拟对象离开作用域时执行回调。
v4.0.0
2022-07-08 22:48 UTC
Requires
- php: >=7.2.9
Requires (Dev)
- mediawiki/mediawiki-codesniffer: 39.0.0
- mediawiki/mediawiki-phan-config: 0.11.1
- mediawiki/minus-x: 1.1.1
- ockcyp/covers-validator: 1.4.0
- php-parallel-lint/php-console-highlighter: 1.0.0
- php-parallel-lint/php-parallel-lint: 1.3.2
- phpunit/phpunit: ^8.5
This package is auto-updated.
Last update: 2024-09-12 06:04:05 UTC
README
ScopedCallback
ScopedCallback 类允许在实例超出作用域后运行函数。它对于确保即使在抛出异常的情况下也能运行拆解或清理函数非常有用。它还通过不需要在每次手动调用回调来为开发者提供一个更清晰的 API。
有关此库的更多文档可以在 MediaWiki.org 上找到。
用法
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 );
运行测试
composer install --prefer-dist
composer test