/
action.php
56 lines (50 loc) · 1.96 KB
/
action.php
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
<?php
namespace Concrete\Controller\Backend\Attribute;
use Concrete\Core\Attribute\Key\Key;
use Concrete\Core\Attribute\Type;
use Concrete\Core\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
class Action extends AbstractController
{
public function dispatch($action)
{
$arguments = explode('/', trim($action, '/'));
if (count($arguments) > 2) { // there must at last be three arguments here
if (isset($arguments[0])) {
switch($arguments[0]) {
case 'key':
if (isset($arguments[1])) {
$key = Key::getByID($arguments[1]);
if (is_object($key)) {
$controller = $key->getController();
}
}
break;
case 'type':
if (isset($arguments[1])) {
$type = Type::getByID($arguments[1]);
if (is_object($type)) {
$controller = $type->getController();
}
}
break;
}
}
if (isset($controller)) {
$action = $arguments[2];
$arguments = array_slice($arguments, 3);
if (method_exists($controller, 'action_' . $action)) { //make sure the controller has the right method
$response = call_user_func_array(array($controller, 'action_' . $action), $arguments);
if ($response instanceof Response) {
return $response;
} else {
print $response;
$this->app->shutdown();
}
}
}
}
$response = new Response(t('Access Denied'));
return $response;
}
}