Example #1
0
 public function setUp()
 {
     $this->registry = new Registry();
     $this->feature = Feature::create('top_secret', array('enabled', 'disabled'), array('whitelist' => array('127.0.0.1', '10.0.0.5')));
     $this->strategy = Strategy::create('ip_whitelist', function ($context, $options) {
         return in_array($context['client_ip'], $options['whitelist']);
     });
     // $this->strategy = Strategy::create('ip_whitelist', 'context.client_ip in options.whitelist');
     $this->registry->registerStrategy($this->strategy);
     $this->registry->register($this->feature, 'ip_whitelist');
 }
Example #2
0
 private function loadFeatures($registry)
 {
     if (!isset($this->data['features'])) {
         return;
     }
     foreach ($this->data['features'] as $name => $config) {
         $strategyName = $config['strategy'];
         if (!$strategyName) {
             throw new \RuntimeException(sprintf("A strategy must be specified for feature '%s'.", $name));
         }
         $variants = isset($config['variants']) ? $config['variants'] : ['enabled', 'disabled'];
         $feature = Feature::create($name, $variants);
         if (isset($config['options'])) {
             $feature->setOptions($config['options']);
         }
         $registry->register($feature, $strategyName);
     }
 }
Example #3
0
 public function feature($name, $strategyName, array $variants = array())
 {
     $feature = Feature::create($name, $variants);
     $this->registry->register($feature, $strategyName);
     return $feature;
 }