PluginProbe
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution / 2.5.0
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution v2.5.0
2.5.0 2.4.0 2.3.0 2.2.5 2.2.0 2.1.2 2.1.1 trunk 1.10.0 1.10.01 1.10.02 1.5.0 1.5.01 1.5.02 1.5.1 1.5.10 1.5.20 1.5.21 1.5.22 1.5.23 1.5.24 1.5.25 1.6.0 1.7.0 1.7.1 All 34 releases
fluent-booking / app / Services / NotificationGate.php

NotificationGate.php in Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution 2.5.0, at app/Services/NotificationGate.php

68 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentBooking\App\Services;
4
5 /**
6 * Suppresses booking notifications for the current request, and nothing else:
7 * calendar sync, CRM triggers and webhooks still run, and reminders still go
8 * out later. For backfills, migrations and agent writes that shouldn't email
9 * the attendee.
10 *
11 * $booking = NotificationGate::silently(function () use ($data) {
12 * return BookingService::createBooking($data);
13 * });
14 *
15 * Add-ons that send their own notifications (SMS, push) should check
16 * isSuppressed() or hook `fluent_booking/suppress_notifications`.
17 *
18 * @since 2.2.6
19 */
20 class NotificationGate
21 {
22 /**
23 * @var bool
24 */
25 private static $suppressed = false;
26
27 /**
28 * Run $callback with notifications off, restoring the previous state even
29 * if it throws.
30 *
31 * @param callable $callback
32 *
33 * @return mixed Whatever $callback returns.
34 */
35 public static function silently(callable $callback)
36 {
37 $previous = self::$suppressed;
38 self::$suppressed = true;
39
40 try {
41 return $callback();
42 } finally {
43 self::$suppressed = $previous;
44 }
45 }
46
47 /**
48 * @param string $context A hint about which notification is being gated,
49 * e.g. 'booking_scheduled' or 'booking_cancelled'.
50 * @param mixed $booking The booking in play, when there is one.
51 *
52 * @return bool
53 */
54 public static function isSuppressed($context = '', $booking = null)
55 {
56 /**
57 * Whether booking notifications should be skipped for this call.
58 *
59 * @since 2.2.6
60 *
61 * @param bool $suppressed Current state of the request-scoped gate.
62 * @param string $context Which notification is being gated.
63 * @param mixed $booking The booking in play, or null.
64 */
65 return (bool) apply_filters('fluent_booking/suppress_notifications', self::$suppressed, $context, $booking);
66 }
67 }
68