1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Keyclic WebApiExtension. |
5
|
|
|
* |
6
|
|
|
* (c) Keyclic team <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Client\Controller; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
15
|
|
|
use Symfony\Component\HttpFoundation\Request; |
16
|
|
|
use Symfony\Component\HttpFoundation\Response; |
17
|
|
|
|
18
|
|
|
class DefaultController |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @param Request $request |
22
|
|
|
* |
23
|
|
|
* @return JsonResponse |
24
|
|
|
*/ |
25
|
|
|
public function echo(Request $request) |
26
|
|
|
{ |
27
|
|
|
$return = [ |
28
|
|
|
'warning' => 'Do not expose this service in production : it is intrinsically unsafe', |
29
|
|
|
'method' => $request->getMethod(), |
30
|
|
|
]; |
31
|
|
|
|
32
|
|
|
// Forms should be read from request, other data straight from input. |
33
|
|
|
$requestData = $request->request->all(); |
34
|
|
|
$return = array_merge( |
35
|
|
|
$return, |
36
|
|
|
$requestData |
37
|
|
|
); |
38
|
|
|
|
39
|
|
|
/** @var string $content */ |
40
|
|
|
$content = $request->getContent(false); |
41
|
|
|
if (false === empty($content)) { |
42
|
|
|
$data = json_decode($content, true); |
43
|
|
|
|
44
|
|
|
if (false === is_array($data)) { |
45
|
|
|
$data['content'] = $data; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
$return = array_merge( |
49
|
|
|
$return, |
50
|
|
|
$data |
51
|
|
|
); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
$return['headers'] = $request->headers->all(); |
55
|
|
|
$return['query'] = $request->query->all(); |
56
|
|
|
|
57
|
|
|
return new JsonResponse($return); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param Request $request |
62
|
|
|
* |
63
|
|
|
* @return JsonResponse |
64
|
|
|
*/ |
65
|
|
|
public function error(Request $request) |
66
|
|
|
{ |
67
|
|
|
$response = $this->echo($request); |
68
|
|
|
$response->setStatusCode(Response::HTTP_NOT_FOUND); |
69
|
|
|
|
70
|
|
|
return $response; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|