raneomik/watchdog-bundle

此包提供了一种可配置的看门狗,用于触发事件。

安装: 861

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 3

分支: 0

开放问题: 1

类型:symfony-bundle

v2.2.2 2024-09-03 12:09 UTC

This package is auto-updated.

Last update: 2024-09-03 12:09:48 UTC


README

一个提供看门狗小部件的包,如果当前时间与提供的配置匹配,则“汪汪”。

安装

composer require raneomik/watchdog-bundle

如果没有使用symfony/flex,您需要在项目中注册此包

// config/bundles.php

return [
    Raneomik\WatchdogBundle\WatchdogBundle::class => ['all' => true],
];

配置

它可以按照以下方式进行配置

#config/packages/watchdog.yml

watchdog:
   default: # raise an event if current date time matches (following "Or" logic)
   - date_time: '2019-12-01 11:00'           # a date and time
   - date: '2019-12-03'                      # a specific date
   - hour: '14:00'                           # a specific hour            
   - time: '14:15'                           # or time      
   - { start: '2019-12-01', end: '2019-12-31' }  # an interval of dates
   - { start: '10:00', end: '11:00' }        # or of times      
   - relative: 'first wednesday of'          # a relative format*
   - compound:                               # or a composite of the rules above, following "And" logic, for example :
     - relative: 'monday'                    # "On mondays"
     - { start: '20:00', end: '22:30' }      # "and between 20:00 and 22:30"
   
   maintenance: # define another watchdogs, independent of each other.
   - compound:
     - relative: 'sundays' 
     - { start: '05:00', end: '06:00' }

* 相对格式

看门狗服务

此包提供了Raneomik\WatchdogBundle\Watchdog\WatchdogInterface服务,可以在任何地方注入。它有一个返回true的方法isWoofTime,一旦配置与当前日期时间匹配。如果定义了多个,可以根据以下示例进行注入(基于上面的示例)

use Raneomik\WatchdogBundle\Watchdog\WatchdogInterface;

class Service
{
    __construct(
        private WatchdogInterface $default,
        private WatchdogInterface $maintenance
    ) {
    }
....

WatchdogHandlerInterface和WatchdogWoofCheckEvent

此包还提供了带有processWoof(array $parameters = [])方法的Raneomik\WatchdogBundle\Handler\WatchdogHandlerInterface接口,用于更复杂的处理。它与订阅了WatchdogWoofCheckEventWatchdogEventSubscriber一起工作。

在任何您希望检查是否为isWoofTime的地方,分派一个new WatchdogWoofCheckEvent($parameters, $watchdogId),如果它为isWoofTime,它将触发所有WatchdogHandlerInterface及其processWoof(array $parameters = []) // 传递给WatchdogWoofCheckEvent构造函数

$watchdogId默认为null,这将导致检查所有定义的看门狗。如果通过此参数传递一个,它将仅检查相关的看门狗。

如果您希望使用它,但您的项目未设置为自动配置,则所有实现WatchdogHandlerInterfaceHandlers都必须带有raneomik_watchdog.handler标记。

进行中:性能数据收集

您可以在Symfony分析器中访问看门狗数据

profiler.png

许可