This repository was archived by the owner on Aug 16, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathLoader.php
More file actions
67 lines (59 loc) · 1.56 KB
/
Loader.php
File metadata and controls
67 lines (59 loc) · 1.56 KB
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
<?php
declare(strict_types=1);
namespace TypistTech\WPContainedHook;
use Psr\Container\ContainerInterface;
use TypistTech\WPContainedHook\Hooks\HookInterface;
/**
* Register all actions and filters for the plugin/package/theme.
*
* Maintain a list of all hooks that are registered throughout
* the plugin, and register them with the WordPress API. Call the
* run function to execute the list of actions and filters.
*/
class Loader implements ContainerAwareInterface
{
use ContainerAwareTrait;
/**
* Array of hooks registered with WordPress.
*
* @var HookInterface[]
*/
protected $hooks = [];
/**
* Initialize the collections used to maintain the hooks.
*
* @param ContainerInterface $container The container.
*/
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
/**
* Add new hooks to the collection to be registered with WordPress.
*
* @param HookInterface|HookInterface[] ...$hooks Hooks to be registered.
*
* @return void
*/
public function add(HookInterface ...$hooks)
{
$this->hooks = array_values(
array_unique(
array_merge($this->hooks, $hooks),
SORT_REGULAR
)
);
}
/**
* Register the hooks to the container and WordPress.
*
* @return void
*/
public function run()
{
foreach ($this->hooks as $hook) {
$hook->setContainer($this->container);
$hook->register();
}
}
}