$key, 'label' => $label, 'type' => $type, 'url' => $url, 'icon' => $icon, 'kind' => $kind, 'action_name' => $actionName, 'capability' => $capability, 'requires_confirmation' => $requiresConfirmation, 'audit_event' => $auditEvent, 'operation_run_type' => $operationRunType, 'disabled_reason' => $disabledReason, ]; } /** * @return array{ * key:string, * label:string, * type:string, * url:null, * icon:string, * kind:string, * action_name:null, * capability:null, * requires_confirmation:false, * audit_event:null, * operation_run_type:null, * disabled_reason:?string * } */ public static function none(string $key, string $label, ?string $disabledReason = null): array { return [ 'key' => $key, 'label' => $label, 'type' => self::TYPE_NONE, 'url' => null, 'icon' => self::iconForType(self::TYPE_NONE), 'kind' => 'none', 'action_name' => null, 'capability' => null, 'requires_confirmation' => false, 'audit_event' => null, 'operation_run_type' => null, 'disabled_reason' => $disabledReason, ]; } private static function typeFromKind(?string $kind, ?string $url): string { return match ($kind) { 'download' => self::TYPE_DOWNLOAD, 'disclosure' => self::TYPE_DISCLOSURE, 'none' => self::TYPE_NONE, default => $url !== null ? self::TYPE_NAVIGATION : self::TYPE_NONE, }; } private static function fallbackType(?string $kind, ?string $url): string { return match (true) { $kind === 'download' => self::TYPE_DOWNLOAD, $kind === 'disclosure' => self::TYPE_DISCLOSURE, $url !== null => self::TYPE_NAVIGATION, default => self::TYPE_NONE, }; } private static function kindFromType(string $type, ?string $kind): string { if (is_string($kind) && $kind !== '') { return $kind; } return match ($type) { self::TYPE_DOWNLOAD => 'download', self::TYPE_DISCLOSURE => 'disclosure', self::TYPE_NONE => 'none', default => 'environment_link', }; } private static function iconForType(string $type): string { return match ($type) { self::TYPE_DOWNLOAD => 'heroicon-o-arrow-down-tray', self::TYPE_DISCLOSURE => 'heroicon-o-information-circle', self::TYPE_NONE => 'heroicon-o-minus-circle', default => 'heroicon-o-arrow-top-right-on-square', }; } private static function isUnsafeExecutable( string $type, ?string $capability, ?string $auditEvent, bool $requiresConfirmation, ?string $operationRunType, ): bool { if (! in_array($type, [self::TYPE_DOMAIN_ACTION, self::TYPE_OPERATION_ACTION], true)) { return false; } if ($capability === null || $auditEvent === null) { return true; } if (! $requiresConfirmation) { return true; } return $type === self::TYPE_OPERATION_ACTION && $operationRunType === null; } }