ssitu/hekate

处理在关机时运行的函数和方法。

v0.1.0 2021-07-22 13:25 UTC

This package is auto-updated.

Last update: 2024-09-09 00:23:18 UTC


README

处理在关机时运行的函数和方法。

  • 提供优先级:1 - 高,2 - 正常,3 - 低;
  • 在注册前执行可调用性的扩展检查;
  • 允许注销;
  • 仅在请求时抛出异常;
  • 提供了一个接口。

非常方便用于日志缓冲、邮件堆积、数据库关闭等。

文档

use \SSITU\Hekate\Hekate;

require_once 'path/to/autoload.php';

$throwException = true; # default: false
$Hekate = new Hekate();
// or
$Hekate = new Hekate($throwException);
// and also
$Hekate->setThrowException($throwException);

$priority = 1; #default: 2

# Functions:
$Hekate->register('funcName', ['funcArgm1', 'funcArgm2'], $priority);

# Methods:
$Hekate->register(['className', 'publicStaticMethodName'], ['someMethodArgm'], $priority);
// or use helper:
$Hekate->registerMethod('className', 'publicStaticMethodName', ['someMethodArgm'], $priority);

// Class passed as string can only register static method.
// Otherwise, pass object:
$Hekate->registerMethod(new SomeClass(), 'publicMethodName',  ['someMethodArgm'], $priority);

# Deregister:
$registrationId = $Hekate->register('callable');
$Hekate->deregister($registrationId);

// when exception throwing is turned off: register method will return FALSE in case of invalid callback
$registrationId = $Hekate->register('badCallable');
if($registrationId === false){
    // handle it the way you prefer
}

贡献

当然可以!您可以查看CONTRIBUTING

许可

本项目采用MIT许可证;详细信息请参阅LICENSE