-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInvoke.php
49 lines (43 loc) · 1.22 KB
/
Invoke.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php // phpcs:disable PHPCompatibility.Variables.ForbiddenThisUseContexts, WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid
/**
* Invoke enum file.
*
* @package eXtended WordPress
* @subpackage Contracts\Hook
*/
namespace XWP\Contracts\Hook;
/**
* Hook invocation strategy.
*/
enum Invoke : string {
/**
* Invokes the hook directly.
*/
case Directly = 'directly';
/**
* Invokes the hook indirectly.
*
* Indirect invoking is an alternative to direct invoking. It enables:
* * Conditional invocation
* * On-demand and Just-in-time initialization of the handler
* * Passing the hook instance to the handler callback
*
* ! Caveat emptor: Indirect invoking can be an order of magnitude slower than direct invoking.
*/
case Indirectly = 'indirectly';
case WithCustomArgs = 'customArgs';
case Conditionally = 'conditionaly';
/**
* Check if the hook is invoked indirectly.
*
* @return bool
*/
public function isIndirect(): bool {
return match ( $this ) {
self::Indirectly,
self::Conditionally,
self::WithCustomArgs => true,
default => false,
};
}
}