PluginProbe ʕ •ᴥ•ʔ
Kirki – Freeform Page Builder, Website Builder & Customizer / 6.0.13
Kirki – Freeform Page Builder, Website Builder & Customizer v6.0.13
6.1.1 6.1.0 6.0.14 6.0.13 6.0.12 6.0.11 6.0.10 6.0.9 6.0.8 6.0.7 6.0.6 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.19 4.0.20 4.0.21 4.0.22 4.0.23 4.0.24 4.1 4.2.0 5.0.0 5.1.0 5.1.1 5.2.0 5.2.1 5.2.2 5.2.3 6.0.0 trunk 3.0.40 3.0.41 3.0.42 3.0.43 3.0.44 3.0.45 3.1.0 3.1.1 3.1.2
kirki / libraries / framework / Concerns / Dispatchable.php
kirki / libraries / framework / Concerns Last commit date
DeepGettable.php 3 weeks ago DependencyResolvable.php 3 weeks ago Dispatchable.php 3 weeks ago HasConstants.php 3 weeks ago
Dispatchable.php
66 lines
1 <?php
2
3 /**
4 * Trait giving event classes static dispatch, dispatch_if, and dispatch_unless helpers.
5 * Instantiates the event and forwards it to the Event facade in one call.
6 * Keeps domain events decoupled from the EventManager while preserving a fluent dispatch API.
7 *
8 * @package Framework
9 * @subpackage Concerns
10 * @since 1.0.0
11 */
12 namespace Kirki\Framework\Concerns;
13
14 \defined('ABSPATH') || exit;
15 use Closure;
16 use Kirki\Framework\Supports\Facades\Event;
17 \defined('ABSPATH') || exit;
18 trait Dispatchable
19 {
20 /**
21 * Dispatch the event.
22 *
23 * @return void
24 *
25 * @since 1.0.0
26 */
27 public static function dispatch()
28 {
29 Event::dispatch(new static(...\func_get_args()));
30 }
31 /**
32 * Dispatch the event if the boolean is true.
33 *
34 * @param mixed $boolean The boolean.
35 * @param mixed $arguments The method arguments.
36 *
37 * @return void
38 *
39 * @since 1.0.0
40 */
41 public static function dispatch_if($boolean, ...$arguments)
42 {
43 $boolean = $boolean instanceof Closure ? $boolean() : $boolean;
44 if ($boolean) {
45 Event::dispatch(new static(...$arguments));
46 }
47 }
48 /**
49 * Dispatch the event unless the boolean is true.
50 *
51 * @param mixed $boolean The boolean.
52 * @param mixed $arguments The method arguments.
53 *
54 * @return void
55 *
56 * @since 1.0.0
57 */
58 public static function dispatch_unless($boolean, ...$arguments)
59 {
60 $boolean = $boolean instanceof Closure ? $boolean() : $boolean;
61 if (!$boolean) {
62 Event::dispatch(new static(...$arguments));
63 }
64 }
65 }
66