You are here

public function CSSCompression_Option::merge in Advanced CSS/JS Aggregation 7

Same name and namespace in other branches
  1. 6 advagg_css_compress/css-compressor-3.x/src/lib/Option.inc \CSSCompression_Option::merge()

Extend like function to merge an array of preferences into the options array.

Parameters

(mixed) options: Array of preferences to merge into options:

1 call to CSSCompression_Option::merge()
CSSCompression_Option::option in advagg_css_compress/css-compressor-3.x/src/lib/Option.inc
Maintainable access to the options array

File

advagg_css_compress/css-compressor-3.x/src/lib/Option.inc, line 78

Class

CSSCompression_Option
CSS Compressor [VERSION] [DATE] Corey Hart @ http://www.codenothing.com

Code

public function merge($options = array()) {
  $modes = CSSCompression::modes();
  if ($options && is_array($options) && count($options)) {
    $this->Control->mode = $this->custom;
    foreach ($this->options as $key => $value) {
      if (!isset($options[$key])) {
        continue;
      }
      else {
        if (strtolower($options[$key]) == 'on') {
          $this->options[$key] = true;
        }
        else {
          if (strtolower($options[$key]) == 'off') {
            $this->options[$key] = false;
          }
          else {
            $this->options[$key] = intval($options[$key]);
          }
        }
      }
    }
  }
  else {
    if ($options && is_string($options) && array_key_exists($options, $modes)) {
      $this->Control->mode = $options;

      // Default all to true, the mode has to force false
      foreach ($this->options as $key => $value) {
        if ($key != 'readability') {
          $this->options[$key] = true;
        }
      }

      // Merge mode into options
      foreach ($modes[$options] as $key => $value) {
        $this->options[$key] = $value;
      }
    }
  }
  return $this->options;
}