subzerobo / sabalim-action-wrapper
在处理Before/After操作时的包装库
v1.0.2
2019-04-25 08:05 UTC
Requires
- php: ^7.0
This package is auto-updated.
Last update: 2024-09-25 21:58:19 UTC
README
在处理特定的Before/After操作时的包装库,这个库为其他库提供抽象层,特别是为Sabalim-Elastic-Apm-PHP-Agent。
HandlerInterface
接口提供两个函数,用于在执行任何特定操作之前和之后运行
interface HandlerInterface{
public function handleBefore($parent, string $actionName, array $actionData = []);
public function handleAfter($parent, string $actionName, array $actionData = []);
}
$parent
是您的主要对象,其操作需要被包装,例如,您可以传递 redis
对象,$actionName
是您要包装的操作的上下文,$actionData
是您希望传递给包装器的额外数据
HandlerAbstract
HandlerAbstract 类实现了 HandlerInterface,默认情况下会计算操作事件持续时间,但您可以通过传递 start
和 end
微时间戳来覆盖默认实现的代码
它内置了 DataStore,用于保存通过 handleBefore
传递的额外参数,以便在 handlerAfter
方法中稍后使用。
您的自定义处理程序可以扩展这个类。
class myCustomHandler extends HandlerAbstract
{
private $your_custom_private;
public $your_custom_public;
public function handleBefore($request, string $actionName, array $actionData = [])
{
parent::handleBefore($request, $actionName, $actionData);
// Your code ...
}
public function handleAfter($request, string $actionName, array $actionData = [])
{
parent::handleAfter($request, $actionName, $actionData);
// Your code ...
}
}