/**
  * @param ConfigInterface $config
  *
  * @return DirectiveInterface
  * @throws Exception
  */
 public function mergeInto(ConfigInterface $config) : DirectiveInterface
 {
     $identifier = static::class;
     // only set directive if it is not present or if it can be overridden
     $config->set($identifier, (new ValueMerger($this->mergePolicy))->merge($config->get($identifier), $this->getValue()));
     return $this;
 }
 /**
  * @param ConfigInterface $config
  *
  * @return DirectiveInterface
  * @throws Exception
  */
 public function mergeInto(ConfigInterface $config) : DirectiveInterface
 {
     $identifier = sprintf('%s.%s', static::class, $this->identifier);
     // only set directive if it is not present
     if ($config->lacks($identifier)) {
         $config->set($identifier, $this->getValue());
         return $this;
     }
     $mergePolicy = $this->mergePolicy;
     // automatically define the merge policy depending
     // on current directive value
     //
     // - MERGE arrays
     // - REPLACE other types
     if ($mergePolicy == MergePolicy::AUTO) {
         if (is_array($config->get($identifier))) {
             $mergePolicy = MergePolicy::NATIVE;
         } else {
             $mergePolicy = MergePolicy::REPLACE;
         }
     }
     // otherwise handle MergePolicy
     switch ($mergePolicy) {
         case MergePolicy::SKIP:
             break;
         case MergePolicy::REPLACE:
             $config->set($identifier, $this->getValue());
             break;
         case MergePolicy::NATIVE:
             $combinedValue = array_merge((array) $config->get($identifier), (array) $this->value);
             $config->set($identifier, $combinedValue);
             break;
         case MergePolicy::COMBINE:
         case MergePolicy::RECURSIVE:
             $combinedValue = array_merge_recursive((array) $config->get($identifier), (array) $this->value);
             $config->set($identifier, $combinedValue);
             break;
         default:
             throw new Exception(sprintf('Unsupported merge policy "%s"', $this->mergePolicy));
     }
     return $this;
 }