$unused) { if (strpos((string) $name, 'custom@') === 0) { return ''; // hosts have their own keys: the old shared one belongs to no host any more } } return (string) ($keys['custom'] ?? ''); } /** * Store a key. For a custom API the key goes to its host; a key from before there was one per host * moves to the host it was used with. * * @param array $settings Settings to change. * @param string $provider Provider key. * @param string $key The key. * @param string $customUrl Custom API URL the key belongs to. */ function store_api_key(array &$settings, string $provider, string $key, string $customUrl = ''): void { if (!isset($settings['api_keys']) || !is_array($settings['api_keys'])) { $settings['api_keys'] = []; } if ($provider !== 'custom' || api_host($customUrl) === '') { $settings['api_keys'][$provider] = $key; return; } $oldHost = api_host((string) ($settings['custom_api_url'] ?? '')); if ($oldHost !== '' && !empty($settings['api_keys']['custom']) && !isset($settings['api_keys']['custom@' . $oldHost])) { $settings['api_keys']['custom@' . $oldHost] = $settings['api_keys']['custom']; } unset($settings['api_keys']['custom']); $settings['api_keys'][api_key_slot('custom', $customUrl)] = $key; }