|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
|
4
|
|
|
|
|
5
|
|
|
namespace WMDE\Fundraising\Frontend\MembershipContext\UseCases\ShowApplicationConfirmation; |
|
6
|
|
|
|
|
7
|
|
|
use WMDE\Fundraising\Frontend\MembershipContext\Authorization\ApplicationAuthorizer; |
|
8
|
|
|
use WMDE\Fundraising\Frontend\MembershipContext\Authorization\ApplicationTokenFetcher; |
|
9
|
|
|
use WMDE\Fundraising\Frontend\MembershipContext\Domain\Repositories\ApplicationPurgedException; |
|
10
|
|
|
use WMDE\Fundraising\Frontend\MembershipContext\Domain\Repositories\ApplicationRepository; |
|
11
|
|
|
use WMDE\Fundraising\Frontend\MembershipContext\Domain\Repositories\GetMembershipApplicationException; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @license GNU GPL v2+ |
|
15
|
|
|
* @author Kai Nissen < [email protected] > |
|
16
|
|
|
*/ |
|
17
|
|
|
class ShowApplicationConfirmationUseCase { |
|
18
|
|
|
|
|
19
|
|
|
private $presenter; |
|
20
|
|
|
private $authorizer; |
|
21
|
|
|
private $repository; |
|
22
|
|
|
private $tokenFetcher; |
|
23
|
|
|
|
|
24
|
|
|
public function __construct( ShowApplicationConfirmationPresenter $presenter, ApplicationAuthorizer $authorizer, |
|
25
|
|
|
ApplicationRepository $repository, ApplicationTokenFetcher $tokenFetcher ) { |
|
26
|
|
|
$this->presenter = $presenter; |
|
27
|
|
|
$this->authorizer = $authorizer; |
|
28
|
|
|
$this->repository = $repository; |
|
29
|
|
|
$this->tokenFetcher = $tokenFetcher; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function showConfirmation( ShowAppConfirmationRequest $request ): void { |
|
33
|
|
|
if ( !$this->authorizer->canAccessApplication( $request->getApplicationId() ) ) { |
|
34
|
|
|
$this->presenter->presentAccessViolation(); |
|
35
|
|
|
return; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
try { |
|
39
|
|
|
$application = $this->repository->getApplicationById( $request->getApplicationId() ); |
|
40
|
|
|
} |
|
41
|
|
|
catch ( ApplicationPurgedException $ex ) { |
|
42
|
|
|
$this->presenter->presentApplicationWasPurged(); |
|
43
|
|
|
return; |
|
44
|
|
|
} |
|
45
|
|
|
catch ( GetMembershipApplicationException $ex ) { |
|
46
|
|
|
$this->presenter->presentTechnicalError( 'A database error occurred' ); |
|
47
|
|
|
return; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
$this->presenter->presentConfirmation( |
|
51
|
|
|
$application, // TODO: use DTO instead of Entity (currently violates the architecture) |
|
52
|
|
|
$this->tokenFetcher->getTokens( $request->getApplicationId() )->getUpdateToken() |
|
53
|
|
|
); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
} |