-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathfoundation.php
More file actions
107 lines (92 loc) · 2.14 KB
/
Copy pathfoundation.php
File metadata and controls
107 lines (92 loc) · 2.14 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
<?php namespace Feather\Components\Gear;
use Event;
abstract class Foundation {
/**
* The feather instance.
*
* @var Feather\Components\Foundation\Application
*/
protected $feather;
/**
* Listen for an event and fire a method or closure handler.
*
* @param string $event
* @param string|Closure $handler
* @return void
*/
public function listen($event, $handler)
{
$this->event('listen', $event, $handler);
}
/**
* Overrides existing events listening for an event and fire
* a method or closure handler.
*
* @param string $event
* @param string|Closure $handler
* @return void
*/
public function override($event, $handler)
{
$this->event('override', $event, $handler);
}
/**
* Binds different types of events.
*
* @param string $type
* @param string $event
* @param string|Closure $handler
* @return void
*/
private function event($type, $event, $handler)
{
$gear = $this;
Event::$type($event, function($parameters = array()) use ($gear, $handler)
{
// If the handler is a callable closure then we'll execute the closure
// and return its result.
if(is_callable($handler))
{
return $handler($parameters);
}
// If the handler is a method that exists on the gear object then execute
// the method and return its result.
elseif(method_exists($gear, $handler))
{
return call_user_func_array(array($gear, $handler), $parameters);
}
// By default we'll return null, as the event manager will expect a non
// null result.
return null;
});
Event::fire('event');
}
/**
* Executed when a gear is enabled.
*
* @return void
*/
public function enabled(){}
/**
* Executed when a gear is disabled.
*
* @return void
*/
public function disabled(){}
/**
* Executed when a gear is removed.
*
* @return void
*/
public function remove(){}
/**
* Set the Feather application instance.
*
* @param Feather\Components\Foundation\Application $feather
* @return void
*/
public function application(\Feather\Components\Foundation\Application $feather)
{
$this->feather = $feather;
}
}