-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlugin.php
More file actions
54 lines (43 loc) · 1.21 KB
/
Plugin.php
File metadata and controls
54 lines (43 loc) · 1.21 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
<?php
namespace plugins\frontend;
abstract class Plugin {
protected static $plugins = array();
/**
* Load plugins from directory
* @param string $dir
*/
public static function load($dir) {
$dir = dirname($dir) . DS;
foreach (glob("{$dir}*/") as $plugin) {
if (is_dir($plugin)) {
$name = end(preg_split('/\//', $plugin, -1, PREG_SPLIT_NO_EMPTY));
$filename = "{$plugin}{$name}.php";
if (file_exists($filename)) {
include $filename;
$class = '\\plugins\\frontend\\' . ucfirst($name);
if (class_exists($class)) {
$o = new $class();
$o instanceof Plugin and static::$plugins[] = $o;
}
}
}
}
}
/**
* Run event on plugins
* @param string $event
*/
public static function run($event, array $arguments = array()) {
$out = '';
if (!empty(static::$plugins)) {
$method = 'event' . ucfirst($event);
foreach (static::$plugins as $plugin) {
if (method_exists($plugin, $method))
$out .= call_user_func_array(array($plugin, $method), $arguments);
}
}
return $out;
}
}
//autoload plugins
Plugin::load(__FILE__);