Completed
Pull Request — master (#709)
by Jeroen De
138:35 queued 129:04
created

FunFunFactory::getDonationTimeframeLimit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\Fundraising\Frontend\Factories;
6
7
use Doctrine\Common\Cache\Cache;
8
use Doctrine\Common\Cache\FilesystemCache;
9
use Doctrine\Common\Cache\VoidCache;
10
use Doctrine\DBAL\Connection;
11
use Doctrine\DBAL\DriverManager;
12
use Doctrine\ORM\EntityManager;
13
use GuzzleHttp\Client;
14
use GuzzleHttp\ClientInterface;
15
use GuzzleHttp\Handler\CurlHandler;
16
use GuzzleHttp\HandlerStack;
17
use Mediawiki\Api\ApiUser;
18
use Mediawiki\Api\Guzzle\MiddlewareFactory;
19
use Mediawiki\Api\MediawikiApi;
20
use NumberFormatter;
21
use Pimple\Container;
22
use Psr\Log\LoggerInterface;
23
use Psr\Log\NullLogger;
24
use Swift_MailTransport;
25
use Swift_NullTransport;
26
use Symfony\Component\Stopwatch\Stopwatch;
27
use Symfony\Component\Translation\TranslatorInterface;
28
use TNvpServiceDispatcher;
29
use Twig_Environment;
30
use Twig_Extensions_Extension_Intl;
31
use WMDE\Fundraising\Frontend\Infrastructure\Cache\AllOfTheCachePurger;
32
use WMDE\Fundraising\Frontend\Presentation\Honorifics;
33
use WMDE\Fundraising\Frontend\UseCases\GetInTouch\GetInTouchUseCase;
34
use WMDE\Fundraising\Frontend\Infrastructure\Cache\AuthorizedCachePurger;
35
use WMDE\Fundraising\Frontend\DonationContext\Authorization\DonationAuthorizer;
36
use WMDE\Fundraising\Frontend\DonationContext\Authorization\DonationTokenFetcher;
37
use WMDE\Fundraising\Frontend\DonationContext\DataAccess\DoctrineCommentFinder;
38
use WMDE\Fundraising\Frontend\DonationContext\DataAccess\DoctrineDonationAuthorizer;
39
use WMDE\Fundraising\Frontend\DonationContext\DataAccess\DoctrineDonationEventLogger;
40
use WMDE\Fundraising\Frontend\DonationContext\DataAccess\DoctrineDonationPrePersistSubscriber;
41
use WMDE\Fundraising\Frontend\DonationContext\DataAccess\DoctrineDonationRepository;
42
use WMDE\Fundraising\Frontend\DonationContext\DataAccess\DoctrineDonationTokenFetcher;
43
use WMDE\Fundraising\Frontend\DonationContext\Domain\Repositories\CommentFinder;
44
use WMDE\Fundraising\Frontend\DonationContext\Domain\Repositories\DonationRepository;
45
use WMDE\Fundraising\Frontend\DonationContext\Infrastructure\BestEffortDonationEventLogger;
46
use WMDE\Fundraising\Frontend\DonationContext\Infrastructure\DonationConfirmationMailer;
47
use WMDE\Fundraising\Frontend\DonationContext\Infrastructure\DonationEventLogger;
48
use WMDE\Fundraising\Frontend\DonationContext\Infrastructure\LoggingCommentFinder;
49
use WMDE\Fundraising\Frontend\DonationContext\Infrastructure\LoggingDonationRepository;
50
use WMDE\Fundraising\Frontend\DonationContext\UseCases\AddComment\AddCommentUseCase;
51
use WMDE\Fundraising\Frontend\DonationContext\UseCases\AddComment\AddCommentValidator;
52
use WMDE\Fundraising\Frontend\DonationContext\UseCases\AddDonation\AddDonationPolicyValidator;
53
use WMDE\Fundraising\Frontend\DonationContext\UseCases\AddDonation\AddDonationUseCase;
54
use WMDE\Fundraising\Frontend\DonationContext\UseCases\AddDonation\AddDonationValidator;
55
use WMDE\Fundraising\Frontend\DonationContext\UseCases\AddDonation\ReferrerGeneralizer;
56
use WMDE\Fundraising\Frontend\DonationContext\UseCases\CancelDonation\CancelDonationUseCase;
57
use WMDE\Fundraising\Frontend\DonationContext\UseCases\CreditCardPaymentNotification\CreditCardNotificationUseCase;
58
use WMDE\Fundraising\Frontend\DonationContext\UseCases\HandlePayPalPaymentNotification\HandlePayPalPaymentNotificationUseCase;
59
use WMDE\Fundraising\Frontend\DonationContext\UseCases\ListComments\ListCommentsUseCase;
60
use WMDE\Fundraising\Frontend\DonationContext\UseCases\ShowDonationConfirmation\ShowDonationConfirmationUseCase;
61
use WMDE\Fundraising\Frontend\DonationContext\Validation\DonorAddressValidator;
62
use WMDE\Fundraising\Frontend\DonationContext\Validation\DonorNameValidator;
63
use WMDE\Fundraising\Frontend\DonationContext\Validation\DonorValidator;
64
use WMDE\Fundraising\Frontend\Infrastructure\InternetDomainNameValidator;
65
use WMDE\Fundraising\Frontend\Infrastructure\LoggingMailer;
66
use WMDE\Fundraising\Frontend\Infrastructure\LoggingPaymentNotificationVerifier;
67
use WMDE\Fundraising\Frontend\Infrastructure\Messenger;
68
use WMDE\Fundraising\Frontend\Infrastructure\OperatorMailer;
69
use WMDE\Fundraising\Frontend\Infrastructure\PageRetrieverBasedStringList;
70
use WMDE\Fundraising\Frontend\Infrastructure\PaymentNotificationVerifier;
71
use WMDE\Fundraising\Frontend\Infrastructure\PayPalPaymentNotificationVerifier;
72
use WMDE\Fundraising\Frontend\Infrastructure\ProfilerDataCollector;
73
use WMDE\Fundraising\Frontend\Infrastructure\ProfilingDecoratorBuilder;
74
use WMDE\Fundraising\Frontend\Infrastructure\RandomTokenGenerator;
75
use WMDE\Fundraising\Frontend\Infrastructure\TemplateBasedMailer;
76
use WMDE\Fundraising\Frontend\Infrastructure\TokenGenerator;
77
use WMDE\Fundraising\Frontend\MembershipContext\Authorization\ApplicationAuthorizer;
78
use WMDE\Fundraising\Frontend\MembershipContext\Authorization\ApplicationTokenFetcher;
79
use WMDE\Fundraising\Frontend\MembershipContext\DataAccess\DoctrineApplicationAuthorizer;
80
use WMDE\Fundraising\Frontend\MembershipContext\DataAccess\DoctrineApplicationPiwikTracker;
81
use WMDE\Fundraising\Frontend\MembershipContext\DataAccess\DoctrineApplicationRepository;
82
use WMDE\Fundraising\Frontend\MembershipContext\DataAccess\DoctrineApplicationTokenFetcher;
83
use WMDE\Fundraising\Frontend\MembershipContext\DataAccess\DoctrineApplicationTracker;
84
use WMDE\Fundraising\Frontend\MembershipContext\DataAccess\DoctrineMembershipApplicationPrePersistSubscriber;
85
use WMDE\Fundraising\Frontend\MembershipContext\Domain\Model\EmailAddress;
86
use WMDE\Fundraising\Frontend\MembershipContext\Domain\Repositories\ApplicationRepository;
87
use WMDE\Fundraising\Frontend\MembershipContext\Infrastructure\LoggingApplicationRepository;
88
use WMDE\Fundraising\Frontend\MembershipContext\Tracking\ApplicationPiwikTracker;
89
use WMDE\Fundraising\Frontend\MembershipContext\Tracking\ApplicationTracker;
90
use WMDE\Fundraising\Frontend\MembershipContext\UseCases\ApplyForMembership\ApplyForMembershipUseCase;
91
use WMDE\Fundraising\Frontend\MembershipContext\UseCases\ApplyForMembership\MembershipApplicationValidator;
92
use WMDE\Fundraising\Frontend\MembershipContext\UseCases\CancelMembershipApplication\CancelMembershipApplicationUseCase;
93
use WMDE\Fundraising\Frontend\MembershipContext\UseCases\ShowMembershipApplicationConfirmation\ShowMembershipApplicationConfirmationUseCase;
94
use WMDE\Fundraising\Frontend\PaymentContext\DataAccess\McpCreditCardService;
95
use WMDE\Fundraising\Frontend\PaymentContext\DataAccess\UniqueTransferCodeGenerator;
96
use WMDE\Fundraising\Frontend\PaymentContext\Domain\BankDataConverter;
97
use WMDE\Fundraising\Frontend\PaymentContext\Domain\SimpleTransferCodeGenerator;
98
use WMDE\Fundraising\Frontend\PaymentContext\Domain\TransferCodeGenerator;
99
use WMDE\Fundraising\Frontend\PaymentContext\Infrastructure\CreditCardService;
100
use WMDE\Fundraising\Frontend\PaymentContext\UseCases\CheckIban\CheckIbanUseCase;
101
use WMDE\Fundraising\Frontend\PaymentContext\UseCases\GenerateIban\GenerateIbanUseCase;
102
use WMDE\Fundraising\Frontend\Presentation\AmountFormatter;
103
use WMDE\Fundraising\Frontend\Presentation\CreditCardUrlConfig;
104
use WMDE\Fundraising\Frontend\Presentation\CreditCardUrlGenerator;
105
use WMDE\Fundraising\Frontend\Presentation\DonationConfirmationPageSelector;
106
use WMDE\Fundraising\Frontend\Presentation\FilePrefixer;
107
use WMDE\Fundraising\Frontend\Presentation\GreetingGenerator;
108
use WMDE\Fundraising\Frontend\Presentation\PayPalUrlConfig;
109
use WMDE\Fundraising\Frontend\Presentation\PayPalUrlGenerator;
110
use WMDE\Fundraising\Frontend\Presentation\Presenters\AddSubscriptionHtmlPresenter;
111
use WMDE\Fundraising\Frontend\Presentation\Presenters\AddSubscriptionJsonPresenter;
112
use WMDE\Fundraising\Frontend\Presentation\Presenters\CancelDonationHtmlPresenter;
113
use WMDE\Fundraising\Frontend\Presentation\Presenters\CancelMembershipApplicationHtmlPresenter;
114
use WMDE\Fundraising\Frontend\Presentation\Presenters\CommentListHtmlPresenter;
115
use WMDE\Fundraising\Frontend\Presentation\Presenters\CommentListJsonPresenter;
116
use WMDE\Fundraising\Frontend\Presentation\Presenters\CommentListRssPresenter;
117
use WMDE\Fundraising\Frontend\Presentation\Presenters\ConfirmSubscriptionHtmlPresenter;
118
use WMDE\Fundraising\Frontend\Presentation\Presenters\CreditCardNotificationPresenter;
119
use WMDE\Fundraising\Frontend\Presentation\Presenters\CreditCardPaymentHtmlPresenter;
120
use WMDE\Fundraising\Frontend\Presentation\Presenters\DonationConfirmationHtmlPresenter;
121
use WMDE\Fundraising\Frontend\Presentation\Presenters\DonationFormPresenter;
122
use WMDE\Fundraising\Frontend\Presentation\Presenters\DonationFormViolationPresenter;
123
use WMDE\Fundraising\Frontend\Presentation\Presenters\GetInTouchHtmlPresenter;
124
use WMDE\Fundraising\Frontend\Presentation\Presenters\IbanPresenter;
125
use WMDE\Fundraising\Frontend\Presentation\Presenters\InternalErrorHtmlPresenter;
126
use WMDE\Fundraising\Frontend\Presentation\Presenters\MembershipApplicationConfirmationHtmlPresenter;
127
use WMDE\Fundraising\Frontend\Presentation\Presenters\MembershipFormViolationPresenter;
128
use WMDE\Fundraising\Frontend\Presentation\TwigTemplate;
129
use WMDE\Fundraising\Frontend\SubscriptionContext\DataAccess\DoctrineSubscriptionRepository;
130
use WMDE\Fundraising\Frontend\SubscriptionContext\Domain\Repositories\SubscriptionRepository;
131
use WMDE\Fundraising\Frontend\SubscriptionContext\Infrastructure\LoggingSubscriptionRepository;
132
use WMDE\Fundraising\Frontend\SubscriptionContext\UseCases\AddSubscription\AddSubscriptionUseCase;
133
use WMDE\Fundraising\Frontend\SubscriptionContext\UseCases\ConfirmSubscription\ConfirmSubscriptionUseCase;
134
use WMDE\Fundraising\Frontend\SubscriptionContext\Validation\SubscriptionDuplicateValidator;
135
use WMDE\Fundraising\Frontend\SubscriptionContext\Validation\SubscriptionValidator;
136
use WMDE\Fundraising\Frontend\Validation\AllowedValuesValidator;
137
use WMDE\Fundraising\Frontend\Validation\AmountPolicyValidator;
138
use WMDE\Fundraising\Frontend\Validation\PaymentDataValidator;
139
use WMDE\Fundraising\Frontend\Validation\BankDataValidator;
140
use WMDE\Fundraising\Frontend\Validation\EmailValidator;
141
use WMDE\Fundraising\Frontend\Validation\GetInTouchValidator;
142
use WMDE\Fundraising\Frontend\Validation\IbanValidator;
143
use WMDE\Fundraising\Frontend\Validation\MembershipFeeValidator;
144
use WMDE\Fundraising\Frontend\Validation\TemplateNameValidator;
145
use WMDE\Fundraising\Frontend\Validation\TextPolicyValidator;
146
use WMDE\Fundraising\Store\Factory as StoreFactory;
147
use WMDE\Fundraising\Store\Installer;
148
use WMDE\PageRetriever\ApiBasedPageRetriever;
149
use WMDE\PageRetriever\CachingPageRetriever;
150
use WMDE\PageRetriever\PageRetriever;
151
152
/**
153
 * @licence GNU GPL v2+
154
 */
155
class FunFunFactory {
156
157
	private $config;
158
159
	/**
160
	 * @var Container
161
	 */
162
	private $pimple;
163
164
	private $addDoctrineSubscribers = true;
165
166
	/**
167
	 * @var Stopwatch|null
168
	 */
169
	private $profiler = null;
170
171 145
	public function __construct( array $config ) {
172 145
		$this->config = $config;
173 145
		$this->pimple = $this->newPimple();
174 145
	}
175
176 145
	private function newPimple(): Container {
177 145
		$pimple = new Container();
178
179
		$pimple['logger'] = function() {
180 108
			return new NullLogger();
181
		};
182
183
		$pimple['profiler_data_collector'] = function() {
184
			return new ProfilerDataCollector();
185
		};
186
187
		$pimple['dbal_connection'] = function() {
188 145
			return DriverManager::getConnection( $this->config['db'] );
189
		};
190
191
		$pimple['entity_manager'] = function() {
192 75
			$entityManager = ( new StoreFactory( $this->getConnection() ) )->getEntityManager();
193 75
			if ( $this->addDoctrineSubscribers ) {
194 75
				$entityManager->getEventManager()->addEventSubscriber( $this->newDoctrineDonationPrePersistSubscriber() );
195 75
				$entityManager->getEventManager()->addEventSubscriber( $this->newDoctrineMembershipApplicationPrePersistSubscriber() );
196
			}
197
198 75
			return $entityManager;
199
		};
200
201
		$pimple['subscription_repository'] = function() {
202 8
			return new LoggingSubscriptionRepository(
203 8
				new DoctrineSubscriptionRepository( $this->getEntityManager() ),
204 8
				$this->getLogger()
205
			);
206
		};
207
208
		$pimple['donation_repository'] = function() {
209 36
			return new LoggingDonationRepository(
210 36
				new DoctrineDonationRepository( $this->getEntityManager() ),
211 36
				$this->getLogger()
212
			);
213
		};
214
215
		$pimple['membership_application_repository'] = function() {
216 11
			return new LoggingApplicationRepository(
217 11
				new DoctrineApplicationRepository( $this->getEntityManager() ),
218 11
				$this->getLogger()
219
			);
220
		};
221
222
		$pimple['comment_repository'] = function() {
223 12
			$finder = new LoggingCommentFinder(
224 12
				new DoctrineCommentFinder( $this->getEntityManager() ),
225 12
				$this->getLogger()
226
			);
227
228 12
			return $this->addProfilingDecorator( $finder, 'CommentFinder' );
229
		};
230
231
		$pimple['mail_validator'] = function() {
232 38
			return new EmailValidator( new InternetDomainNameValidator() );
233
		};
234
235
		$pimple['subscription_validator'] = function() {
236 6
			return new SubscriptionValidator(
237 6
				$this->getEmailValidator(),
238 6
				$this->newTextPolicyValidator( 'fields' ),
239 6
				$this->newSubscriptionDuplicateValidator(),
240 6
				$this->newHonorificValidator()
241
			);
242
		};
243
244
		$pimple['template_name_validator'] = function() {
245 8
			return new TemplateNameValidator( $this->getTwig() );
246
		};
247
248
		$pimple['contact_validator'] = function() {
249 3
			return new GetInTouchValidator( $this->getEmailValidator() );
250
		};
251
252
		$pimple['greeting_generator'] = function() {
253 43
			return new GreetingGenerator();
254
		};
255
256
		$pimple['mw_api'] = function() {
257 86
			return new MediawikiApi(
258 86
				$this->config['cms-wiki-api-url'],
259 86
				$this->getGuzzleClient()
260
			);
261
		};
262
263
		$pimple['guzzle_client'] = function() {
264 86
			$middlewareFactory = new MiddlewareFactory();
265 86
			$middlewareFactory->setLogger( $this->getLogger() );
266
267 86
			$handlerStack = HandlerStack::create( new CurlHandler() );
268 86
			$handlerStack->push( $middlewareFactory->retry() );
269
270 86
			$guzzle = new Client( [
271 86
				'cookies' => true,
272 86
				'handler' => $handlerStack,
273
				'headers' => [ 'User-Agent' => 'WMDE Fundraising Frontend' ],
274
			] );
275
276 86
			return $this->addProfilingDecorator( $guzzle, 'Guzzle Client' );
277
		};
278
279
		$pimple['translator'] = function() {
280 98
			$translationFactory = new TranslationFactory();
281
			$loaders = [
282 98
				'json' => $translationFactory->newJsonLoader()
283
			];
284 98
			$locale = $this->config['locale'];
285 98
			$translator = $translationFactory->create( $loaders, $locale );
286 98
			$translator->addResource(
287 98
				'json',
288 98
				__DIR__ . '/../../app/translations/messages.' . $locale . '.json',
289
				$locale
290
			);
291
292 98
			$translator->addResource(
293 98
				'json',
294 98
				__DIR__ . '/../../app/translations/paymentTypes.' . $locale . '.json',
295
				$locale,
296 98
				'paymentTypes'
297
			);
298
299 98
			$translator->addResource(
300 98
				'json',
301 98
				__DIR__ . '/../../app/translations/paymentIntervals.' . $locale . '.json',
302
				$locale,
303 98
				'paymentIntervals'
304
			);
305
306 98
			$translator->addResource(
307 98
				'json',
308 98
				__DIR__ . '/../../app/translations/donationStatus.' . $locale . '.json',
309
				$locale,
310 98
				'donationStatus'
311
			);
312
313 98
			$translator->addResource(
314 98
				'json',
315 98
				__DIR__ . '/../../app/translations/validations.' . $locale . '.json',
316
				$locale,
317 98
				'validations'
318
			);
319
320 98
			return $translator;
321
		};
322
323
		// In the future, this could be locale-specific or filled from a DB table
324
		$pimple['honorifics'] = function() {
325 71
			return new Honorifics( [
326 71
				'' => 'Kein Titel',
327
				'Dr.' => 'Dr.',
328
				'Prof.' => 'Prof.',
329
				'Prof. Dr.' => 'Prof. Dr.'
330
			] );
331
		};
332
333
		$pimple['twig_factory'] = function () {
334
			// TODO: like this we end up with two Twig instance, one created here and on in the framework
335 93
			return new TwigFactory( $this->config['twig'], $this->getCachePath() . '/twig' );
336
		};
337
338
		$pimple['twig'] = function() {
339 93
			$twigFactory = $this->getTwigFactory();
340 93
			$loaders = array_filter( [
341 93
				$twigFactory->newFileSystemLoader(),
342 93
				$twigFactory->newArrayLoader(), // This is just a fallback for testing
343 93
				$twigFactory->newWikiPageLoader(
344 93
					$this->newRawWikiPageRetriever(),
345 93
					$this->newRenderedWikiPageRetriever()
346
				),
347
			] );
348
			$extensions = [
349 93
				$twigFactory->newTranslationExtension( $this->getTranslator() ),
350 93
				new Twig_Extensions_Extension_Intl()
351
			];
352
			$filters = [
353 93
				$twigFactory->newFilePrefixFilter(
354 93
					$this->newFilePrefixer()
355
				)
356
			];
357
358 93
			return $twigFactory->create( $loaders, $extensions, $filters );
359
		};
360
361
		$pimple['messenger'] = function() {
362 5
			return new Messenger(
363 5
				new Swift_MailTransport(),
364 5
				$this->getOperatorAddress(),
365 5
				$this->config['operator-displayname']
366
			);
367
		};
368
369
		$pimple['confirmation-page-selector'] = function() {
370 4
			return new DonationConfirmationPageSelector( $this->config['confirmation-pages'] );
371
		};
372
373
		// TODO split verifiers for donation and membership
374
		$pimple['paypal-payment-notification-verifier'] = function() {
375
			return new LoggingPaymentNotificationVerifier(
376
				new PayPalPaymentNotificationVerifier(
377
					new Client(),
378
					$this->config['paypal-donation']
379
				),
380
				$this->getLogger()
381
			);
382
		};
383
384
		$pimple['credit-card-api-service'] = function() {
385
			return new McpCreditCardService(
386
				new TNvpServiceDispatcher(
387
					'IMcpCreditcardService_v1_5',
388
					'https://sipg.micropayment.de/public/creditcard/v1.5/nvp/'
389
				),
390
				$this->config['creditcard']['access-key'],
391
				$this->config['creditcard']['testmode']
392
			);
393
		};
394
395
		$pimple['token_generator'] = function() {
396 58
			return new RandomTokenGenerator(
397 58
				$this->config['token-length'],
398 58
				new \DateInterval( $this->config['token-validity-timestamp'] )
399
			);
400
		};
401
402
		$pimple['page_cache'] = function() {
403 96
			return new VoidCache();
404
		};
405
406
		$pimple['rendered_page_cache'] = function() {
407 93
			return new VoidCache();
408
		};
409
410 145
		return $pimple;
411
	}
412
413 145
	public function getConnection(): Connection {
414 145
		return $this->pimple['dbal_connection'];
415
	}
416
417 75
	public function getEntityManager(): EntityManager {
418 75
		return $this->pimple['entity_manager'];
419
	}
420
421 8
	private function newDonationEventLogger(): DonationEventLogger {
422 8
		return new BestEffortDonationEventLogger(
423 8
			new DoctrineDonationEventLogger( $this->getEntityManager() ),
424 8
			$this->getLogger()
425
		);
426
	}
427
428 145
	public function newInstaller(): Installer {
429 145
		return ( new StoreFactory( $this->getConnection() ) )->newInstaller();
430
	}
431
432 12
	public function newListCommentsUseCase(): ListCommentsUseCase {
433 12
		return new ListCommentsUseCase( $this->getCommentFinder() );
434
	}
435
436 6
	public function newCommentListJsonPresenter(): CommentListJsonPresenter {
437 6
		return new CommentListJsonPresenter();
438
	}
439
440 2
	public function newCommentListRssPresenter(): CommentListRssPresenter {
441 2
		return new CommentListRssPresenter( new TwigTemplate(
442 2
			$this->getTwig(),
443 2
			'CommentList.rss.twig'
444
		) );
445
	}
446
447 4
	public function newCommentListHtmlPresenter(): CommentListHtmlPresenter {
448 4
		return new CommentListHtmlPresenter( $this->getLayoutTemplate( 'CommentList.html.twig', [ 'piwikGoals' => [ 1 ] ] ) );
449
	}
450
451 12
	private function getCommentFinder(): CommentFinder {
452 12
		return $this->pimple['comment_repository'];
453
	}
454
455 9
	public function getSubscriptionRepository(): SubscriptionRepository {
456 9
		return $this->pimple['subscription_repository'];
457
	}
458
459 1
	public function setSubscriptionRepository( SubscriptionRepository $subscriptionRepository ) {
460 1
		$this->pimple['subscription_repository'] = $subscriptionRepository;
461 1
	}
462
463 6
	private function getSubscriptionValidator(): SubscriptionValidator {
464 6
		return $this->pimple['subscription_validator'];
465
	}
466
467 38
	public function getEmailValidator(): EmailValidator {
468 38
		return $this->pimple['mail_validator'];
469
	}
470
471 8
	public function getTemplateNameValidator(): TemplateNameValidator {
472 8
		return $this->pimple['template_name_validator'];
473
	}
474
475 1
	public function newAddSubscriptionHTMLPresenter(): AddSubscriptionHtmlPresenter {
476 1
		return new AddSubscriptionHtmlPresenter( $this->getIncludeTemplate( 'Subscription_Form.twig' ), $this->getTranslator() );
477
	}
478
479 3
	public function newConfirmSubscriptionHtmlPresenter(): ConfirmSubscriptionHtmlPresenter {
480 3
		return new ConfirmSubscriptionHtmlPresenter(
481 3
			$this->getLayoutTemplate( 'ConfirmSubscription.html.twig' ),
482 3
			$this->getTranslator()
483
		);
484
	}
485
486 2
	public function newAddSubscriptionJSONPresenter(): AddSubscriptionJsonPresenter {
487 2
		return new AddSubscriptionJsonPresenter( $this->getTranslator() );
488
	}
489
490 1
	public function newGetInTouchHTMLPresenter(): GetInTouchHtmlPresenter {
491 1
		return new GetInTouchHtmlPresenter( $this->getIncludeTemplate( 'Kontaktformular.twig' ), $this->getTranslator() );
492
	}
493
494 93
	public function getTwig(): Twig_Environment {
495 93
		return $this->pimple['twig'];
496
	}
497
498
	/**
499
	 * Get a template, with the content for the layout areas filled in.
500
	 *
501
	 * @param string $templateName
502
	 * @param array $context Additional variables for the template
503
	 * @return TwigTemplate
504
	 */
505 35
	public function getLayoutTemplate( string $templateName, array $context = [] ): TwigTemplate {
506 35
		 return new TwigTemplate(
507 35
			$this->getTwig(),
508
			$templateName,
509 35
			array_merge( $this->getDefaultTwigVariables(), $context )
510
		);
511
	}
512
513
	/**
514
	 * Get a layouted template that includes another template
515
	 *
516
	 * @param string $templateName Template to include
517
	 * @return TwigTemplate
518
	 */
519 32
	private function getIncludeTemplate( string $templateName, array $context = [] ): TwigTemplate {
520 32
		return new TwigTemplate(
521 32
			$this->getTwig(),
522 32
			'IncludeInLayout.twig',
523
			array_merge(
524 32
				$this->getDefaultTwigVariables(),
525 32
				[ 'main_template' => $templateName ],
526
				$context
527
			)
528
		);
529
	}
530
531 66
	private function getDefaultTwigVariables() {
532
		return [
533 66
			'basepath' => $this->config['web-basepath'],
534 66
			'honorifics' => $this->getHonorifics()->getList(),
535 66
			'header_template' => $this->config['default-layout-templates']['header'],
536 66
			'footer_template' => $this->config['default-layout-templates']['footer'],
537 66
			'no_js_notice_template' => $this->config['default-layout-templates']['no-js-notice'],
538 66
			'piwik' => $this->config['piwik'],
539
		];
540
	}
541
542 15
	private function newReferrerGeneralizer() {
543 15
		return new ReferrerGeneralizer(
544 15
			$this->config['referrer-generalization']['default'],
545 15
			$this->config['referrer-generalization']['domain-map']
546
		);
547
	}
548
549 96
	private function getMediaWikiApi(): MediawikiApi {
550 96
		return $this->pimple['mw_api'];
551
	}
552
553 10
	public function setMediaWikiApi( MediawikiApi $api ) {
554 10
		$this->pimple['mw_api'] = $api;
555 10
	}
556
557 86
	private function getGuzzleClient(): ClientInterface {
558 86
		return $this->pimple['guzzle_client'];
559
	}
560
561 96
	private function newRawWikiPageRetriever(): PageRetriever {
562 96
		$pageRetriever = new CachingPageRetriever(
563 96
			$this->newApiRawPageRetriever(),
564 96
			$this->getPageCache()
565
		);
566
567 96
		return $this->addProfilingDecorator( $pageRetriever, 'PageRetriever' );
568
	}
569
570 93
	private function newRenderedWikiPageRetriever(): PageRetriever {
571 93
		$pageRetriever = new CachingPageRetriever(
572 93
			$this->newApiRenderedPageRetriever(),
573 93
			$this->getRenderedPageCache()
574
		);
575
576 93
		return $this->addProfilingDecorator( $pageRetriever, 'PageRetriever' );
577
	}
578
579 96
	private function newApiRawPageRetriever(): PageRetriever {
580 96
		return new ApiBasedPageRetriever(
581 96
			$this->getMediaWikiApi(),
582 96
			new ApiUser( $this->config['cms-wiki-user'], $this->config['cms-wiki-password'] ),
583 96
			$this->getLogger(),
584 96
			$this->config['cms-wiki-title-prefix'],
585 96
			ApiBasedPageRetriever::MODE_RAW
586
		);
587
	}
588
589 93
	private function newApiRenderedPageRetriever(): PageRetriever {
590 93
		return new ApiBasedPageRetriever(
591 93
			$this->getMediaWikiApi(),
592 93
			new ApiUser( $this->config['cms-wiki-user'], $this->config['cms-wiki-password'] ),
593 93
			$this->getLogger(),
594 93
			$this->config['cms-wiki-title-prefix'],
595 93
			ApiBasedPageRetriever::MODE_RENDERED
596
		);
597
	}
598
599 108
	public function getLogger(): LoggerInterface {
600 108
		return $this->pimple['logger'];
601
	}
602
603 93
	private function getVarPath(): string {
604 93
		return __DIR__ . '/../../var';
605
	}
606
607 93
	public function getCachePath(): string {
608 93
		return $this->getVarPath() . '/cache';
609
	}
610
611
	public function getLoggingPath(): string {
612
		return $this->getVarPath() . '/log';
613
	}
614
615
	public function getTemplatePath(): string {
616
		return __DIR__ . '/../../app/templates';
617
	}
618
619 6
	public function newAddSubscriptionUseCase(): AddSubscriptionUseCase {
620 6
		return new AddSubscriptionUseCase(
621 6
			$this->getSubscriptionRepository(),
622 6
			$this->getSubscriptionValidator(),
623 6
			$this->newAddSubscriptionMailer()
624
		);
625
	}
626
627 3
	public function newConfirmSubscriptionUseCase(): ConfirmSubscriptionUseCase {
628 3
		return new ConfirmSubscriptionUseCase(
629 3
			$this->getSubscriptionRepository(),
630 3
			$this->newConfirmSubscriptionMailer()
631
		);
632
	}
633
634 6
	private function newAddSubscriptionMailer(): TemplateBasedMailer {
635 6
		return $this->newTemplateMailer(
636 6
			new TwigTemplate(
637 6
				$this->getTwig(),
638 6
				'Mail_Subscription_Request.twig',
639
				[
640 6
					'basepath' => $this->config['web-basepath'],
641 6
					'greeting_generator' => $this->getGreetingGenerator()
642
				]
643
			),
644 6
			'mail_subject_membership'
645
		);
646
	}
647
648 3
	private function newConfirmSubscriptionMailer(): TemplateBasedMailer {
649 3
		return $this->newTemplateMailer(
650 3
			new TwigTemplate(
651 3
					$this->getTwig(),
652 3
					'Mail_Subscription_Confirmation.twig',
653 3
					[ 'greeting_generator' => $this->getGreetingGenerator() ]
654
			),
655 3
			'mail_subject_membership'
656
		);
657
	}
658
659 46
	private function newTemplateMailer( TwigTemplate $template, string $messageKey ): TemplateBasedMailer {
660 46
		$mailer = new TemplateBasedMailer(
661 46
			$this->getMessenger(),
662
			$template,
663 46
			$this->getTranslator()->trans( $messageKey )
664
		);
665
666 46
		$mailer = new LoggingMailer( $mailer, $this->getLogger() );
667
668 46
		return $this->addProfilingDecorator( $mailer, 'Mailer' );
669
	}
670
671 43
	public function getGreetingGenerator() {
672 43
		return $this->pimple['greeting_generator'];
673
	}
674
675
	public function newCheckIbanUseCase(): CheckIbanUseCase {
676
		return new CheckIbanUseCase( $this->newBankDataConverter(), $this->newIbanValidator() );
677
	}
678
679
	public function newGenerateIbanUseCase(): GenerateIbanUseCase {
680
		return new GenerateIbanUseCase( $this->newBankDataConverter(), $this->newIbanValidator() );
681
	}
682
683
	public function newIbanPresenter(): IbanPresenter {
684
		return new IbanPresenter();
685
	}
686
687 24
	public function newBankDataConverter() {
688 24
		return new BankDataConverter( $this->config['bank-data-file'] );
689
	}
690
691
	public function setSubscriptionValidator( SubscriptionValidator $subscriptionValidator ) {
692
		$this->pimple['subscription_validator'] = $subscriptionValidator;
693
	}
694
695
	public function setPageTitlePrefix( string $prefix ) {
696
		$this->config['cms-wiki-title-prefix'] = $prefix;
697
	}
698
699 3
	public function newGetInTouchUseCase() {
700 3
		return new GetInTouchUseCase(
701 3
			$this->getContactValidator(),
702 3
			$this->newContactOperatorMailer(),
703 3
			$this->newContactUserMailer()
704
		);
705
	}
706
707 3
	private function newContactUserMailer(): TemplateBasedMailer {
708 3
		return $this->newTemplateMailer(
709 3
			new TwigTemplate( $this->getTwig(), 'KontaktMailExtern.twig' ),
710 3
			'mail_subject_getintouch'
711
		);
712
	}
713
714 3
	private function newContactOperatorMailer(): OperatorMailer {
715 3
		return new OperatorMailer(
716 3
			$this->getMessenger(),
717 3
			new TwigTemplate( $this->getTwig(), 'KontaktMailIntern.twig' ),
718 3
			$this->getTranslator()->trans( 'mail_subject_getintouch_forward' )
719
		);
720
	}
721
722 3
	private function getContactValidator(): GetInTouchValidator {
723 3
		return $this->pimple['contact_validator'];
724
	}
725
726 6
	private function newSubscriptionDuplicateValidator(): SubscriptionDuplicateValidator {
727 6
		return new SubscriptionDuplicateValidator(
728 6
				$this->getSubscriptionRepository(),
729 6
				$this->newSubscriptionDuplicateCutoffDate()
730
		);
731
	}
732
733 6
	private function newSubscriptionDuplicateCutoffDate(): \DateTime {
734 6
		$cutoffDateTime = new \DateTime();
735 6
		$cutoffDateTime->sub( new \DateInterval( $this->config['subscription-interval'] ) );
736 6
		return $cutoffDateTime;
737
	}
738
739 6
	private function newHonorificValidator(): AllowedValuesValidator {
740 6
		return new AllowedValuesValidator( $this->getHonorifics()->getKeys() );
741
	}
742
743 71
	private function getHonorifics(): Honorifics {
744 71
		return $this->pimple['honorifics'];
745
	}
746
747 1
	public function newAuthorizedCachePurger(): AuthorizedCachePurger {
748 1
		return new AuthorizedCachePurger(
749 1
			new AllOfTheCachePurger( $this->getTwig(), $this->getPageCache() ),
750 1
			$this->config['purging-secret']
751
		);
752
	}
753
754 24
	private function newBankDataValidator(): BankDataValidator {
755 24
		return new BankDataValidator( $this->newIbanValidator() );
756
	}
757
758 46
	private function getMessenger(): Messenger {
759 46
		return $this->pimple['messenger'];
760
	}
761
762 44
	public function setMessenger( Messenger $messenger ) {
763 44
		$this->pimple['messenger'] = $messenger;
764 44
	}
765
766 43
	public function setNullMessenger() {
767 43
		$this->setMessenger( new Messenger(
768 43
			Swift_NullTransport::newInstance(),
769 43
			$this->getOperatorAddress()
770
		) );
771 43
	}
772
773 48
	public function getOperatorAddress() {
774 48
		return new EmailAddress( $this->config['operator-email'] );
775
	}
776
777 9
	public function newInternalErrorHTMLPresenter(): InternalErrorHtmlPresenter {
778 9
		return new InternalErrorHtmlPresenter( $this->getIncludeTemplate( 'ErrorPage.twig' ) );
779
	}
780
781 3
	public function newAccessDeniedHTMLPresenter(): InternalErrorHtmlPresenter {
782 3
		return new InternalErrorHtmlPresenter( $this->getLayoutTemplate( 'AccessDenied.twig' ) );
783
	}
784
785 100
	public function getTranslator(): TranslatorInterface {
786 100
		return $this->pimple['translator'];
787
	}
788
789 2
	public function setTranslator( TranslatorInterface $translator ) {
790 2
		$this->pimple['translator'] = $translator;
791 2
	}
792
793 93
	private function getTwigFactory(): TwigFactory {
794 93
		return $this->pimple['twig_factory'];
795
	}
796
797 24
	private function newTextPolicyValidator( string $policyName ): TextPolicyValidator {
798 24
		$contentProvider = $this->newRawWikiPageRetriever();
799 24
		$textPolicyConfig = $this->config['text-policies'][$policyName];
800
801 24
		return new TextPolicyValidator(
802 24
			new PageRetrieverBasedStringList( $contentProvider, $textPolicyConfig['badwords'] ?? '' ),
803 24
			new PageRetrieverBasedStringList( $contentProvider, $textPolicyConfig['whitewords'] ?? '' )
804
		);
805
	}
806
807 3
	private function newCommentPolicyValidator(): TextPolicyValidator {
808 3
		return $this->newTextPolicyValidator( 'comment' );
809
	}
810
811 5
	public function newCancelDonationUseCase( string $updateToken ): CancelDonationUseCase {
812 5
		return new CancelDonationUseCase(
813 5
			$this->getDonationRepository(),
814 5
			$this->newCancelDonationMailer(),
815 5
			$this->newDonationAuthorizer( $updateToken ),
816 5
			$this->newDonationEventLogger()
817
		);
818
	}
819
820 5
	private function newCancelDonationMailer(): TemplateBasedMailer {
821 5
		return $this->newTemplateMailer(
822 5
			new TwigTemplate(
823 5
				$this->getTwig(),
824 5
				'Mail_Donation_Cancellation_Confirmation.twig',
825 5
				[ 'greeting_generator' => $this->getGreetingGenerator() ]
826
			),
827 5
			'mail_subject_confirm_cancellation'
828
		);
829
	}
830
831 15
	public function newAddDonationUseCase(): AddDonationUseCase {
832 15
		return new AddDonationUseCase(
833 15
			$this->getDonationRepository(),
834 15
			$this->newDonationValidator(),
835 15
			$this->newDonationPolicyValidator(),
836 15
			$this->newReferrerGeneralizer(),
837 15
			$this->newDonationConfirmationMailer(),
838 15
			$this->newBankTransferCodeGenerator(),
839 15
			$this->newDonationTokenFetcher()
840
		);
841
	}
842
843 15
	private function newBankTransferCodeGenerator(): TransferCodeGenerator {
844 15
		return new UniqueTransferCodeGenerator(
845 15
			new SimpleTransferCodeGenerator(),
846 15
			$this->getEntityManager()
847
		);
848
	}
849
850 15
	private function newDonationValidator(): AddDonationValidator {
851 15
		return new AddDonationValidator(
852 15
			$this->newPaymentDataValidator(),
853 15
			$this->newBankDataValidator(),
854 15
			$this->getEmailValidator()
855
		);
856
	}
857
858 2
	public function newPersonalInfoValidator(): DonorValidator {
859 2
		return new DonorValidator(
860 2
			new DonorNameValidator(),
861 2
			new DonorAddressValidator(),
862 2
			$this->getEmailValidator()
863
		);
864
	}
865
866 18
	private function newDonationConfirmationMailer(): DonationConfirmationMailer {
867 18
		return new DonationConfirmationMailer(
868 18
			$this->newTemplateMailer(
869 18
				new TwigTemplate(
870 18
					$this->getTwig(),
871 18
					'Mail_Donation_Confirmation.twig', // TODO: ongoing unification of different templates
872
					[
873 18
						'basepath' => $this->config['web-basepath'],
874 18
						'greeting_generator' => $this->getGreetingGenerator()
875
					]
876
				),
877 18
				'mail_subject_confirm_donation'
878
			)
879
		);
880
	}
881
882 1
	public function newPayPalUrlGeneratorForDonations() {
883 1
		return new PayPalUrlGenerator( $this->getPayPalUrlConfigForDonations() );
884
	}
885
886
	public function newPayPalUrlGeneratorForMembershipApplications() {
887
		return new PayPalUrlGenerator( $this->getPayPalUrlConfigForMembershipApplications() );
888
	}
889
890 1
	private function getPayPalUrlConfigForDonations() {
891 1
		return PayPalUrlConfig::newFromConfig( $this->config['paypal-donation'] );
892
	}
893
894
	private function getPayPalUrlConfigForMembershipApplications() {
895
		return PayPalUrlConfig::newFromConfig( $this->config['paypal-membership-application'] );
896
	}
897
898 2
	private function newCreditCardUrlGenerator() {
899 2
		return new CreditCardUrlGenerator( $this->newCreditCardUrlConfig() );
900
	}
901
902 2
	private function newCreditCardUrlConfig() {
903 2
		return CreditCardUrlConfig::newFromConfig( $this->config['creditcard'] );
904
	}
905
906 36
	public function getDonationRepository(): DonationRepository {
907 36
		return $this->pimple['donation_repository'];
908
	}
909
910 30
	public function newPaymentDataValidator(): PaymentDataValidator {
911 30
		return new PaymentDataValidator( $this->config['donation-minimum-amount'], $this->config['donation-maximum-amount'] );
912
	}
913
914 17
	private function newAmountFormatter(): AmountFormatter {
915 17
		return new AmountFormatter( $this->config['locale'] );
916
	}
917
918 2
	public function newDecimalNumberFormatter(): NumberFormatter {
919 2
		return new NumberFormatter( $this->config['locale'], NumberFormatter::DECIMAL );
920
	}
921
922 3
	public function newAddCommentUseCase( string $updateToken ): AddCommentUseCase {
923 3
		return new AddCommentUseCase(
924 3
			$this->getDonationRepository(),
925 3
			$this->newDonationAuthorizer( $updateToken ),
926 3
			$this->newCommentPolicyValidator(),
927 3
			$this->newAddCommentValidator()
928
		);
929
	}
930
931 22
	private function newDonationAuthorizer( string $updateToken = null, string $accessToken = null ): DonationAuthorizer {
932 22
		return new DoctrineDonationAuthorizer(
933 22
			$this->getEntityManager(),
934
			$updateToken,
935
			$accessToken
936
		);
937
	}
938
939 75
	public function getTokenGenerator(): TokenGenerator {
940 75
		return $this->pimple['token_generator'];
941
	}
942
943 8
	public function newDonationConfirmationPresenter() {
944 8
		return new DonationConfirmationHtmlPresenter(
945 8
			$this->getIncludeTemplate( 'DonationConfirmation.twig', [ 'piwikGoals' => [ 3 ] ] )
946
		);
947
	}
948
949 2
	public function newCreditCardPaymentHtmlPresenter() {
950 2
		return new CreditCardPaymentHtmlPresenter(
951 2
			$this->getIncludeTemplate( 'CreditCardPaymentIframe.twig' ),
952 2
			$this->getTranslator(),
953 2
			$this->newCreditCardUrlGenerator()
954
		);
955
	}
956
957 5
	public function newCancelDonationHtmlPresenter() {
958 5
		return new CancelDonationHtmlPresenter(
959 5
			$this->getIncludeTemplate( 'Donation_Cancellation_Confirmation.twig' )
960
		);
961
	}
962
963 9
	public function newApplyForMembershipUseCase(): ApplyForMembershipUseCase {
964 9
		return new ApplyForMembershipUseCase(
965 9
			$this->getMembershipApplicationRepository(),
966 9
			$this->newMembershipApplicationTokenFetcher(),
967 9
			$this->newApplyForMembershipMailer(),
968 9
			$this->newMembershipApplicationValidator(),
969 9
			$this->newMembershipApplicationTracker(),
970 9
			$this->newMembershipApplicationPiwikTracker()
971
		);
972
	}
973
974 9
	private function newApplyForMembershipMailer(): TemplateBasedMailer {
975 9
		return $this->newTemplateMailer(
976 9
			new TwigTemplate(
977 9
				$this->getTwig(),
978 9
				'Mail_Membership_Application_Confirmation.twig',
979 9
				[ 'greeting_generator' => $this->getGreetingGenerator() ]
980
			),
981 9
			'mail_subject_confirm_membership_application'
982
		);
983
	}
984
985 9
	private function newMembershipApplicationValidator(): MembershipApplicationValidator {
986 9
		return new MembershipApplicationValidator(
987 9
			new MembershipFeeValidator(),
988 9
			$this->newBankDataValidator(),
989 9
			$this->getEmailValidator()
990
		);
991
	}
992
993 9
	private function newMembershipApplicationTracker(): ApplicationTracker {
994 9
		return new DoctrineApplicationTracker( $this->getEntityManager() );
995
	}
996
997 9
	private function newMembershipApplicationPiwikTracker(): ApplicationPiwikTracker {
998 9
		return new DoctrineApplicationPiwikTracker( $this->getEntityManager() );
999
	}
1000
1001 2
	public function newCancelMembershipApplicationUseCase( string $updateToken ): CancelMembershipApplicationUseCase {
1002 2
		return new CancelMembershipApplicationUseCase(
1003 2
			$this->newMembershipApplicationAuthorizer( $updateToken ),
1004 2
			$this->getMembershipApplicationRepository(),
1005 2
			$this->newCancelMembershipApplicationMailer()
1006
		);
1007
	}
1008
1009 2
	private function newMembershipApplicationAuthorizer(
1010
		string $updateToken = null, string $accessToken = null ): ApplicationAuthorizer {
1011
1012 2
		return new DoctrineApplicationAuthorizer(
1013 2
			$this->getEntityManager(),
1014
			$updateToken,
1015
			$accessToken
1016
		);
1017
	}
1018
1019 11
	public function getMembershipApplicationRepository(): ApplicationRepository {
1020 11
		return $this->pimple['membership_application_repository'];
1021
	}
1022
1023 2
	private function newCancelMembershipApplicationMailer(): TemplateBasedMailer {
1024 2
		return $this->newTemplateMailer(
1025 2
			new TwigTemplate(
1026 2
				$this->getTwig(),
1027 2
				'Mail_Membership_Application_Cancellation_Confirmation.twig',
1028 2
				[ 'greeting_generator' => $this->getGreetingGenerator() ]
1029
			),
1030 2
			'mail_subject_confirm_membership_application_cancellation'
1031
		);
1032
	}
1033
1034
	public function newMembershipApplicationConfirmationUseCase( string $accessToken ) {
1035
		return new ShowMembershipApplicationConfirmationUseCase(
1036
			$this->newMembershipApplicationAuthorizer( null, $accessToken ), $this->getMembershipApplicationRepository(),
1037
			$this->newMembershipApplicationTokenFetcher()
1038
		);
1039
	}
1040
1041 11
	public function newShowDonationConfirmationUseCase( string $accessToken ): ShowDonationConfirmationUseCase {
1042 11
		return new ShowDonationConfirmationUseCase(
1043 11
			$this->newDonationAuthorizer( null, $accessToken ),
1044 11
			$this->newDonationTokenFetcher(),
1045 11
			$this->getDonationRepository()
1046
		);
1047
	}
1048
1049 7
	public function setDonationConfirmationPageSelector( DonationConfirmationPageSelector $selector ) {
1050 7
		$this->pimple['confirmation-page-selector'] = $selector;
1051 7
	}
1052
1053 8
	public function getDonationConfirmationPageSelector() {
1054 8
		return $this->pimple['confirmation-page-selector'];
1055
	}
1056
1057 3
	public function newDonationFormViolationPresenter() {
1058
		// TODO make the template name dependent on the 'form' value from the HTTP POST request
1059
		// (we need different form pages for A/B testing)
1060 3
		$template = $this->getLayoutTemplate( 'DisplayPageLayout.twig', [ 'main_template' => 'DonationForm.twig' ] );
1061 3
		return new DonationFormViolationPresenter( $template, $this->newAmountFormatter() );
1062
	}
1063
1064 14
	public function newDonationFormPresenter() {
1065
		// TODO make the template name dependent on the 'form' value from the HTTP POST request
1066
		// (we need different form pages for A/B testing)
1067 14
		$template = $this->getLayoutTemplate( 'DisplayPageLayout.twig', [ 'main_template' => 'DonationForm.twig' ] );
1068 14
		return new DonationFormPresenter( $template, $this->newAmountFormatter() );
1069
	}
1070
1071 1
	public function newHandlePayPalPaymentNotificationUseCase( string $updateToken ) {
1072 1
		return new HandlePayPalPaymentNotificationUseCase(
1073 1
			$this->getDonationRepository(),
1074 1
			$this->newDonationAuthorizer( $updateToken ),
1075 1
			$this->newDonationConfirmationMailer(),
1076 1
			$this->getLogger(),
1077 1
			$this->newDonationEventLogger()
1078
		);
1079
	}
1080
1081 5
	public function getPayPalPaymentNotificationVerifier(): PaymentNotificationVerifier {
1082 5
		return $this->pimple['paypal-payment-notification-verifier'];
1083
	}
1084
1085 5
	public function setPayPalPaymentNotificationVerifier( PaymentNotificationVerifier $verifier ) {
1086 5
		$this->pimple['paypal-payment-notification-verifier'] = $verifier;
1087 5
	}
1088
1089 2
	public function newCreditCardNotificationUseCase( string $updateToken ) {
1090 2
		return new CreditCardNotificationUseCase(
1091 2
			$this->getDonationRepository(),
1092 2
			$this->newDonationAuthorizer( $updateToken ),
1093 2
			$this->getCreditCardService(),
1094 2
			$this->newDonationConfirmationMailer(),
1095 2
			$this->getLogger(),
1096 2
			$this->newDonationEventLogger()
1097
		);
1098
	}
1099
1100 2
	public function newCancelMembershipApplicationHtmlPresenter() {
1101 2
		return new CancelMembershipApplicationHtmlPresenter(
1102 2
			$this->getIncludeTemplate( 'Membership_Application_Cancellation_Confirmation.twig' )
1103
		);
1104
	}
1105
1106
	public function newMembershipApplicationConfirmationHtmlPresenter() {
1107
		return new MembershipApplicationConfirmationHtmlPresenter(
1108
			$this->getIncludeTemplate( 'MembershipApplicationConfirmation.twig' )
1109
		);
1110
	}
1111
1112 2
	public function newMembershipFormViolationPresenter() {
1113 2
		return new MembershipFormViolationPresenter(
1114 2
			$this->getIncludeTemplate( 'MembershipApplication.twig' )
1115
		);
1116
	}
1117
1118 2
	public function setCreditCardService( CreditCardService $ccService ) {
1119 2
		$this->pimple['credit-card-api-service'] = $ccService;
1120 2
	}
1121
1122 2
	public function getCreditCardService(): CreditCardService {
1123 2
		return $this->pimple['credit-card-api-service'];
1124
	}
1125
1126 2
	public function newCreditCardNotificationPresenter(): CreditCardNotificationPresenter {
1127 2
		return new CreditCardNotificationPresenter(
1128 2
			new TwigTemplate(
1129 2
				$this->getTwig(),
1130 2
				'CreditCardPaymentNotification.twig',
1131 2
				[ 'returnUrl' => $this->config['creditcard']['return-url'] ]
1132
			)
1133
		);
1134
	}
1135
1136 75
	private function newDoctrineDonationPrePersistSubscriber(): DoctrineDonationPrePersistSubscriber {
1137 75
		$tokenGenerator = $this->getTokenGenerator();
1138 75
		return new DoctrineDonationPrePersistSubscriber(
1139
			$tokenGenerator,
1140
			$tokenGenerator
1141
		);
1142
	}
1143
1144 75
	private function newDoctrineMembershipApplicationPrePersistSubscriber(): DoctrineMembershipApplicationPrePersistSubscriber {
1145 75
		$tokenGenerator = $this->getTokenGenerator();
1146 75
		return new DoctrineMembershipApplicationPrePersistSubscriber(
1147
			$tokenGenerator,
1148
			$tokenGenerator
1149
		);
1150
	}
1151
1152 17
	public function setTokenGenerator( TokenGenerator $tokenGenerator ) {
1153 17
		$this->pimple['token_generator'] = $tokenGenerator;
1154 17
	}
1155
1156
	public function disableDoctrineSubscribers() {
1157
		$this->addDoctrineSubscribers = false;
1158
	}
1159
1160 24
	private function newDonationTokenFetcher(): DonationTokenFetcher {
1161 24
		return new DoctrineDonationTokenFetcher(
1162 24
			$this->getEntityManager()
1163
		);
1164
	}
1165
1166 9
	private function newMembershipApplicationTokenFetcher(): ApplicationTokenFetcher {
1167 9
		return new DoctrineApplicationTokenFetcher(
1168 9
			$this->getEntityManager()
1169
		);
1170
	}
1171
1172 15
	private function newDonationPolicyValidator(): AddDonationPolicyValidator {
1173 15
		return new AddDonationPolicyValidator(
1174 15
			$this->newDonationAmountPolicyValidator(),
1175 15
			$this->newTextPolicyValidator( 'fields' )
1176
		);
1177
	}
1178
1179 15
	private function newDonationAmountPolicyValidator(): AmountPolicyValidator {
1180
		// in the future, this might come from the configuration
1181 15
		return new AmountPolicyValidator( 1000, 1000 );
1182
	}
1183
1184 2
	public function getDonationTimeframeLimit() {
1185 2
		return $this->config['donation-timeframe-limit'];
1186
	}
1187
1188 2
	public function newSystemMessageResponse( string $message ) {
1189 2
		$test = $this->getIncludeTemplate( 'System_Message.twig' );
1190 2
		return $test->render( [ 'message' => $message ] );
1191
	}
1192
1193 2
	public function getMembershipApplicationTimeframeLimit() {
1194 2
		return $this->config['membership-application-timeframe-limit'];
1195
	}
1196
1197 3
	private function newAddCommentValidator(): AddCommentValidator {
1198 3
		return new AddCommentValidator();
1199
	}
1200
1201 96
	private function getPageCache(): Cache {
1202 96
		return $this->pimple['page_cache'];
1203
	}
1204
1205 93
	private function getRenderedPageCache(): Cache {
1206 93
		return $this->pimple['rendered_page_cache'];
1207
	}
1208
1209
	public function enablePageCache() {
1210
		$this->pimple['page_cache'] = function() {
1211
			return new FilesystemCache( $this->getCachePath() . '/pages/raw' );
1212
		};
1213
1214
		$this->pimple['rendered_page_cache'] = function() {
1215
			return new FilesystemCache( $this->getCachePath() . '/pages/rendered' );
1216
		};
1217
	}
1218
1219 102
	private function addProfilingDecorator( $objectToDecorate, string $profilingLabel ) {
1220 102
		if ( $this->profiler === null ) {
1221 102
			return $objectToDecorate;
1222
		}
1223
1224
		$builder = new ProfilingDecoratorBuilder( $this->profiler, $this->getProfilerDataCollector() );
1225
1226
		return $builder->decorate( $objectToDecorate, $profilingLabel );
1227
	}
1228
1229
	public function setProfiler( Stopwatch $profiler ) {
1230
		$this->profiler = $profiler;
1231
	}
1232
1233
	public function setLogger( LoggerInterface $logger ) {
1234
		$this->pimple['logger'] = $logger;
1235
	}
1236
1237
	public function getProfilerDataCollector(): ProfilerDataCollector {
1238
		return $this->pimple['profiler_data_collector'];
1239
	}
1240
1241 24
	private function newIbanValidator(): IbanValidator {
1242 24
		return new IbanValidator( $this->newBankDataConverter(), $this->config['banned-ibans'] );
1243
	}
1244
1245 93
	private function newFilePrefixer(): FilePrefixer {
1246 93
		return new FilePrefixer( $this->getFilePrefix() );
1247
	}
1248
1249 93
	private function getFilePrefix(): string {
1250 93
		$prefixContentFile = $this->getVarPath() . '/file_prefix.txt';
1251 93
		if ( !file_exists( $prefixContentFile ) ) {
1252 93
			return '';
1253
		}
1254
		return $prefix = preg_replace( '/[^0-9a-f]/', '', file_get_contents( $prefixContentFile ) );
0 ignored issues
show
Unused Code introduced by
$prefix is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1255
	}
1256
1257
}
1258