|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
|
4
|
|
|
|
|
5
|
|
|
namespace WMDE\Fundraising\Frontend\Infrastructure; |
|
6
|
|
|
|
|
7
|
|
|
use WMDE\Fundraising\DonationContext\Domain\Model\Donor; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* This class is for generating the expected address type strings for the AddDonationRequest und UpdateDonorRequest. |
|
11
|
|
|
*/ |
|
12
|
|
|
class AddressType { |
|
13
|
|
|
public const PERSON = 'person'; |
|
14
|
|
|
public const COMPANY = 'company'; |
|
15
|
|
|
public const EMAIL = 'email'; |
|
16
|
|
|
public const ANONYMOUS = 'anonymous'; |
|
17
|
|
|
|
|
18
|
|
|
public const LEGACY_PERSON = 'person'; |
|
19
|
|
|
public const LEGACY_COMPANY = 'firma'; |
|
20
|
|
|
public const LEGACY_EMAIL = 'email'; |
|
21
|
|
|
public const LEGACY_ANONYMOUS = 'anonym'; |
|
22
|
|
|
|
|
23
|
|
|
private const PRESENTATION_TO_DOMAIN = [ |
|
24
|
|
|
self::LEGACY_PERSON => self::PERSON, |
|
25
|
|
|
self::LEGACY_COMPANY => self::COMPANY, |
|
26
|
|
|
self::LEGACY_EMAIL => self::EMAIL, |
|
27
|
|
|
self::LEGACY_ANONYMOUS => self::ANONYMOUS |
|
28
|
|
|
]; |
|
29
|
|
|
|
|
30
|
|
|
public static function presentationAddressTypeToDomainAddressType( string $presentationAddressType ): string { |
|
31
|
|
|
if ( !isset( self::PRESENTATION_TO_DOMAIN[$presentationAddressType] ) ) { |
|
32
|
|
|
throw new \UnexpectedValueException( sprintf( 'Unexpected Presentation Address Type: %s', $presentationAddressType, ) ); |
|
33
|
|
|
} |
|
34
|
|
|
return self::PRESENTATION_TO_DOMAIN[$presentationAddressType]; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public static function donorToPresentationAddressType( Donor $donor ): string { |
|
38
|
|
|
$invertedMap = array_flip( self::PRESENTATION_TO_DOMAIN ); |
|
39
|
|
|
if ( !isset( $invertedMap[$donor->getDonorType()] ) ) { |
|
40
|
|
|
throw new \UnexpectedValueException( sprintf( 'Unexpected Donor Type: %s', $donor->getDonorType(), ) ); |
|
41
|
|
|
} |
|
42
|
|
|
return $invertedMap[$donor->getDonorType()]; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
|