|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of the Adlogix package. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Allan Segebarth <[email protected]> |
|
6
|
|
|
* (c) Jean-Jacques Courtens <[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 Adlogix\Zf2Rollout\Service\Controller; |
|
13
|
|
|
|
|
14
|
|
|
use Opensoft\Rollout\Rollout; |
|
15
|
|
|
use Opensoft\Rollout\RolloutUserInterface; |
|
16
|
|
|
use Zend\Http\Header\Referer; |
|
17
|
|
|
use Zend\Http\Request; |
|
18
|
|
|
use Zend\Mvc\Controller\AbstractActionController; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @author Toni Van de Voorde <[email protected]> |
|
22
|
|
|
*/ |
|
23
|
|
|
final class RolloutController extends AbstractActionController |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var Rollout |
|
27
|
|
|
*/ |
|
28
|
|
|
private $rollout; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var RolloutUserInterface |
|
32
|
|
|
*/ |
|
33
|
|
|
private $rolloutUser; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @param Rollout $rollout |
|
37
|
|
|
* @param RolloutUserInterface $rolloutUser |
|
38
|
|
|
*/ |
|
39
|
|
|
public function __construct( |
|
40
|
|
|
Rollout $rollout, |
|
41
|
|
|
RolloutUserInterface $rolloutUser |
|
42
|
|
|
) { |
|
43
|
|
|
$this->rollout = $rollout; |
|
44
|
|
|
$this->rolloutUser = $rolloutUser; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @return \Zend\Http\Response |
|
49
|
|
|
*/ |
|
50
|
|
|
public function toggleFeatureAction() |
|
51
|
|
|
{ |
|
52
|
|
|
$feature = $this->params()->fromRoute('feature'); |
|
53
|
|
|
|
|
54
|
|
|
if ($this->rollout->isActive($feature, $this->rolloutUser)) { |
|
55
|
|
|
$this->rollout->deactivateUser($feature, $this->rolloutUser); |
|
56
|
|
|
} else { |
|
57
|
|
|
$this->rollout->activateUser($feature, $this->rolloutUser); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
return $this->redirect()->toUrl($this->getRefererUri()); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @return string The referer URI (if not available returns '/' ) |
|
65
|
|
|
*/ |
|
66
|
|
|
protected function getRefererUri() |
|
67
|
|
|
{ |
|
68
|
|
|
/** @var Request $request */ |
|
69
|
|
|
$request = $this->getRequest(); |
|
70
|
|
|
|
|
71
|
|
|
$headers = $request->getHeader('Referer', '/'); |
|
72
|
|
|
|
|
73
|
|
|
return $headers instanceof Referer ? $headers->getUri() : (string)$headers; |
|
74
|
|
|
} |
|
75
|
|
|
} |