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

71 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Services\TenantConfiguration;
use InvalidArgumentException;
final readonly class ExchangePowerShellCommandContract
{
/**
* @param array<string, mixed> $payload
* @param array<string, mixed> $parameters
*/
private function __construct(
private array $payload,
private array $parameters,
) {}
/**
* @param array<string, mixed> $contract
* @param array<string, mixed> $parameters
*/
public static function fromVerifiedArray(
array $contract,
ExchangePowerShellCommandContracts $contracts,
array $parameters = [],
): self {
$validation = $contracts->validateInvocation($contract, $parameters);
if (! $validation['accepted']) {
throw new InvalidArgumentException('Exchange PowerShell command contract was not verified.');
}
$commandName = $contract['command_name'] ?? null;
$canonicalContract = is_string($commandName)
? $contracts->contractForCommandName($commandName)
: null;
if (! is_array($canonicalContract)) {
throw new InvalidArgumentException('Exchange PowerShell command contract was not canonical.');
}
return new self($canonicalContract, $parameters);
}
/**
* @return array<string, mixed>
*/
public function toArray(): array
{
return $this->payload;
}
/**
* @return array<string, mixed>
*/
public function parameters(): array
{
return $this->parameters;
}
/**
* @return list<string>
*/
public function parameterNames(): array
{
return array_values(array_map('strval', array_keys($this->parameters)));
}
}