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
|
<?php
namespace PHPPgAdmin\Middleware;
/**
* Set the requestobj and responseobj properties of the container
* as the value of $request and $response, which already contain the route
*/
class PopulateRequestResponse extends Middleware
{
use \PHPPgAdmin\Traits\HelperTrait;
public function __invoke(
\Psr\Http\Message\ServerRequestInterface $request,
\Psr\Http\Message\ResponseInterface $response,
$next
) {
$container = $this->container;
$container['requestobj'] = $request;
$container['responseobj'] = $response;
$container['server'] = $request->getParam('server');
$container['database'] = $request->getParam('database');
$container['schema'] = $request->getParam('schema');
$misc = $container->get('misc');
$misc->setHREF();
$misc->setForm();
$container->view->offsetSet('METHOD', $request->getMethod());
if ($request->getAttribute('route')) {
$container->view->offsetSet('subject', $request->getAttribute('route')->getArgument('subject'));
}
$query_string = $request->getUri()->getQuery();
$container->view->offsetSet('query_string', $query_string);
$path = (SUBFOLDER ? (SUBFOLDER . '/') : '') . $request->getUri()->getPath() . ($query_string ? '?' . $query_string : '');
$container->view->offsetSet('path', $path);
$params = $request->getParams();
$viewparams = [];
foreach ($params as $key => $value) {
if (is_scalar($value)) {
$viewparams[$key] = $value;
}
}
if (isset($_COOKIE['IN_TEST'])) {
$in_test = (string) $_COOKIE['IN_TEST'];
} else {
$in_test = '0';
}
// remove tabs and linebreaks from query
if (isset($params['query'])) {
$viewparams['query'] = str_replace(["\r", "\n", "\t"], ' ', $params['query']);
}
$container->view->offsetSet('params', $viewparams);
$container->view->offsetSet('in_test', $in_test);
if (count($container['errors']) > 0) {
return ($container->haltHandler)($container->requestobj, $container->responseobj, $container['errors'], 412);
}
$messages = $container->flash->getMessages();
if (!empty($messages)) {
foreach ($messages as $key => $message) {
\PC::debug($message, 'Flash: ' . $key);
}
}
// First execute anything else
$response = $next($request, $response);
// Any other request, pass on current response
return $response;
}
}
|