-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathKernel.php
More file actions
118 lines (103 loc) · 2.56 KB
/
Kernel.php
File metadata and controls
118 lines (103 loc) · 2.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
/**
*
*===================================================================
*
* Shot Library
*-------------------------------------------------------------------
* @package shot
* @author emberlabs.org
* @copyright (c) 2012 emberlabs.org
* @license MIT License
* @link https://github.com/emberlabs/shot
*
*===================================================================
*
* This source file is subject to the MIT license that is bundled
* with this package in the file LICENSE.
*
*/
namespace emberlabs\shot;
use \OpenFlame\Framework\Core\Core;
use \OpenFlame\Framework\Core\DependencyInjector;
use \OpenFlame\Framework\Event\Dispatcher;
use \OpenFlame\Framework\Event\Instance as Event;
/**
* Shot - Web Kernel
* Provides shortcuts to commonly used web functionality.
*
* @package shot
* @author emberlabs.org
* @license http://opensource.org/licenses/mit-license.php The MIT License
* @link https://github.com/emberlabs/shot/
*/
class Kernel extends Core
{
const VERSION = '1.0.0-dev';
const TRIGGER_NOBREAK = 1;
const TRIGGER_MANUALBREAK = 2;
const TRIGGER_RETURNBREAK = 3;
const TRIGGER_MIXEDBREAK = 4;
protected static $init = false;
protected static $dispatcher, $injector;
protected static function _init()
{
self::$injector = DependencyInjector::getInstance();
self::$dispatcher = self::$injector->get('dispatcher');
self::$init = true;
}
public static function get($object)
{
if(!self::$init)
{
self::_init();
}
return self::$injector->get($object);
}
public static function mget(array $objects, $object_slot_as_key = true)
{
$r = array();
foreach($objects as $object)
{
if($object_slot_as_key)
{
$r[$object] = self::$injector->get($object);
}
else
{
$r[] = self::$injector->get($object);
}
}
return $r;
}
public static function register($event, $priority, $listener, $limit = -1)
{
if(!self::$init)
{
self::_init();
}
return self::$dispatcher->register($event, $priority, $listener, $limit);
}
public static function trigger($event_name, $dispatch_type = self::TRIGGER_NOBREAK)
{
return self::$dispatcher->trigger(Event::newEvent($event_name), $dispatch_type);
}
public static function _trigger(Event $event, $dispatch_type = self::TRIGGER_NOBREAK)
{
return self::$dispatcher->trigger($event, $dispatch_type);
}
public static function mtrigger(array $events)
{
foreach($events as $event)
{
if($event instanceof Event)
{
self::_trigger($event);
}
else
{
self::trigger($event);
}
}
}
}