1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Starkerxp\CampagneBundle\Controller; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
7
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
8
|
|
|
use Symfony\Component\HttpFoundation\Request; |
9
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class TemplateController extends Controller |
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
public function cgetAction(Request $request) |
16
|
|
|
{ |
17
|
|
|
$manager = $this->get("starkerxp_campagne.manager.template"); |
18
|
|
|
try { |
19
|
|
|
$options = $this->resolveParams()->resolve($request->query->all()); |
20
|
|
|
|
21
|
|
|
$orderBy = !empty($options['sort']) ? array_map( |
22
|
|
|
function ($r) { |
23
|
|
|
return [substr($r, 1) => substr($r, 0, 1) == '+' ? 'ASC' : 'DESC']; |
24
|
|
|
}, |
25
|
|
|
explode(',', $options['sort']) |
26
|
|
|
) : []; |
27
|
|
|
|
28
|
|
|
$manager->findBy([], $orderBy, $options['limit'], $options['offset']); |
29
|
|
|
} catch (\Exception $e) { |
30
|
|
|
return new JsonResponse(["payload" => $e->getMessage()], 400); //400 |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
return new JsonResponse(["payload" => $options]); //400 |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function resolveParams() |
37
|
|
|
{ |
38
|
|
|
$resolver = new OptionsResolver(); |
39
|
|
|
$resolver->setDefaults( |
40
|
|
|
[ |
41
|
|
|
'offset' => 0, |
42
|
|
|
'limit' => 15, |
43
|
|
|
//'fields' => "*", |
|
|
|
|
44
|
|
|
'sort' => "", |
45
|
|
|
//'filter' => "", |
|
|
|
|
46
|
|
|
] |
47
|
|
|
); |
48
|
|
|
|
49
|
|
|
return $resolver; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function getAction(Request $request) |
|
|
|
|
53
|
|
|
{ |
54
|
|
|
$manager = $this->get("starkerxp_campagne.manager.template"); |
|
|
|
|
55
|
|
|
|
56
|
|
|
return new JsonResponse(["payload" => []]);//400 |
57
|
|
|
} |
58
|
|
|
|
59
|
|
View Code Duplication |
public function postAction(Request $request) |
|
|
|
|
60
|
|
|
{ |
61
|
|
|
$manager = $this->get("starkerxp_campagne.manager.template"); |
62
|
|
|
$options = $manager->getPostOptionResolver()->resolve($request->request->all()); |
|
|
|
|
63
|
|
|
|
64
|
|
|
return new JsonResponse(["payload" => ""], 201);//400 |
65
|
|
|
} |
66
|
|
|
|
67
|
|
View Code Duplication |
public function putAction(Request $request) |
|
|
|
|
68
|
|
|
{ |
69
|
|
|
$manager = $this->get("starkerxp_campagne.manager.template"); |
70
|
|
|
$options = $manager->getPutOptionResolver()->resolve($request->request->all()); |
|
|
|
|
71
|
|
|
|
72
|
|
|
return new JsonResponse(["payload" => ""], 303); //400 |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function deleteAction(Request $request) |
|
|
|
|
76
|
|
|
{ |
77
|
|
|
$manager = $this->get("starkerxp_campagne.manager.template"); |
|
|
|
|
78
|
|
|
|
79
|
|
|
return new JsonResponse(["payload" => ""], 204); //404 /400 |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
} |
83
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.