1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* zf2-featureflags. |
4
|
|
|
* |
5
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
6
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
7
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
8
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
9
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
10
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
11
|
|
|
* SOFTWARE. |
12
|
|
|
* |
13
|
|
|
* @copyright 2016 MehrAlsNix (http://www.mehralsnix.de) |
14
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
15
|
|
|
* |
16
|
|
|
* @link http://github.com/MehrAlsNix/zf2-featureflags |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace MehrAlsNix\FeatureToggle\Factory; |
20
|
|
|
|
21
|
|
|
use MehrAlsNix\FeatureToggle\Context\EnvContext; |
22
|
|
|
use Qandidate\Toggle\Context; |
23
|
|
|
use Zend\Http\PhpEnvironment\Request; |
24
|
|
|
use Zend\ServiceManager\Exception\ServiceNotFoundException; |
25
|
|
|
use Zend\ServiceManager\FactoryInterface; |
26
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
27
|
|
|
|
28
|
|
|
class EnvContextFactory implements FactoryInterface |
|
|
|
|
29
|
|
|
{ |
30
|
|
|
private $name = ''; |
31
|
|
|
|
32
|
|
|
public function __construct($name = '') |
33
|
|
|
{ |
34
|
|
|
$this->name = $name; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Create service |
39
|
|
|
* |
40
|
|
|
* @param ServiceLocatorInterface $serviceLocator |
41
|
|
|
* |
42
|
|
|
* @return Context |
43
|
|
|
* |
44
|
|
|
* @throws ServiceNotFoundException |
45
|
|
|
*/ |
46
|
|
|
public function createService(ServiceLocatorInterface $serviceLocator) |
47
|
|
|
{ |
48
|
|
|
$name = $this->name; |
49
|
|
|
|
50
|
|
|
if ($name === '') { |
51
|
|
|
$name = $serviceLocator->get('Config')['zf2_featureflags']['envContext']; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** @var Request $request */ |
55
|
|
|
$request = $serviceLocator->get('Request'); |
56
|
|
|
|
57
|
|
|
$envContext = new EnvContext($name, $request); |
58
|
|
|
|
59
|
|
|
return $envContext->createContext(); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|