raneomik / watchdog-bundle
此包提供了一种可配置的看门狗,用于触发事件。
Requires
- php: ^7.4|^8.0
- symfony/framework-bundle: ^5.4|^6.0
Requires (Dev)
- ekino/phpstan-banned-code: *
- infection/infection: *
- phpstan/extension-installer: *
- phpstan/phpstan: *
- phpstan/phpstan-phpunit: *
- phpstan/phpstan-symfony: *
- phpunit/phpunit: ^9.5.20|^10.1
- psalm/plugin-symfony: *
- symfony/profiler-pack: ^1.0
- symfony/yaml: ^5.4|^6.0
- symplify/coding-standard: *
- symplify/easy-coding-standard: *
- symplify/phpstan-rules: *
- vimeo/psalm: *
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
接口,用于更复杂的处理。它与订阅了WatchdogWoofCheckEvent
的WatchdogEventSubscriber
一起工作。
在任何您希望检查是否为isWoofTime
的地方,分派一个new WatchdogWoofCheckEvent($parameters, $watchdogId)
,如果它为isWoofTime
,它将触发所有WatchdogHandlerInterface
及其processWoof(array $parameters = []) // 传递给WatchdogWoofCheckEvent构造函数
。
$watchdogId
默认为null,这将导致检查所有定义的看门狗。如果通过此参数传递一个,它将仅检查相关的看门狗。
如果您希望使用它,但您的项目未设置为自动配置,则所有实现WatchdogHandlerInterface
的Handlers
都必须带有raneomik_watchdog.handler
标记。
进行中:性能数据收集
您可以在Symfony分析器中访问看门狗数据