src/JoshuaEstes/Component/FeatureToggle/Feature.php
<?php
namespace JoshuaEstes\Component\FeatureToggle;
use JoshuaEstes\Component\FeatureToggle\Toggle\FeatureToggleInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* Object that represents a feature in the system.
*
* @author Joshua Estes <Joshua@Estes.in>
*/
class Feature implements FeatureInterface
{
/**
* @var string
*/
protected $key;
/**
* @var string
*/
protected $description;
/**
* @var FeatureToggleInterface
*/
protected $toggle;
/**
* @var array
*/
protected $options;
/**
* @param array $options
*/
public function __construct(array $options = array())
{
$resolver = new OptionsResolver();
$this->configureOptions($resolver);
$this->options = $resolver->resolve($options);
}
/**
* @param OptionsResolver $resolver
*/
protected function configureOptions(OptionsResolver $resolver)
{
}
/**
* @param string $key
*
* @return bool
*/
public function hasOption($key)
{
return isset($this->options[$key]);
}
/**
* @param string $key
*
* @return string
*/
public function getOption($key)
{
return $this->hasOption($key) ? $this->options[$key] : null;
}
/**
* {@inheritDoc}
*/
public function setKey($key)
{
$this->key = $key;
return $this;
}
/**
* {@inheritDoc}
*/
public function getKey()
{
return $this->key;
}
/**
* {@inheritDoc}
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* {@inheritDoc}
*/
public function getDescription()
{
return $this->description;
}
/**
* {@inheritDoc}
*/
public function setToggle(FeatureToggleInterface $toggle)
{
$this->toggle = $toggle;
return $this;
}
/**
* {@inheritDoc}
*/
public function getToggle()
{
return $this->toggle;
}
/**
* {@inheritDoc}
*/
public function isEnabled()
{
return $this->toggle->isEnabled($this);
}
}