}> */ public function validateCustomKey(string $key): array { if (1 !== preg_match(UtmParameterCatalog::CUSTOM_KEY_PATTERN, $key)) { return [[self::ERROR_KEY_INVALID, ['%key%' => $key]]]; } if ($this->catalog->isReservedKey($key)) { return [[self::ERROR_KEY_RESERVED, ['%key%' => $key]]]; } return []; } /** * @param string[] $existingKeys All custom keys of the form, including $key itself * * @return list}> */ public function validateKeyIsUnique(string $key, array $existingKeys): array { $occurrences = count(array_filter($existingKeys, fn (string $other): bool => $other === $key)); return $occurrences > 1 ? [[self::ERROR_KEY_DUPLICATE, ['%key%' => $key]]] : []; } /** * Rules that apply to the whole value list of a `dropdown` parameter. Nothing is checked * for other modes: their values are never processed. * * @param array $rows * * @return list}> */ public function validateValueList(string $mode, bool $enabled, array $rows): array { if (UtmParameterMode::DROPDOWN !== $mode) { return []; } $errors = []; if ($enabled && [] === $rows) { $errors[] = [self::ERROR_VALUES_REQUIRED, []]; } $seen = []; foreach ($rows as $row) { $value = (string) ($row['value'] ?? ''); if ('' === $value) { continue; } if (isset($seen[$value]) && 1 === $seen[$value]) { $errors[] = [self::ERROR_VALUE_DUPLICATE, ['%value%' => $value]]; } $seen[$value] = ($seen[$value] ?? 0) + 1; } $defaults = array_filter($rows, fn (array $row): bool => !empty($row['is_default'])); if (count($defaults) > 1) { $errors[] = [self::ERROR_DEFAULT_MULTIPLE, []]; } return $errors; } }