-
Notifications
You must be signed in to change notification settings - Fork 0
/
Initialize.php
100 lines (88 loc) · 2.39 KB
/
Initialize.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php // phpcs:disable PHPCompatibility.Variables.ForbiddenThisUseContexts, WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid
/**
* Invoke enum file.
*
* @package eXtended WordPress
* @subpackage Contracts\Hook
*/
namespace XWP\Contracts\Hook;
/**
* Determines initialization strategy for a Handler.
*/
enum Initialize: string {
/**
* Indicates that the handler should be initialized unconditionally.
*/
case Unconditionally = 'unconditional';
/**
* Indicates that the handler should be initialized immediately.
*/
case Immediately = 'immediate';
/**
* Indicates that the handler should be initialized on registration.
*/
case Early = 'early';
/**
* Indicates that the handler should be initialized on demand.
*
* On demand will initialize the handler when the hook is registered.
*/
case OnDemand = 'on-demand';
/**
* Indicates that the handler should be initialized on specified action.
*/
case Deferred = 'deferred';
/**
* Special case for manually initialized handlers.
*/
case Dynamically = 'dynamic';
/**
* Indicates that the handler should be initialized just in time.
*
* Just in time will initialize the handler just before the hook is invoked.
*/
case JustInTime = 'just-in-time';
/**
* Check if the tag is valid for the initialization strategy.
*
* @param string|null $tag Tag to check.
* @return bool
*/
public function isTagValid( ?string $tag ): bool {
return match ( $this ) {
self::OnDemand,
self::JustInTime,
self::Dynamically,
self::Immediately => ! $tag,
default => ! ! $tag,
};
}
/**
* Check if the handler hooks indirectly.
*
* @return bool
*/
public function hooksIndirectly(): bool {
return match ( $this ) {
self::OnDemand,
self::JustInTime => true,
default => false,
};
}
/**
* Check if the handler is initialized on demand.
*
* @return bool
*/
public function isOnDemand(): bool {
return self::OnDemand === $this;
}
/**
* Check if the handler is initialized just in time.
*
* @return bool
*/
public function isJIT(): bool {
return self::JustInTime === $this;
}
}