public static function normalizeBrackets(array $input, array $validKeys) { $output = []; foreach ($input as $key => $value) { $attribute = null; $options = []; if (is_int($key)) { if ($value) { if (is_string($value) && in_array($value, $validKeys)) { $attribute = $value; } elseif (is_array($value)) { if (array_key_exists(0, $value) && $value[0] && is_string($value[0]) && in_array($value[0], $validKeys)) { $attribute = $value[0]; $options = $value; unset($options[0]); } elseif (array_key_exists('attribute', $value) && $value['attribute'] && is_string($value['attribute']) && in_array($value['attribute'], $validKeys)) { $attribute = $value['attribute']; $options = $value; unset($options['attribute']); } } } } elseif ($key && is_string($key) && in_array($key, $validKeys)) { $attribute = $key; if ($value) { if (is_string($value)) { if ($value == 'invisible') { $options['visible'] = false; } elseif (class_exists($value) && is_subclass_of($value, Object::className())) { $options['class'] = $value; } else { $options['type'] = $value; } } elseif (is_array($value)) { $options = $value; } } elseif ($value === false) { $options['visible'] = false; } } if (array_key_exists($attribute, $output)) { $output[$attribute] = ArrayHelper::merge($output[$attribute], $options); } else { $output[$attribute] = $options; } } return $output; }
/** * @inheritdoc */ public function init() { parent::init(); $this->db = Instance::ensure($this->db, Object::className()); }