HookRegistrar
in package
Discovers every {@see HookInterface} implementation under the configured roots and registers it (container-resolved when the consumer provides one).
The FQCN of each hook is derived from the path relative to its root,
prefixed with that root's namespace. A trailing / on the directory and a
missing trailing \ on the namespace are normalised; a namespace written
with / is rejected with a HookRegistrationException.
Discovery follows the INTERFACE, never the filename. Matching on a *Hooks
suffix — or on a single root directory — makes registration depend on where
a file sits and what it is called, so a hook in the "wrong" folder, or named
in the singular, silently never registers: the class exists, it compiles,
its unit test passes, and add_action is never reached. That failure mode
cost real production behaviour, hence the contract here is the type.
Table of Contents
Properties
- $container : ContainerInterface|null
- $hookPaths : array<string, string>
Methods
- __construct() : mixed
- register() : void
- discoverHooks() : array<int, HookInterface>>
- discoverIn() : array<int, HookInterface>>
Properties
$container
private
ContainerInterface|null
$container
= null
$hookPaths
private
array<string, string>
$hookPaths
namespace prefix => absolute directory
Methods
__construct()
public
__construct([ContainerInterface|null $container = null ][, array<string, string> $hookPaths = [] ]) : mixed
Parameters
- $container : ContainerInterface|null = null
- $hookPaths : array<string, string> = []
-
namespace prefix => absolute directory
register()
public
register() : void
discoverHooks()
private
discoverHooks() : array<int, HookInterface>>
Return values
array<int, HookInterface>>discoverIn()
private
discoverIn(string $directory, string $namespace) : array<int, HookInterface>>
Parameters
- $directory : string
- $namespace : string