-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbase.php
More file actions
153 lines (131 loc) · 3.13 KB
/
Copy pathbase.php
File metadata and controls
153 lines (131 loc) · 3.13 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php
class Feather_Base_Controller extends Controller {
/**
* Controllers are RESTful.
*
* @var bool
*/
public $restful = true;
/**
* Controllers can be geared.
*
* @var bool
*/
public $geared = true;
/**
* The default layout to be used by Feather.
*
* @var string
*/
public $layout = 'feather core::template';
/**
* The feather instance.
*
* @var Feather\Components\Foundation\Application
*/
public $feather;
/**
* Create a new Controller instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
$this->feather = Feather\Components\Support\Facade::application();
}
/**
* Determines if a place is valid, if it is return the place.
*
* @param int $id
* @return Feather\Core\Place
*/
protected function place($id)
{
return is_numeric($id) ? Feather\Core\Place::with('permissions')->find($id) : null;
}
/**
* Determines if a discussion is valid, if it is return the discussion.
*
* @param int $id
* @return Feather\Core\Discussion
*/
protected function discussion($id)
{
return is_numeric($id) ? Feather\Core\Discussion::with(array('participants', 'participants.details'))->find($id) : null;
}
/**
* Method to be run before each request.
*
* @return void
*/
public function before()
{
if($this->geared)
{
$this->feather['gear']->controller('before', $this);
}
}
/**
* Method to be run after each request.
*
* @return void
*/
public function after($response)
{
if($this->geared)
{
$this->feather['gear']->controller('after', $this);
}
$this->feather['gear']->fire('assets: change styles', array(Asset::container('theme')));
$this->feather['gear']->fire('assets: change scripts', array(Asset::container('theme')));
}
/**
* Overload the execute method on the controller. If the controller is geared we'll
* run the first override gear and return the result accordingly.
*
* @param string $method
* @param array $parameters
* @return string|object
*/
public function execute($method, $parameters = array())
{
$response = $this->geared ? $this->feather['gear']->controller('override', $this) : null;
// Only if the response is not null and we actually fired a gear event successfully.
if(!is_null($response) and $response)
{
$response = is_string($response) ? $response : $this->layout;
return $response;
}
return parent::execute($method, $parameters);
}
/**
* Magic method for calling Feather components.
*
* @param string $component
* @return object
*/
public function __get($component)
{
if(isset($this->feather[$component]))
{
return $this->feather[$component];
}
throw new BadMethodCallException("Invalid component [{$component}] called on controller.");
}
/**
* Catch-all method for requests that can't be matched.
*
* @param string $method
* @param array $parameters
* @return Response
*/
public function __call($method, $parameters)
{
$response = $this->geared ? $this->feather['gear']->controller('create', $this) : null;
if(is_null($response) or !$response)
{
return Response::error('404');
}
}
}