1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Opensoft\RolloutBundle\Controller; |
4
|
|
|
|
5
|
|
|
use Opensoft\Rollout\Rollout; |
6
|
|
|
use Opensoft\RolloutBundle\Rollout\UserProviderInterface; |
7
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
8
|
|
|
use Symfony\Component\DependencyInjection\ContainerAware; |
9
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
10
|
|
|
use Symfony\Component\HttpFoundation\Request; |
11
|
|
|
use Symfony\Component\HttpFoundation\Response; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @author Richard Fullmer <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
class DefaultController extends ContainerAware |
|
|
|
|
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @return Response |
20
|
|
|
*/ |
21
|
|
|
public function indexAction() |
22
|
|
|
{ |
23
|
|
|
return $this->container->get('templating')->renderResponse('OpensoftRolloutBundle:Default:index.html.twig', array('rollout' => $this->getRollout())); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param string $feature |
28
|
|
|
* @return RedirectResponse |
29
|
|
|
*/ |
30
|
|
|
public function activateAction($feature) |
31
|
|
|
{ |
32
|
|
|
$this->getRollout()->activate($feature); |
33
|
|
|
|
34
|
|
|
$this->addFlash('success', sprintf("Feature '%s' is now globally activated", $feature)); |
35
|
|
|
|
36
|
|
|
return $this->createRedirectToFeatureListReponse(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param string $feature |
41
|
|
|
* @return RedirectResponse |
42
|
|
|
*/ |
43
|
|
|
public function deactivateAction($feature) |
44
|
|
|
{ |
45
|
|
|
$this->getRollout()->deactivate($feature); |
46
|
|
|
|
47
|
|
|
$this->addFlash('danger', sprintf("Feature '%s' is now globally deactivated", $feature)); |
48
|
|
|
|
49
|
|
|
return $this->createRedirectToFeatureListReponse(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param string $feature |
54
|
|
|
* @return RedirectResponse |
55
|
|
|
*/ |
56
|
|
View Code Duplication |
public function incrementPercentageAction($feature) |
|
|
|
|
57
|
|
|
{ |
58
|
|
|
$rollout = $this->getRollout(); |
59
|
|
|
$percentage = $rollout->get($feature)->getPercentage() + 10; |
60
|
|
|
$rollout->activatePercentage($feature, $percentage); |
61
|
|
|
|
62
|
|
|
$this->addFlash('info', sprintf("Feature '%s' percentage changed to %d%% of all users", $feature, $percentage)); |
63
|
|
|
|
64
|
|
|
return $this->createRedirectToFeatureListReponse(); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param string $feature |
69
|
|
|
* @return RedirectResponse |
70
|
|
|
*/ |
71
|
|
View Code Duplication |
public function decrementPercentageAction($feature) |
|
|
|
|
72
|
|
|
{ |
73
|
|
|
$rollout = $this->getRollout(); |
74
|
|
|
$percentage = $rollout->get($feature)->getPercentage() - 10; |
75
|
|
|
$rollout->activatePercentage($feature, $percentage); |
76
|
|
|
|
77
|
|
|
$this->addFlash('info', sprintf("Feature '%s' percentage changed to %d%% of all users", $feature, $percentage)); |
78
|
|
|
|
79
|
|
|
return $this->createRedirectToFeatureListReponse(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param string $feature |
84
|
|
|
* @param string $group |
85
|
|
|
* @return RedirectResponse |
86
|
|
|
*/ |
87
|
|
View Code Duplication |
public function activateGroupAction($feature, $group) |
|
|
|
|
88
|
|
|
{ |
89
|
|
|
$this->getRollout()->activateGroup($feature, $group); |
90
|
|
|
|
91
|
|
|
$this->addFlash('info', sprintf("Feature '%s' is now active in group '%s'", $feature, $group)); |
92
|
|
|
|
93
|
|
|
return $this->createRedirectToFeatureListReponse(); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param string $feature |
98
|
|
|
* @param string $group |
99
|
|
|
* @return RedirectResponse |
100
|
|
|
*/ |
101
|
|
View Code Duplication |
public function deactivateGroupAction($feature, $group) |
|
|
|
|
102
|
|
|
{ |
103
|
|
|
$this->getRollout()->deactivateGroup($feature, $group); |
104
|
|
|
|
105
|
|
|
$this->addFlash('info', sprintf("Feature '%s' is no longer active in group '%s'", $feature, $group)); |
106
|
|
|
|
107
|
|
|
return $this->createRedirectToFeatureListReponse(); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @param Request $request |
112
|
|
|
* @param string $feature |
113
|
|
|
* @return RedirectResponse |
114
|
|
|
*/ |
115
|
|
|
public function activateUserAction(Request $request, $feature) |
116
|
|
|
{ |
117
|
|
|
$requestUser = $request->get('user'); |
118
|
|
|
$user = $this->getRolloutUserProvider()->findByRolloutIdentifier($requestUser); |
119
|
|
|
|
120
|
|
|
if ($user) { |
121
|
|
|
$this->getRollout()->activateUser($feature, $user); |
122
|
|
|
|
123
|
|
|
$this->addFlash('info', sprintf("User '%s' was activated in feature '%s'", $user->getRolloutIdentifier(), $feature)); |
124
|
|
|
} else { |
125
|
|
|
$this->addFlash('danger', sprintf("User '%s' not found", $requestUser)); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
return $this->createRedirectToFeatureListReponse(); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @param string $feature |
133
|
|
|
* @param string $id |
134
|
|
|
* @return RedirectResponse |
135
|
|
|
*/ |
136
|
|
|
public function deactivateUserAction($feature, $id) |
137
|
|
|
{ |
138
|
|
|
$user = $this->getRolloutUserProvider()->findByRolloutIdentifier($id); |
139
|
|
|
$this->getRollout()->deactivateUser($feature, $user); |
|
|
|
|
140
|
|
|
|
141
|
|
|
$this->addFlash('info', sprintf("User '%s' was deactivated from feature '%s'", $user->getRolloutIdentifier(), $feature)); |
142
|
|
|
|
143
|
|
|
return $this->createRedirectToFeatureListReponse(); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @param string $feature |
148
|
|
|
* @return RedirectResponse |
149
|
|
|
*/ |
150
|
|
|
public function removeAction($feature) |
151
|
|
|
{ |
152
|
|
|
$this->getRollout()->remove($feature); |
153
|
|
|
|
154
|
|
|
$this->addFlash('info', sprintf("Feature '%s' was removed from rollout.", $feature)); |
155
|
|
|
|
156
|
|
|
return $this->createRedirectToFeatureListReponse(); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @param Request $request |
161
|
|
|
* @param string $feature |
162
|
|
|
* @return RedirectResponse |
163
|
|
|
*/ |
164
|
|
|
public function setRequestParamAction(Request $request, $feature) |
165
|
|
|
{ |
166
|
|
|
$requestParam = $request->get('requestParam'); |
167
|
|
|
if ($requestParam === null) { |
168
|
|
|
$this->addFlash('danger', 'Missing "requestParam" value'); |
169
|
|
|
return $this->createRedirectToFeatureListReponse(); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
$this->getRollout()->activateRequestParam($feature, $requestParam); |
173
|
|
|
|
174
|
|
|
$this->addFlash('info', sprintf('Feature "%s" requestParam changed to "%s"', $feature, $requestParam)); |
175
|
|
|
|
176
|
|
|
return $this->createRedirectToFeatureListReponse(); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @return Rollout |
181
|
|
|
*/ |
182
|
|
|
private function getRollout() |
183
|
|
|
{ |
184
|
|
|
return $this->container->get('rollout'); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* @return UserProviderInterface |
189
|
|
|
*/ |
190
|
|
|
private function getRolloutUserProvider() |
191
|
|
|
{ |
192
|
|
|
return $this->container->get('rollout.user_provider'); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* Helper for adding flash messages |
197
|
|
|
* |
198
|
|
|
* @param string $type |
199
|
|
|
* @param string $message |
200
|
|
|
*/ |
201
|
|
|
private function addFlash($type, $message) |
202
|
|
|
{ |
203
|
|
|
$this->container->get('session')->getFlashBag()->add($type, $message); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @return RedirectResponse |
208
|
|
|
*/ |
209
|
|
|
private function createRedirectToFeatureListReponse() |
210
|
|
|
{ |
211
|
|
|
return new RedirectResponse($this->container->get('router')->generate('opensoft_rollout')); |
212
|
|
|
} |
213
|
|
|
} |
214
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.