Example #1
0
 public static function merge(array $input, $message_list, $options = array())
 {
     $context = isset($options['context']) ? $options['context'] : null;
     $mixables = array();
     foreach (Util::splitDelimList($message_list) as $message) {
         if ($result = self::call($message, $context)) {
             $mixables = array_merge($mixables, $result);
         }
     }
     while ($mixable = array_shift($mixables)) {
         if ($mixable instanceof Declaration) {
             $input[] = $mixable;
         } else {
             list($property, $value) = $mixable;
             if ($property === 'mixin') {
                 $input = Mixin::merge($input, $value, $options);
             } elseif (!empty($options['keyed'])) {
                 $input[$property] = $value;
             } else {
                 $input[] = array($property, $value);
             }
         }
     }
     return $input;
 }
 public function flatten($rule_context)
 {
     if ($this->flattened) {
         return;
     }
     $new_set = array();
     foreach ($this->store as $declaration) {
         if (is_array($declaration) && $declaration[0] === 'mixin') {
             foreach (Mixin::merge(array(), $declaration[1], array('context' => $rule_context)) as $mixable) {
                 if ($mixable instanceof Declaration) {
                     $clone = clone $mixable;
                     $clone->index = count($new_set);
                     $new_set[] = $clone;
                 } else {
                     $new_set[] = new Declaration($mixable[0], $mixable[1], count($new_set));
                 }
             }
         } else {
             $declaration->index = count($new_set);
             $new_set[] = $declaration;
         }
     }
     $this->reset($new_set);
     $this->flattened = true;
 }