示例#1
0
 /**
  * @param string $feature
  * @param array  $context
  *
  * @return bool
  */
 public function isActive($feature, array $context = [])
 {
     $value = $this->config->get($feature);
     switch (true) {
         case $value instanceof Expression:
             $value = $this->evaluateExpression($feature, $value, $context);
             break;
         case is_callable($value):
             $value = $this->evaluateCallback($feature, $value, $context);
             break;
     }
     return $this->isTruthy($value);
 }
示例#2
0
 public function boot()
 {
     $config = null;
     if ($this->container->hasParameter('toggler.config')) {
         $config = $this->container->getParameter('toggler.config');
     } else {
         if ($this->container->has('toggler.config')) {
             $config = $this->container->get('toggler.config');
         }
     }
     Config::instance()->setConfig($config);
 }
示例#3
0
/**
 * @param array|StorageInterface $features
 *
 * @return Config
 * @throws Exception
 */
function toggleConfig($features)
{
    $config = Config::instance();
    if (is_array($features) || $features instanceof StorageInterface) {
        return $config->setConfig($features);
    }
    if (is_file($file = realpath($features))) {
        if ('yml' === pathinfo($file, PATHINFO_EXTENSION)) {
            if (!class_exists('Symfony\\Component\\Yaml\\Yaml')) {
                throw new \Exception('The Symfony Yaml component is needed in order to load config from yml filed');
            }
            return $config->setConfig(Yaml::parse(file_get_contents($file)));
        }
        $values = (require_once $file);
        return $config->setConfig($values);
    }
}
示例#4
0
 protected function tearDown()
 {
     Config::instance()->clear();
 }