Implementing report profiles and disclosure policy as per spec 357. Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #428
162 lines
5.8 KiB
PHP
162 lines
5.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Support\ReviewPacks;
|
|
|
|
final class ReportProfileRegistry
|
|
{
|
|
public const string QUERY_PARAMETER = 'profile';
|
|
|
|
public const string CUSTOMER_EXECUTIVE = 'customer_executive';
|
|
|
|
public const string CUSTOMER_TECHNICAL = 'customer_technical';
|
|
|
|
public const string INTERNAL_MSP_REVIEW = 'internal_msp_review';
|
|
|
|
public const string AUDITOR_APPENDIX = 'auditor_appendix';
|
|
|
|
public const string FRAMEWORK_READINESS = 'framework_readiness';
|
|
|
|
public const string DEFAULT_PROFILE = self::INTERNAL_MSP_REVIEW;
|
|
|
|
/**
|
|
* @return array<string, array{
|
|
* profile_key:string,
|
|
* label_key:string,
|
|
* audience_key:string,
|
|
* implemented:bool,
|
|
* is_customer_facing:bool,
|
|
* show_section_appendix:bool,
|
|
* show_technical_details:bool
|
|
* }>
|
|
*/
|
|
public static function all(): array
|
|
{
|
|
return [
|
|
self::CUSTOMER_EXECUTIVE => [
|
|
'profile_key' => self::CUSTOMER_EXECUTIVE,
|
|
'label_key' => 'localization.review.report_profile_customer_executive',
|
|
'audience_key' => 'localization.review.report_audience_customer_executive',
|
|
'implemented' => true,
|
|
'is_customer_facing' => true,
|
|
'show_section_appendix' => false,
|
|
'show_technical_details' => false,
|
|
],
|
|
self::CUSTOMER_TECHNICAL => [
|
|
'profile_key' => self::CUSTOMER_TECHNICAL,
|
|
'label_key' => 'localization.review.report_profile_customer_technical',
|
|
'audience_key' => 'localization.review.report_audience_customer_technical',
|
|
'implemented' => true,
|
|
'is_customer_facing' => true,
|
|
'show_section_appendix' => true,
|
|
'show_technical_details' => true,
|
|
],
|
|
self::INTERNAL_MSP_REVIEW => [
|
|
'profile_key' => self::INTERNAL_MSP_REVIEW,
|
|
'label_key' => 'localization.review.report_profile_internal_msp_review',
|
|
'audience_key' => 'localization.review.report_audience_internal_msp_review',
|
|
'implemented' => true,
|
|
'is_customer_facing' => false,
|
|
'show_section_appendix' => true,
|
|
'show_technical_details' => true,
|
|
],
|
|
self::AUDITOR_APPENDIX => [
|
|
'profile_key' => self::AUDITOR_APPENDIX,
|
|
'label_key' => 'localization.review.report_profile_auditor_appendix',
|
|
'audience_key' => 'localization.review.report_audience_controlled_auditor',
|
|
'implemented' => true,
|
|
'is_customer_facing' => false,
|
|
'show_section_appendix' => true,
|
|
'show_technical_details' => true,
|
|
],
|
|
self::FRAMEWORK_READINESS => [
|
|
'profile_key' => self::FRAMEWORK_READINESS,
|
|
'label_key' => 'localization.review.report_profile_framework_readiness',
|
|
'audience_key' => 'localization.review.report_audience_internal_msp_review',
|
|
'implemented' => false,
|
|
'is_customer_facing' => false,
|
|
'show_section_appendix' => false,
|
|
'show_technical_details' => false,
|
|
],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array{
|
|
* profile_key:string,
|
|
* requested_key:?string,
|
|
* effective_key:string,
|
|
* label_key:string,
|
|
* label:string,
|
|
* audience_key:string,
|
|
* audience_label:string,
|
|
* implemented:bool,
|
|
* is_customer_facing:bool,
|
|
* show_section_appendix:bool,
|
|
* show_technical_details:bool,
|
|
* is_fallback:bool,
|
|
* fallback_reason:?string
|
|
* }
|
|
*/
|
|
public static function resolve(?string $requestedKey, ?string $defaultProfileKey = null): array
|
|
{
|
|
$profiles = self::all();
|
|
$normalizedRequestedKey = self::normalizeKey($requestedKey);
|
|
$defaultProfileKey = array_key_exists((string) $defaultProfileKey, $profiles)
|
|
? (string) $defaultProfileKey
|
|
: self::DEFAULT_PROFILE;
|
|
|
|
$effectiveProfile = $profiles[$defaultProfileKey];
|
|
$isFallback = false;
|
|
$fallbackReason = null;
|
|
|
|
if ($normalizedRequestedKey !== null) {
|
|
$requestedProfile = $profiles[$normalizedRequestedKey] ?? null;
|
|
|
|
if (! is_array($requestedProfile)) {
|
|
$effectiveProfile = $profiles[self::DEFAULT_PROFILE];
|
|
$isFallback = true;
|
|
$fallbackReason = 'unknown_profile';
|
|
} elseif (! (bool) ($requestedProfile['implemented'] ?? false)) {
|
|
$effectiveProfile = $profiles[self::DEFAULT_PROFILE];
|
|
$isFallback = true;
|
|
$fallbackReason = 'unimplemented_profile';
|
|
} else {
|
|
$effectiveProfile = $requestedProfile;
|
|
}
|
|
}
|
|
|
|
$effectiveKey = (string) $effectiveProfile['profile_key'];
|
|
|
|
return $effectiveProfile + [
|
|
'requested_key' => $normalizedRequestedKey,
|
|
'effective_key' => $effectiveKey,
|
|
'label' => __((string) $effectiveProfile['label_key']),
|
|
'audience_label' => __((string) $effectiveProfile['audience_key']),
|
|
'is_fallback' => $isFallback,
|
|
'fallback_reason' => $fallbackReason,
|
|
];
|
|
}
|
|
|
|
public static function defaultForRenderedReportState(string $state, bool $customerSafeHandoff): string
|
|
{
|
|
if ($state === ReviewPackOutputResolutionGuidance::STATE_CUSTOMER_SAFE_READY) {
|
|
return self::CUSTOMER_EXECUTIVE;
|
|
}
|
|
|
|
return self::DEFAULT_PROFILE;
|
|
}
|
|
|
|
private static function normalizeKey(?string $requestedKey): ?string
|
|
{
|
|
$requestedKey = trim((string) $requestedKey);
|
|
|
|
if ($requestedKey === '') {
|
|
return null;
|
|
}
|
|
|
|
return strtolower($requestedKey);
|
|
}
|
|
}
|