forked from php-censor/php-censor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathController.php
More file actions
109 lines (95 loc) · 2.08 KB
/
Controller.php
File metadata and controls
109 lines (95 loc) · 2.08 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
<?php
namespace PHPCensor;
use PHPCensor\Http\Request;
use PHPCensor\Http\Response;
abstract class Controller
{
/**
* @var Request
*/
protected $request;
/**
* @var Config
*/
protected $config;
/**
* @param Config $config
* @param Request $request
*/
public function __construct(Config $config, Request $request)
{
$this->config = $config;
$this->request = $request;
}
/**
* Initialise the controller.
*/
abstract public function init();
/**
* @param string $name
*
* @return bool
*/
public function hasAction($name)
{
if (method_exists($this, $name)) {
return true;
}
if (method_exists($this, '__call')) {
return true;
}
return false;
}
/**
* Handles an action on this controller and returns a Response object.
*
* @param string $action
* @param array $actionParams
*
* @return Response
*/
public function handleAction($action, $actionParams)
{
return call_user_func_array([$this, $action], $actionParams);
}
/**
* Get a hash of incoming request parameters ($_GET, $_POST)
*
* @return array
*/
public function getParams()
{
return $this->request->getParams();
}
/**
* Get a specific incoming request parameter.
*
* @param string $key
* @param mixed $default Default return value (if key does not exist)
*
* @return mixed
*/
public function getParam($key, $default = null)
{
return $this->request->getParam($key, $default);
}
/**
* Change the value of an incoming request parameter.
*
* @param string $key
* @param mixed $value
*/
public function setParam($key, $value)
{
$this->request->setParam($key, $value);
}
/**
* Remove an incoming request parameter.
*
* @param string $key
*/
public function unsetParam($key)
{
$this->request->unsetParam($key);
}
}