TenantAtlas/apps/platform/app/Services/Providers/ProviderOperationStartGate.php
2026-07-07 15:54:34 +02:00

54 lines
1.7 KiB
PHP

<?php
namespace App\Services\Providers;
use App\Models\ManagedEnvironment;
use App\Models\ProviderConnection;
use App\Models\User;
use App\Support\Providers\ProviderReasonCodes;
final class ProviderOperationStartGate
{
public function __construct(
private readonly ProviderOperationTrustedStarter $trustedStarter,
) {}
/**
* @param array<string, mixed> $extraContext
*/
public function start(
ManagedEnvironment $tenant,
?ProviderConnection $connection,
string $operationType,
callable $dispatcher,
?User $initiator = null,
array $extraContext = [],
): ProviderOperationStartResult {
if ($this->isExchangePowerShellInvocationOperation($operationType)) {
return $this->trustedStarter->block(
tenant: $tenant,
connection: $connection,
operationType: $operationType,
reasonCode: ProviderReasonCodes::ProviderBindingUnsupported,
extensionReasonCode: 'ext.exchange_powershell_invocation_gate_required',
reasonMessage: 'Exchange PowerShell invocation must start through the invocation gate.',
initiator: $initiator,
);
}
return $this->trustedStarter->start(
tenant: $tenant,
connection: $connection,
operationType: $operationType,
dispatcher: $dispatcher,
initiator: $initiator,
extraContext: $extraContext,
);
}
private function isExchangePowerShellInvocationOperation(string $operationType): bool
{
return $operationType === 'tenant_configuration.exchange_powershell_invocation';
}
}