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
<?php
namespace Laminas\Mvc\Controller\Plugin;
use Laminas\Mvc\Exception\RuntimeException;
use Laminas\Mvc\InjectApplicationEventInterface;
class Params extends AbstractPlugin
{
/**
* Grabs a param from route match by default.
*
* @param string $param
* @param mixed $default
* @return mixed
*/
public function __invoke($param = null, $default = null)
{
if ($param === null) {
return $this;
}
return $this->fromRoute($param, $default);
}
/**
* Return all files or a single file.
*
* @param string $name File name to retrieve, or null to get all.
* @param mixed $default Default value to use when the file is missing.
* @return array|\ArrayAccess|null
*/
public function fromFiles($name = null, $default = null)
{
if ($name === null) {
return $this->getController()->getRequest()->getFiles($name, $default)->toArray();
}
return $this->getController()->getRequest()->getFiles($name, $default);
}
/**
* Return all header parameters or a single header parameter.
*
* @param string $header Header name to retrieve, or null to get all.
* @param mixed $default Default value to use when the requested header is missing.
* @return null|\Laminas\Http\Header\HeaderInterface
*/
public function fromHeader($header = null, $default = null)
{
if ($header === null) {
return $this->getController()->getRequest()->getHeaders($header, $default)->toArray();
}
return $this->getController()->getRequest()->getHeaders($header, $default);
}
/**
* Return all post parameters or a single post parameter.
*
* @param string $param Parameter name to retrieve, or null to get all.
* @param mixed $default Default value to use when the parameter is missing.
* @return mixed
*/
public function fromPost($param = null, $default = null)
{
if ($param === null) {
return $this->getController()->getRequest()->getPost($param, $default)->toArray();
}
return $this->getController()->getRequest()->getPost($param, $default);
}
/**
* Return all query parameters or a single query parameter.
*
* @param string $param Parameter name to retrieve, or null to get all.
* @param mixed $default Default value to use when the parameter is missing.
* @return mixed
*/
public function fromQuery($param = null, $default = null)
{
if ($param === null) {
return $this->getController()->getRequest()->getQuery($param, $default)->toArray();
}
return $this->getController()->getRequest()->getQuery($param, $default);
}
/**
* Return all route parameters or a single route parameter.
*
* @param string $param Parameter name to retrieve, or null to get all.
* @param mixed $default Default value to use when the parameter is missing.
* @return mixed
* @throws RuntimeException
*/
public function fromRoute($param = null, $default = null)
{
$controller = $this->getController();
if (! $controller instanceof InjectApplicationEventInterface) {
throw new RuntimeException(
'Controllers must implement Laminas\Mvc\InjectApplicationEventInterface to use this plugin.'
);
}
if ($param === null) {
return $controller->getEvent()->getRouteMatch()->getParams();
}
return $controller->getEvent()->getRouteMatch()->getParam($param, $default);
}
}