Verbs

Global Report Generated

1<?php ...
2 
3namespace Thunk\Verbs\Examples\Subscriptions\Events;
4 
5use Thunk\Verbs\Attributes\Autodiscovery\AppliesToSingletonState;
6use Thunk\Verbs\Attributes\Hooks\Once;
7use Thunk\Verbs\Event;
8use Thunk\Verbs\Examples\Subscriptions\Models\Report;
9use Thunk\Verbs\Examples\Subscriptions\States\GlobalReportState;
10 
11#[AppliesToSingletonState(GlobalReportState::class)]
12class GlobalReportGenerated extends Event
13{
14 #[Once]
15 public function handle()
16 {
17 $state = $this->state(GlobalReportState::class);
18 
19 Report::create([
20 'plan_id' => null,
21 'subscribes_since_last_report' => $state->subscribes_since_last_report,
22 'unsubscribes_since_last_report' => $state->unsubscribes_since_last_report,
23 'total_subscriptions' => $state->total_subscriptions,
24 'summary' => $state->summary(),
25 ]);
26 
27 ResetGlobalReportState::fire();
28 }
29}