-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathController.php
More file actions
76 lines (63 loc) · 1.77 KB
/
Controller.php
File metadata and controls
76 lines (63 loc) · 1.77 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
<?php
declare(strict_types=1);
namespace PHPCensor;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use PHPCensor\Common\Application\ConfigurationInterface;
use Symfony\Component\HttpFoundation\Session\Session;
/**
* @package PHP Censor
* @subpackage Application
*
* @author Dan Cryer <dan@block8.co.uk>
* @author Dmitry Khomutov <poisoncorpsee@gmail.com>
*/
abstract class Controller
{
protected Request $request;
protected Session $session;
protected ConfigurationInterface $configuration;
protected StoreRegistry $storeRegistry;
public function __construct(
ConfigurationInterface $configuration,
StoreRegistry $storeRegistry,
Request $request,
Session $session
) {
$this->configuration = $configuration;
$this->storeRegistry = $storeRegistry;
$this->request = $request;
$this->session = $session;
}
/**
* Initialise the controller.
*/
abstract public function init(): void;
public function hasAction(string $name): bool
{
if (\method_exists($this, $name)) {
return true;
}
return false;
}
/**
* Handles an action on this controller and returns a Response object.
*
* @return Response|string
*/
public function handleAction(string $action, array $actionParams)
{
return \call_user_func_array([$this, $action], $actionParams);
}
/**
* Get a specific incoming request parameter.
*
* @param mixed $default Default return value (if key does not exist)
*
* @return mixed
*/
public function getParam(string $key, $default = null)
{
return $this->request->get($key, $default);
}
}