Daan is sweet to Kelley and delegates himself TestCMS code reflection
[ssproject1617.git] / testcms-final-anon / system / classes / events.php
1 <?php defined('IN_CMS') or die('No direct access allowed.');
2
3 class Events {
4
5 private static $stack = array();
6
7 private static function parse($page) {
8 $name = 'main';
9
10 if(strpos($page, '.') !== false) {
11 list($page, $name) = explode('.', $page);
12 }
13
14 return array($page, $name);
15 }
16
17 public static function bind($page, $fn) {
18 list($page, $name) = static::parse($page);
19
20 if(!isset(static::$stack[$page])) {
21 static::$stack[$page] = array();
22 }
23
24 static::$stack[$page][$name] = $fn;
25 }
26
27 public static function call($name = '') {
28 $page = basename(Request::uri());
29
30 if(empty($name)) {
31 $name = 'main';
32 }
33
34 if($func = isset(static::$stack[$page][$name]) ? static::$stack[$page][$name] : false) {
35 return is_callable($func) ? $func() : '';
36 }
37
38 return '';
39 }
40
41 }