|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Hookable interface file. |
| 4 | + * |
| 5 | + * @package eXtended WordPress |
| 6 | + * @subpackage Contracts\Hook |
| 7 | + */ |
| 8 | + |
| 9 | +namespace XWP\Contracts\Hook; |
| 10 | + |
| 11 | +/** |
| 12 | + * Hook decorator functionality. |
| 13 | + * |
| 14 | + * @template T |
| 15 | + * |
| 16 | + * ! Global properties shared among hooks and handlers |
| 17 | + * |
| 18 | + * @property-read string $tag Hook name. Can use the `vsprinf` format in combination with `$modifiers`. |
| 19 | + * @property-read array|int|string|callable $priority Hook priority. Can be a number, callable, or a string. Strings are treated as filters, which will be applied to the default priority. |
| 20 | + * @property-read int $context Context bitmask determining where the hook can be invoked. |
| 21 | + * @property-read string|false $requires Prerequisite hook that must be invoked before this hook. Handler classname, or Classname, method array. |
| 22 | + * @property-read string|array|false $modifiers Replacement pairs for the tag name. |
| 23 | + * @property-read int $real_priority Actual priority of the hook. |
| 24 | + * @property-read array|callable|false $conditional Hook conditional. Callable which will be invoked to determine if the hook should be invoked. |
| 25 | + */ |
| 26 | +interface Hookable { |
| 27 | + /** |
| 28 | + * Indicates that a hook can be invoked in user-facing pages. |
| 29 | + * |
| 30 | + * @var int |
| 31 | + */ |
| 32 | + public const CTX_FRONTEND = 1; // 0000001 |
| 33 | + |
| 34 | + /** |
| 35 | + * Indicates that a hook can be invoked in the admin area. |
| 36 | + * |
| 37 | + * @var int |
| 38 | + */ |
| 39 | + public const CTX_ADMIN = 2; // 0000010 |
| 40 | + |
| 41 | + /** |
| 42 | + * Indicates that a hook can be invoked on AJAX requests. |
| 43 | + * |
| 44 | + * @var int |
| 45 | + */ |
| 46 | + public const CTX_AJAX = 4; // 0000100 |
| 47 | + |
| 48 | + /** |
| 49 | + * Indicates that a hook can be invoked when a cron job is running. |
| 50 | + * |
| 51 | + * @var int |
| 52 | + */ |
| 53 | + public const CTX_CRON = 8; // 0001000 |
| 54 | + |
| 55 | + /** |
| 56 | + * Indicates that a hook can be invoked on REST API requests. |
| 57 | + * |
| 58 | + * @var int |
| 59 | + */ |
| 60 | + public const CTX_REST = 16; // 0010000 |
| 61 | + |
| 62 | + /** |
| 63 | + * Indicates that a hook can be invoked when WP CLI is running. |
| 64 | + * |
| 65 | + * @var int |
| 66 | + */ |
| 67 | + public const CTX_CLI = 32; // 0100000 |
| 68 | + |
| 69 | + /** |
| 70 | + * Indicates that a hook can be invoked in any context. |
| 71 | + * |
| 72 | + * @var int |
| 73 | + */ |
| 74 | + public const CTX_GLOBAL = 63; // 0111111 |
| 75 | + |
| 76 | + /** |
| 77 | + * Hook type. Can be `handler`, `action` or `filter`. |
| 78 | + * |
| 79 | + * @var string |
| 80 | + */ |
| 81 | + public const HOOK_TYPE = self::HOOK_TYPE; |
| 82 | + |
| 83 | + /** |
| 84 | + * Set the reflector |
| 85 | + * |
| 86 | + * @param \Reflector $reflector Reflector instance. |
| 87 | + * @return static |
| 88 | + */ |
| 89 | + public function set_reflector( \Reflector $reflector ): static; |
| 90 | + |
| 91 | + /** |
| 92 | + * Set the hook target. |
| 93 | + * |
| 94 | + * @param array|T $target Hook target. |
| 95 | + * @return static |
| 96 | + */ |
| 97 | + public function set_target( array|object $target ): static; |
| 98 | +} |
0 commit comments