PluginProbe
Import WP – CSV & XML Import Export for WordPress / 2.7.1
Import WP – CSV & XML Import Export for WordPress v2.7.1
2.15.1 2.15.0 2.14.24 2.14.23 2.7.0 2.7.1 2.7.10 2.7.11 2.7.12 2.7.13 2.7.14 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.2 2.8.3 2.9.0 2.9.1 All 144 releases
jc-importer / class / Common / Importer / EventHandler.php

EventHandler.php in Import WP – CSV & XML Import Export for WordPress 2.7.1, at class/Common/Importer/EventHandler.php

82 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ImportWP\Common\Importer;
4
5 class EventHandler
6 {
7 /**
8 * Single instance of class
9 */
10 protected static $_instance = null;
11 /**
12 * List of stored events
13 *
14 * @var array $events
15 */
16 private $events;
17
18 public static function instance()
19 {
20 if (is_null(self::$_instance)) {
21 self::$_instance = new self();
22 }
23
24 return self::$_instance;
25 }
26
27 /**
28 * Trigger event
29 *
30 * @param string $event
31 * @param array $args
32 *
33 * @return void
34 */
35 public function run($event, $args = array())
36 {
37
38 if (isset($this->events[$event]) && is_array($this->events[$event]) && !empty($this->events[$event])) {
39 foreach ($this->events[$event] as $callback) {
40
41 call_user_func_array($callback, (array) $args);
42 }
43 }
44 }
45
46 /**
47 * Add event
48 *
49 * @param string $event
50 * @param $callback
51 */
52 public function listen($event, $callback)
53 {
54
55 if (!isset($this->events[$event])) {
56 $this->events[$event] = array();
57 }
58
59 $this->events[$event][] = $callback;
60 }
61
62 /**
63 * Remove event
64 *
65 * @param string $event
66 * @param $callback
67 */
68 public function unlisten($event, $callback)
69 {
70 if (isset($this->events[$event]) && in_array($callback, $this->events[$event], true)) {
71
72 if (($key = array_search($callback, $this->events[$event])) !== false) {
73 unset($this->events[$event][$key]);
74 }
75
76 if (empty($this->events[$event])) {
77 unset($this->events[$event]);
78 }
79 }
80 }
81 }
82