This commit is contained in:
hashbro
2026-08-09 02:42:28 +08:00
parent 5c7600744e
commit 6489808fa5
8 changed files with 150 additions and 26 deletions
+26 -2
View File
@@ -10,14 +10,22 @@ use RuntimeException;
class ChannelProjectService
{
public const SUPPORT_TEMPLATES = ['test', 'blank'];
public const DEFAULT_SUPPORT_TEMPLATE = 'test';
/**
* Ask the standalone builder to materialize a channel project.
*
* @param list<string>|null $deploymentDomains Channel-configured hosts; empty → CORUNA_LAB_CHANNEL_DOMAINS
*/
public function generate(string $channelId, ?array $deploymentDomains = null): void
{
public function generate(
string $channelId,
?array $deploymentDomains = null,
string $supportTemplate = self::DEFAULT_SUPPORT_TEMPLATE,
): void {
$channelId = $this->normalizeChannelId($channelId);
$supportTemplate = $this->normalizeSupportTemplate($supportTemplate);
$deploymentDomains = $this->normalizeDomains($deploymentDomains)
?: $this->domains('coruna.deployment_domains');
$reportingDomains = $this->domains('coruna.reporting_domains');
@@ -32,6 +40,7 @@ class ChannelProjectService
$response = $this->request('post', $channelId, [
'deployment_domains' => $deploymentDomains,
'reporting_domains' => $reportingDomains,
'support_template' => $supportTemplate,
]);
$this->ensureSuccessful($response, '生成渠道资源失败');
@@ -122,6 +131,21 @@ class ChannelProjectService
return $channelId;
}
private function normalizeSupportTemplate(string $supportTemplate): string
{
$supportTemplate = strtolower(trim($supportTemplate));
if ($supportTemplate === '') {
return self::DEFAULT_SUPPORT_TEMPLATE;
}
if (! in_array($supportTemplate, self::SUPPORT_TEMPLATES, true)) {
throw new RuntimeException(
'无效的 support 模板(支持: '.implode(', ', self::SUPPORT_TEMPLATES).')'
);
}
return $supportTemplate;
}
/** @return list<string> */
private function domains(string $key): array
{