-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
61 lines (47 loc) · 1.85 KB
/
index.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
<?php
/*
Plugin Name: Event
Description: Event Handler for WordPress
Plugin URI: https://italystrap.com
Author: Enea Overclokk
Author URI: https://italystrap.com
Version: 1.0.0
License: GPL2
Text Domain: Text Domain
Domain Path: Domain Path
*/
/*
Copyright (C) Year Enea Overclokk Email
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
add_action('plugins_loaded', function () {
require __DIR__ . '/vendor/autoload.php';
$listenerProvider = new \ItalyStrap\Event\GlobalOrderedListenerProvider();
$state = new \ItalyStrap\Event\GlobalState();
$event = new \stdClass();
$listenerProvider->addListener(\stdClass::class, function (object $event) {
$event->name = 'Hello';
}, 10);
$listener = new class ($state) {
private $state;
public function __construct(\ItalyStrap\Event\GlobalState $state) {
$this->state = $state;
}
public function __invoke(object $event) {
$event->name .= ' World';
$event->currentState = $this->state->currentEventName();
}
};
$listenerProvider->addListener(\stdClass::class, $listener, 20);
$dispatcher = new \ItalyStrap\Event\Dispatcher($listenerProvider, $state);
$name = $dispatcher->dispatch($event)->name;
});