Completed
Pull Request — master (#580)
by Jeroen De
04:50
created

FunFunFactory::disableDoctrineSubscribers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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 Psr\Log\LoggerInterface;
22
use Psr\Log\NullLogger;
23
use Swift_MailTransport;
24
use Swift_NullTransport;
25
use Symfony\Component\Stopwatch\Stopwatch;
26
use Symfony\Component\Translation\TranslatorInterface;
27
use TNvpServiceDispatcher;
28
use Twig_Environment;
29
use Twig_Extensions_Extension_Intl;
30
use WMDE\Fundraising\Frontend\DataAccess\ApiBasedPageRetriever;
31
use WMDE\Fundraising\Frontend\DataAccess\DoctrineCommentFinder;
32
use WMDE\Fundraising\Frontend\DataAccess\DoctrineDonationAuthorizer;
33
use WMDE\Fundraising\Frontend\DataAccess\DoctrineDonationEventLogger;
34
use WMDE\Fundraising\Frontend\DataAccess\DoctrineDonationPrePersistSubscriber;
35
use WMDE\Fundraising\Frontend\DataAccess\DoctrineDonationRepository;
36
use WMDE\Fundraising\Frontend\DataAccess\DoctrineDonationTokenFetcher;
37
use WMDE\Fundraising\Frontend\DataAccess\DoctrineMembershipApplicationAuthorizer;
38
use WMDE\Fundraising\Frontend\DataAccess\DoctrineMembershipApplicationPiwikTracker;
39
use WMDE\Fundraising\Frontend\DataAccess\DoctrineMembershipApplicationPrePersistSubscriber;
40
use WMDE\Fundraising\Frontend\DataAccess\DoctrineMembershipApplicationRepository;
41
use WMDE\Fundraising\Frontend\DataAccess\DoctrineMembershipApplicationTokenFetcher;
42
use WMDE\Fundraising\Frontend\DataAccess\DoctrineMembershipApplicationTracker;
43
use WMDE\Fundraising\Frontend\DataAccess\DoctrineSubscriptionRepository;
44
use WMDE\Fundraising\Frontend\DataAccess\InternetDomainNameValidator;
45
use WMDE\Fundraising\Frontend\DataAccess\McpCreditCardService;
46
use WMDE\Fundraising\Frontend\DataAccess\UniqueTransferCodeGenerator;
47
use WMDE\Fundraising\Frontend\Domain\BankDataConverter;
48
use WMDE\Fundraising\Frontend\Domain\CommentFinder;
49
use WMDE\Fundraising\Frontend\Domain\Model\EmailAddress;
50
use WMDE\Fundraising\Frontend\Domain\ReferrerGeneralizer;
51
use WMDE\Fundraising\Frontend\Domain\Repositories\DonationRepository;
52
use WMDE\Fundraising\Frontend\Domain\Repositories\MembershipApplicationRepository;
53
use WMDE\Fundraising\Frontend\Domain\Repositories\SubscriptionRepository;
54
use WMDE\Fundraising\Frontend\Domain\SimpleTransferCodeGenerator;
55
use WMDE\Fundraising\Frontend\Domain\TransferCodeGenerator;
56
use WMDE\Fundraising\Frontend\Infrastructure\BestEffortDonationEventLogger;
57
use WMDE\Fundraising\Frontend\Infrastructure\CachingPageRetriever;
58
use WMDE\Fundraising\Frontend\Infrastructure\CreditCardService;
59
use WMDE\Fundraising\Frontend\Infrastructure\DonationAuthorizer;
60
use WMDE\Fundraising\Frontend\Infrastructure\DonationConfirmationMailer;
61
use WMDE\Fundraising\Frontend\Infrastructure\DonationEventLogger;
62
use WMDE\Fundraising\Frontend\Infrastructure\DonationTokenFetcher;
63
use WMDE\Fundraising\Frontend\Infrastructure\Honorifics;
64
use WMDE\Fundraising\Frontend\Infrastructure\LoggingMailer;
65
use WMDE\Fundraising\Frontend\Infrastructure\LoggingPaymentNotificationVerifier;
66
use WMDE\Fundraising\Frontend\Infrastructure\MembershipApplicationAuthorizer;
67
use WMDE\Fundraising\Frontend\Infrastructure\MembershipApplicationPiwikTracker;
68
use WMDE\Fundraising\Frontend\Infrastructure\MembershipApplicationTokenFetcher;
69
use WMDE\Fundraising\Frontend\Infrastructure\MembershipApplicationTracker;
70
use WMDE\Fundraising\Frontend\Infrastructure\Messenger;
71
use WMDE\Fundraising\Frontend\Infrastructure\PageRetriever;
72
use WMDE\Fundraising\Frontend\Infrastructure\PageRetrieverBasedStringList;
73
use WMDE\Fundraising\Frontend\Infrastructure\PaymentNotificationVerifier;
74
use WMDE\Fundraising\Frontend\Infrastructure\PayPalPaymentNotificationVerifier;
75
use WMDE\Fundraising\Frontend\Infrastructure\ProfilingDecoratorBuilder;
76
use WMDE\Fundraising\Frontend\Infrastructure\RandomTokenGenerator;
77
use WMDE\Fundraising\Frontend\Infrastructure\Repositories\LoggingCommentFinder;
78
use WMDE\Fundraising\Frontend\Infrastructure\Repositories\LoggingDonationRepository;
79
use WMDE\Fundraising\Frontend\Infrastructure\Repositories\LoggingMembershipApplicationRepository;
80
use WMDE\Fundraising\Frontend\Infrastructure\Repositories\LoggingSubscriptionRepository;
81
use WMDE\Fundraising\Frontend\Infrastructure\TemplateBasedMailer;
82
use WMDE\Fundraising\Frontend\Infrastructure\TokenGenerator;
83
use WMDE\Fundraising\Frontend\Infrastructure\AllOfTheCachePurger;
84
use WMDE\Fundraising\Frontend\Presentation\AmountFormatter;
85
use WMDE\Fundraising\Frontend\Presentation\Content\PageContentModifier;
86
use WMDE\Fundraising\Frontend\Infrastructure\ModifyingPageRetriever;
87
use WMDE\Fundraising\Frontend\Presentation\CreditCardUrlConfig;
88
use WMDE\Fundraising\Frontend\Presentation\CreditCardUrlGenerator;
89
use WMDE\Fundraising\Frontend\Presentation\DonationConfirmationPageSelector;
90
use WMDE\Fundraising\Frontend\Presentation\GreetingGenerator;
91
use WMDE\Fundraising\Frontend\Presentation\PayPalUrlConfig;
92
use WMDE\Fundraising\Frontend\Presentation\PayPalUrlGenerator;
93
use WMDE\Fundraising\Frontend\Presentation\Presenters\AddSubscriptionHtmlPresenter;
94
use WMDE\Fundraising\Frontend\Presentation\Presenters\AddSubscriptionJsonPresenter;
95
use WMDE\Fundraising\Frontend\Presentation\Presenters\CancelDonationHtmlPresenter;
96
use WMDE\Fundraising\Frontend\Presentation\Presenters\CancelMembershipApplicationHtmlPresenter;
97
use WMDE\Fundraising\Frontend\Presentation\Presenters\CommentListHtmlPresenter;
98
use WMDE\Fundraising\Frontend\Presentation\Presenters\CommentListJsonPresenter;
99
use WMDE\Fundraising\Frontend\Presentation\Presenters\CommentListRssPresenter;
100
use WMDE\Fundraising\Frontend\Presentation\Presenters\ConfirmSubscriptionHtmlPresenter;
101
use WMDE\Fundraising\Frontend\Presentation\Presenters\CreditCardNotificationPresenter;
102
use WMDE\Fundraising\Frontend\Presentation\Presenters\CreditCardPaymentHtmlPresenter;
103
use WMDE\Fundraising\Frontend\Presentation\Presenters\DisplayPagePresenter;
104
use WMDE\Fundraising\Frontend\Presentation\Presenters\DonationConfirmationHtmlPresenter;
105
use WMDE\Fundraising\Frontend\Presentation\Presenters\DonationFormViolationPresenter;
106
use WMDE\Fundraising\Frontend\Presentation\Presenters\GetInTouchHtmlPresenter;
107
use WMDE\Fundraising\Frontend\Presentation\Presenters\IbanPresenter;
108
use WMDE\Fundraising\Frontend\Presentation\Presenters\InternalErrorHtmlPresenter;
109
use WMDE\Fundraising\Frontend\Presentation\Presenters\MembershipApplicationConfirmationHtmlPresenter;
110
use WMDE\Fundraising\Frontend\Presentation\Presenters\MembershipFormViolationPresenter;
111
use WMDE\Fundraising\Frontend\Presentation\TwigTemplate;
112
use WMDE\Fundraising\Frontend\UseCases\AddComment\AddCommentUseCase;
113
use WMDE\Fundraising\Frontend\UseCases\AddComment\AddCommentValidator;
114
use WMDE\Fundraising\Frontend\UseCases\AddDonation\AddDonationPolicyValidator;
115
use WMDE\Fundraising\Frontend\UseCases\AddDonation\AddDonationUseCase;
116
use WMDE\Fundraising\Frontend\UseCases\AddDonation\AddDonationValidator;
117
use WMDE\Fundraising\Frontend\UseCases\AddSubscription\AddSubscriptionUseCase;
118
use WMDE\Fundraising\Frontend\UseCases\ApplyForMembership\ApplyForMembershipUseCase;
119
use WMDE\Fundraising\Frontend\UseCases\ApplyForMembership\MembershipApplicationValidator;
120
use WMDE\Fundraising\Frontend\UseCases\CancelDonation\CancelDonationUseCase;
121
use WMDE\Fundraising\Frontend\UseCases\CancelMembershipApplication\CancelMembershipApplicationUseCase;
122
use WMDE\Fundraising\Frontend\UseCases\CheckIban\CheckIbanUseCase;
123
use WMDE\Fundraising\Frontend\UseCases\ConfirmSubscription\ConfirmSubscriptionUseCase;
124
use WMDE\Fundraising\Frontend\UseCases\CreditCardPaymentNotification\CreditCardNotificationUseCase;
125
use WMDE\Fundraising\Frontend\UseCases\DisplayPage\DisplayPageUseCase;
126
use WMDE\Fundraising\Frontend\UseCases\GenerateIban\GenerateIbanUseCase;
127
use WMDE\Fundraising\Frontend\UseCases\GetInTouch\GetInTouchUseCase;
128
use WMDE\Fundraising\Frontend\UseCases\HandlePayPalPaymentNotification\HandlePayPalPaymentNotificationUseCase;
129
use WMDE\Fundraising\Frontend\UseCases\ListComments\ListCommentsUseCase;
130
use WMDE\Fundraising\Frontend\UseCases\PurgeCache\PurgeCacheUseCase;
131
use WMDE\Fundraising\Frontend\UseCases\ShowDonationConfirmation\ShowDonationConfirmationUseCase;
132
use WMDE\Fundraising\Frontend\UseCases\ShowMembershipApplicationConfirmation\ShowMembershipApplicationConfirmationUseCase;
133
use WMDE\Fundraising\Frontend\Validation\AllowedValuesValidator;
134
use WMDE\Fundraising\Frontend\Validation\AmountPolicyValidator;
135
use WMDE\Fundraising\Frontend\Validation\AmountValidator;
136
use WMDE\Fundraising\Frontend\Validation\BankDataValidator;
137
use WMDE\Fundraising\Frontend\Validation\EmailValidator;
138
use WMDE\Fundraising\Frontend\Validation\GetInTouchValidator;
139
use WMDE\Fundraising\Frontend\Validation\IbanValidator;
140
use WMDE\Fundraising\Frontend\Validation\MembershipFeeValidator;
141
use WMDE\Fundraising\Frontend\Validation\PersonalInfoValidator;
142
use WMDE\Fundraising\Frontend\Validation\PersonNameValidator;
143
use WMDE\Fundraising\Frontend\Validation\PhysicalAddressValidator;
144
use WMDE\Fundraising\Frontend\Validation\SubscriptionDuplicateValidator;
145
use WMDE\Fundraising\Frontend\Validation\SubscriptionValidator;
146
use WMDE\Fundraising\Frontend\Validation\TemplateNameValidator;
147
use WMDE\Fundraising\Frontend\Validation\TextPolicyValidator;
148
use WMDE\Fundraising\Store\Factory as StoreFactory;
149
use WMDE\Fundraising\Store\Installer;
150
151
/**
152
 * @licence GNU GPL v2+
153
 */
154
class FunFunFactory {
155
156
	private $config;
157
158
	/**
159
	 * @var \Pimple
160
	 */
161
	private $pimple;
162
163
	private $addDoctrineSubscribers = true;
164
165
	/**
166
	 * @var Stopwatch|null
167
	 */
168
	private $profiler = null;
169
170
	public function __construct( array $config ) {
171
		$this->config = $config;
172
		$this->pimple = $this->newPimple();
173
	}
174
175
	private function newPimple(): \Pimple {
176
		$pimple = new \Pimple();
177
178
		$pimple['logger'] = $pimple->share( function() {
179
			return new NullLogger();
180
		} );
181
182
		$pimple['dbal_connection'] = $pimple->share( function() {
183
			return DriverManager::getConnection( $this->config['db'] );
184
		} );
185
186
		$pimple['entity_manager'] = $pimple->share( function() {
187
			$entityManager = ( new StoreFactory( $this->getConnection() ) )->getEntityManager();
188
			if ( $this->addDoctrineSubscribers ) {
189
				$entityManager->getEventManager()->addEventSubscriber( $this->newDoctrineDonationPrePersistSubscriber() );
190
				$entityManager->getEventManager()->addEventSubscriber( $this->newDoctrineMembershipApplicationPrePersistSubscriber() );
191
			}
192
193
			return $entityManager;
194
		} );
195
196
		$pimple['subscription_repository'] = $pimple->share( function() {
197
			return new LoggingSubscriptionRepository(
198
				new DoctrineSubscriptionRepository( $this->getEntityManager() ),
199
				$this->getLogger()
200
			);
201
		} );
202
203
		$pimple['donation_repository'] = $pimple->share( function() {
204
			return new LoggingDonationRepository(
205
				new DoctrineDonationRepository( $this->getEntityManager() ),
206
				$this->getLogger()
207
			);
208
		} );
209
210
		$pimple['membership_application_repository'] = $pimple->share( function() {
211
			return new LoggingMembershipApplicationRepository(
212
				new DoctrineMembershipApplicationRepository( $this->getEntityManager() ),
213
				$this->getLogger()
214
			);
215
		} );
216
217
		$pimple['comment_repository'] = $pimple->share( function() {
218
			$finder = new LoggingCommentFinder(
219
				new DoctrineCommentFinder( $this->getEntityManager() ),
220
				$this->getLogger()
221
			);
222
223
			return $this->addProfilingDecorator( $finder, 'CommentFinder' );
224
		} );
225
226
		$pimple['mail_validator'] = $pimple->share( function() {
227
			return new EmailValidator( new InternetDomainNameValidator() );
228
		} );
229
230
		$pimple['subscription_validator'] = $pimple->share( function() {
231
			return new SubscriptionValidator(
232
				$this->getEmailValidator(),
233
				$this->newTextPolicyValidator( 'fields' ),
234
				$this->newSubscriptionDuplicateValidator(),
235
				$this->newHonorificValidator()
236
			);
237
		} );
238
239
		$pimple['template_name_validator'] = $pimple->share( function() {
240
			return new TemplateNameValidator( $this->getTwig() );
241
		} );
242
243
		$pimple['contact_validator'] = $pimple->share( function() {
244
			return new GetInTouchValidator( $this->getEmailValidator() );
245
		} );
246
247
		$pimple['greeting_generator'] = $pimple->share( function() {
248
			return new GreetingGenerator();
249
		} );
250
251
		$pimple['mw_api'] = $pimple->share( function() {
252
			return new MediawikiApi(
253
				$this->config['cms-wiki-api-url'],
254
				$this->getGuzzleClient()
255
			);
256
		} );
257
258
		$pimple['guzzle_client'] = $pimple->share( function() {
259
			$middlewareFactory = new MiddlewareFactory();
260
			$middlewareFactory->setLogger( $this->getLogger() );
261
262
			$handlerStack = HandlerStack::create( new CurlHandler() );
263
			$handlerStack->push( $middlewareFactory->retry() );
264
265
			$guzzle = new Client( [
266
				'cookies' => true,
267
				'handler' => $handlerStack,
268
				'headers' => [ 'User-Agent' => 'WMDE Fundraising Frontend' ],
269
			] );
270
271
			return $this->addProfilingDecorator( $guzzle, 'Guzzle Client' );
272
		} );
273
274
		$pimple['translator'] = $pimple->share( function() {
275
			$translationFactory = new TranslationFactory();
276
			$loaders = [
277
				'json' => $translationFactory->newJsonLoader()
278
			];
279
			$locale = $this->config['locale'];
280
			$translator = $translationFactory->create( $loaders, $locale );
281
			$translator->addResource(
282
				'json',
283
				__DIR__ . '/../../app/translations/messages.' . $locale . '.json',
284
				$locale
285
			);
286
287
			$translator->addResource(
288
				'json',
289
				__DIR__ . '/../../app/translations/paymentTypes.' . $locale . '.json',
290
				$locale,
291
				'paymentTypes'
292
			);
293
294
			$translator->addResource(
295
				'json',
296
				__DIR__ . '/../../app/translations/paymentIntervals.' . $locale . '.json',
297
				$locale,
298
				'paymentIntervals'
299
			);
300
301
			$translator->addResource(
302
				'json',
303
				__DIR__ . '/../../app/translations/donationStatus.' . $locale . '.json',
304
				$locale,
305
				'donationStatus'
306
			);
307
308
			$translator->addResource(
309
				'json',
310
				__DIR__ . '/../../app/translations/validations.' . $locale . '.json',
311
				$locale,
312
				'validations'
313
			);
314
315
			return $translator;
316
		} );
317
318
		// In the future, this could be locale-specific or filled from a DB table
319
		$pimple['honorifics'] = $pimple->share( function() {
320
			return new Honorifics( [
321
				'' => 'Kein Titel',
322
				'Dr.' => 'Dr.',
323
				'Prof.' => 'Prof.',
324
				'Prof. Dr.' => 'Prof. Dr.'
325
			] );
326
		} );
327
328
		$pimple['twig_factory'] = $pimple->share( function () {
329
			return new TwigFactory( $this->config['twig'], $this->getCachePath() . '/twig' );
330
		} );
331
332
		$pimple['twig'] = $pimple->share( function() {
333
			$twigFactory = $this->getTwigFactory();
334
			$loaders = array_filter( [
335
				$twigFactory->newFileSystemLoader(),
336
				$twigFactory->newArrayLoader(), // This is just a fallback for testing
337
				$twigFactory->newWikiPageLoader( $this->newWikiPageRetriever() ),
338
			] );
339
			$extensions = [
340
				$twigFactory->newTranslationExtension( $this->getTranslator() ),
341
				new Twig_Extensions_Extension_Intl()
342
			];
343
344
			return $twigFactory->create( $loaders, $extensions );
345
		} );
346
347
		$pimple['messenger'] = $pimple->share( function() {
348
			return new Messenger(
349
				new Swift_MailTransport(),
350
				$this->getOperatorAddress(),
351
				$this->config['operator-displayname']
352
			);
353
		} );
354
355
		$pimple['confirmation-page-selector'] = $pimple->share( function() {
356
			return new DonationConfirmationPageSelector( $this->config['confirmation-pages'] );
357
		} );
358
359
		$pimple['paypal-payment-notification-verifier'] = $pimple->share( function() {
360
			return new LoggingPaymentNotificationVerifier(
361
				new PayPalPaymentNotificationVerifier(
362
					new Client(),
363
					$this->config['paypal']
364
				),
365
				$this->getLogger()
366
			);
367
		} );
368
369
		$pimple['credit-card-api-service'] = $pimple->share( function() {
370
			return new McpCreditCardService(
371
				new TNvpServiceDispatcher(
372
					'IMcpCreditcardService_v1_5',
373
					'https://sipg.micropayment.de/public/creditcard/v1.5/nvp/'
374
				),
375
				$this->config['creditcard']['access-key'],
376
				$this->config['creditcard']['testmode']
377
			);
378
		} );
379
380
		$pimple['token_generator'] = $pimple->share( function() {
381
			return new RandomTokenGenerator(
382
				$this->config['token-length'],
383
				new \DateInterval( $this->config['token-validity-timestamp'] )
384
			);
385
		} );
386
387
		$pimple['page_cache'] = $pimple->share( function() {
388
			return new VoidCache();
389
		} );
390
391
		return $pimple;
392
	}
393
394
	public function getConnection(): Connection {
395
		return $this->pimple['dbal_connection'];
396
	}
397
398
	public function getEntityManager(): EntityManager {
399
		return $this->pimple['entity_manager'];
400
	}
401
402
	private function newDonationEventLogger(): DonationEventLogger {
403
		return new BestEffortDonationEventLogger(
404
			new DoctrineDonationEventLogger( $this->getEntityManager() ),
405
			$this->getLogger()
406
		);
407
	}
408
409
	public function newInstaller(): Installer {
410
		return ( new StoreFactory( $this->getConnection() ) )->newInstaller();
411
	}
412
413
	public function newListCommentsUseCase(): ListCommentsUseCase {
414
		return new ListCommentsUseCase( $this->getCommentFinder() );
415
	}
416
417
	public function newCommentListJsonPresenter(): CommentListJsonPresenter {
418
		return new CommentListJsonPresenter();
419
	}
420
421
	public function newCommentListRssPresenter(): CommentListRssPresenter {
422
		return new CommentListRssPresenter( new TwigTemplate(
423
			$this->getTwig(),
424
			'CommentList.rss.twig'
425
		) );
426
	}
427
428
	public function newCommentListHtmlPresenter(): CommentListHtmlPresenter {
429
		return new CommentListHtmlPresenter( $this->getLayoutTemplate( 'CommentList.html.twig' ) );
430
	}
431
432
	private function getCommentFinder(): CommentFinder {
433
		return $this->pimple['comment_repository'];
434
	}
435
436
	public function getSubscriptionRepository(): SubscriptionRepository {
437
		return $this->pimple['subscription_repository'];
438
	}
439
440
	public function setSubscriptionRepository( SubscriptionRepository $subscriptionRepository ) {
441
		$this->pimple['subscription_repository'] = $subscriptionRepository;
442
	}
443
444
	private function getSubscriptionValidator(): SubscriptionValidator {
445
		return $this->pimple['subscription_validator'];
446
	}
447
448
	public function getEmailValidator(): EmailValidator {
449
		return $this->pimple['mail_validator'];
450
	}
451
452
	private function getTemplateNameValidator(): TemplateNameValidator {
453
		return $this->pimple['template_name_validator'];
454
	}
455
456
	public function newDisplayPageUseCase(): DisplayPageUseCase {
457
		return new DisplayPageUseCase(
458
			$this->getTemplateNameValidator()
459
		);
460
	}
461
462
	public function newDisplayPagePresenter(): DisplayPagePresenter {
463
		return new DisplayPagePresenter( $this->getLayoutTemplate( 'DisplayPageLayout.twig' ) );
464
	}
465
466
	public function newAddSubscriptionHTMLPresenter(): AddSubscriptionHtmlPresenter {
467
		return new AddSubscriptionHtmlPresenter( $this->getIncludeTemplate( 'Subscription_Form.twig' ), $this->getTranslator() );
468
	}
469
470
	public function newConfirmSubscriptionHtmlPresenter(): ConfirmSubscriptionHtmlPresenter {
471
		return new ConfirmSubscriptionHtmlPresenter(
472
			$this->getLayoutTemplate( 'ConfirmSubscription.html.twig' ),
473
			$this->getTranslator()
474
		);
475
	}
476
477
	public function newAddSubscriptionJSONPresenter(): AddSubscriptionJsonPresenter {
478
		return new AddSubscriptionJsonPresenter( $this->getTranslator() );
479
	}
480
481
	public function newGetInTouchHTMLPresenter(): GetInTouchHtmlPresenter {
482
		return new GetInTouchHtmlPresenter( $this->getIncludeTemplate( 'Kontaktformular.twig' ), $this->getTranslator() );
483
	}
484
485
	public function getTwig(): Twig_Environment {
486
		return $this->pimple['twig'];
487
	}
488
489
	/**
490
	 * Get a template, with the content for the layout areas filled in.
491
	 *
492
	 * @param string $templateName
493
	 * @return TwigTemplate
494
	 */
495
	private function getLayoutTemplate( string $templateName ): TwigTemplate {
496
		 return new TwigTemplate(
497
			$this->getTwig(),
498
			$templateName,
499
			$this->getDefaultTwigVariables()
500
		);
501
	}
502
503
	/**
504
	 * Get a layouted template that includes another template
505
	 *
506
	 * @param string $templateName Template to include
507
	 * @return TwigTemplate
508
	 */
509
	private function getIncludeTemplate( string $templateName ): TwigTemplate {
510
		return new TwigTemplate(
511
			$this->getTwig(),
512
			'IncludeInLayout.twig',
513
			array_merge(
514
				$this->getDefaultTwigVariables(),
515
				[ 'main_template' => $templateName ]
516
			)
517
		);
518
	}
519
520
	private function getDefaultTwigVariables() {
521
		return [
522
			'basepath' => $this->config['web-basepath'],
523
			'honorifics' => $this->getHonorifics()->getList(),
524
			'header_template' => $this->config['default-layout-templates']['header'],
525
			'footer_template' => $this->config['default-layout-templates']['footer'],
526
			'no_js_notice_template' => $this->config['default-layout-templates']['no-js-notice'],
527
		];
528
	}
529
530
	private function newReferrerGeneralizer() {
531
		return new ReferrerGeneralizer(
532
			$this->config['referrer-generalization']['default'],
533
			$this->config['referrer-generalization']['domain-map']
534
		);
535
	}
536
537
	private function getMediaWikiApi(): MediawikiApi {
538
		return $this->pimple['mw_api'];
539
	}
540
541
	public function setMediaWikiApi( MediawikiApi $api ) {
542
		$this->pimple['mw_api'] = $api;
543
	}
544
545
	private function getGuzzleClient(): ClientInterface {
546
		return $this->pimple['guzzle_client'];
547
	}
548
549
	private function newWikiPageRetriever(): PageRetriever {
550
		$PageRetriever = new ModifyingPageRetriever(
551
			$this->newCachedPageRetriever(),
552
			$this->newPageContentModifier(),
553
			$this->config['cms-wiki-title-prefix']
554
		);
555
556
		return $this->addProfilingDecorator( $PageRetriever, 'PageRetriever' );
557
	}
558
559
	private function newCachedPageRetriever(): PageRetriever {
560
		return new CachingPageRetriever(
561
			$this->newNonCachedApiPageRetriever(),
562
			$this->getPageCache()
563
		);
564
	}
565
566
	private function newNonCachedApiPageRetriever(): PageRetriever {
567
		return new ApiBasedPageRetriever(
568
			$this->getMediaWikiApi(),
569
			new ApiUser( $this->config['cms-wiki-user'], $this->config['cms-wiki-password'] ),
570
			$this->getLogger()
571
		);
572
	}
573
574
	public function getLogger(): LoggerInterface {
575
		return $this->pimple['logger'];
576
	}
577
578
	private function getVarPath(): string {
579
		return __DIR__ . '/../../var';
580
	}
581
582
	public function getCachePath(): string {
583
		return $this->getVarPath() . '/cache';
584
	}
585
586
	public function getLoggingPath(): string {
587
		return $this->getVarPath() . '/log';
588
	}
589
590
	private function newPageContentModifier(): PageContentModifier {
591
		return new PageContentModifier(
592
			$this->getLogger()
593
		);
594
	}
595
596
	public function newAddSubscriptionUseCase(): AddSubscriptionUseCase {
597
		return new AddSubscriptionUseCase(
598
			$this->getSubscriptionRepository(),
599
			$this->getSubscriptionValidator(),
600
			$this->newAddSubscriptionMailer()
601
		);
602
	}
603
604
	public function newConfirmSubscriptionUseCase(): ConfirmSubscriptionUseCase {
605
		return new ConfirmSubscriptionUseCase(
606
			$this->getSubscriptionRepository(),
607
			$this->newConfirmSubscriptionMailer()
608
		);
609
	}
610
611
	private function newAddSubscriptionMailer(): TemplateBasedMailer {
612
		return $this->newTemplateMailer(
613
			new TwigTemplate(
614
				$this->getTwig(),
615
				'Mail_Subscription_Request.twig',
616
				[
617
					'basepath' => $this->config['web-basepath'],
618
					'greeting_generator' => $this->getGreetingGenerator()
619
				]
620
			),
621
			'mail_subject_membership'
622
		);
623
	}
624
625
	private function newConfirmSubscriptionMailer(): TemplateBasedMailer {
626
		return $this->newTemplateMailer(
627
			new TwigTemplate(
628
					$this->getTwig(),
629
					'Mail_Subscription_Confirmation.twig',
630
					[ 'greeting_generator' => $this->getGreetingGenerator() ]
631
			),
632
			'mail_subject_membership'
633
		);
634
	}
635
636
	private function newTemplateMailer( TwigTemplate $template, string $messageKey ): TemplateBasedMailer {
637
		$mailer = new TemplateBasedMailer(
638
			$this->getMessenger(),
639
			$template,
640
			$this->getTranslator()->trans( $messageKey )
641
		);
642
643
		$mailer = new LoggingMailer( $mailer, $this->getLogger() );
644
645
		return $this->addProfilingDecorator( $mailer, 'Mailer' );
646
	}
647
648
	public function getGreetingGenerator() {
649
		return $this->pimple['greeting_generator'];
650
	}
651
652
	public function newCheckIbanUseCase(): CheckIbanUseCase {
653
		return new CheckIbanUseCase( $this->newBankDataConverter() );
654
	}
655
656
	public function newGenerateIbanUseCase(): GenerateIbanUseCase {
657
		return new GenerateIbanUseCase( $this->newBankDataConverter() );
658
	}
659
660
	public function newIbanPresenter(): IbanPresenter {
661
		return new IbanPresenter();
662
	}
663
664
	public function newBankDataConverter() {
665
		return new BankDataConverter( $this->config['bank-data-file'] );
666
	}
667
668
	public function setSubscriptionValidator( SubscriptionValidator $subscriptionValidator ) {
669
		$this->pimple['subscription_validator'] = $subscriptionValidator;
670
	}
671
672
	public function setPageTitlePrefix( string $prefix ) {
673
		$this->config['cms-wiki-title-prefix'] = $prefix;
674
	}
675
676
	public function newGetInTouchUseCase() {
677
		return new GetInTouchUseCase(
678
			$this->getContactValidator(),
679
			$this->getMessenger(),
680
			$this->newContactConfirmationMailer()
681
		);
682
	}
683
684
	private function newContactConfirmationMailer(): TemplateBasedMailer {
685
		return $this->newTemplateMailer(
686
			new TwigTemplate( $this->getTwig(), 'KontaktMailExtern.twig' ),
687
			'mail_subject_getintouch'
688
		);
689
	}
690
691
	private function getContactValidator(): GetInTouchValidator {
692
		return $this->pimple['contact_validator'];
693
	}
694
695
	private function newSubscriptionDuplicateValidator(): SubscriptionDuplicateValidator {
696
		return new SubscriptionDuplicateValidator(
697
				$this->getSubscriptionRepository(),
698
				$this->newSubscriptionDuplicateCutoffDate()
699
		);
700
	}
701
702
	private function newSubscriptionDuplicateCutoffDate(): \DateTime {
703
		$cutoffDateTime = new \DateTime();
704
		$cutoffDateTime->sub( new \DateInterval( $this->config['subscription-interval'] ) );
705
		return $cutoffDateTime;
706
	}
707
708
	private function newHonorificValidator(): AllowedValuesValidator {
709
		return new AllowedValuesValidator( $this->getHonorifics()->getKeys() );
710
	}
711
712
	private function getHonorifics(): Honorifics {
713
		return $this->pimple['honorifics'];
714
	}
715
716
	public function newPurgeCacheUseCase(): PurgeCacheUseCase {
717
		return new PurgeCacheUseCase(
718
			new AllOfTheCachePurger( $this->getTwig(), $this->getPageCache() ),
719
			$this->config['purging-secret']
720
		);
721
	}
722
723
	private function newBankDataValidator(): BankDataValidator {
724
		return new BankDataValidator( new IbanValidator( $this->newBankDataConverter() ) );
725
	}
726
727
	private function getMessenger(): Messenger {
728
		return $this->pimple['messenger'];
729
	}
730
731
	public function setMessenger( Messenger $messenger ) {
732
		$this->pimple['messenger'] = $messenger;
733
	}
734
735
	public function setNullMessenger() {
736
		$this->setMessenger( new Messenger(
737
			Swift_NullTransport::newInstance(),
738
			$this->getOperatorAddress()
739
		) );
740
	}
741
742
	public function getOperatorAddress() {
743
		return new EmailAddress( $this->config['operator-email'] );
744
	}
745
746
	public function newInternalErrorHTMLPresenter(): InternalErrorHtmlPresenter {
747
		return new InternalErrorHtmlPresenter( $this->getIncludeTemplate( 'ErrorPage.twig' ) );
748
	}
749
750
	public function newAccessDeniedHTMLPresenter(): InternalErrorHtmlPresenter {
751
		return new InternalErrorHtmlPresenter( $this->getLayoutTemplate( 'AccessDenied.twig' ) );
752
	}
753
754
	public function getTranslator(): TranslatorInterface {
755
		return $this->pimple['translator'];
756
	}
757
758
	public function setTranslator( TranslatorInterface $translator ) {
759
		$this->pimple['translator'] = $translator;
760
	}
761
762
	private function getTwigFactory(): TwigFactory {
763
		return $this->pimple['twig_factory'];
764
	}
765
766
	private function newTextPolicyValidator( string $policyName ): TextPolicyValidator {
767
		$contentProvider = $this->newWikiPageRetriever();
768
		$textPolicyConfig = $this->config['text-policies'][$policyName];
769
770
		return new TextPolicyValidator(
771
			new PageRetrieverBasedStringList( $contentProvider, $textPolicyConfig['badwords'] ?? '' ),
772
			new PageRetrieverBasedStringList( $contentProvider, $textPolicyConfig['whitewords'] ?? '' )
773
		);
774
	}
775
776
	private function newCommentPolicyValidator(): TextPolicyValidator {
777
		return $this->newTextPolicyValidator( 'comment' );
778
	}
779
780
	public function newCancelDonationUseCase( string $updateToken ): CancelDonationUseCase {
781
		return new CancelDonationUseCase(
782
			$this->getDonationRepository(),
783
			$this->newCancelDonationMailer(),
784
			$this->newDonationAuthorizer( $updateToken ),
785
			$this->newDonationEventLogger()
786
		);
787
	}
788
789
	private function newCancelDonationMailer(): TemplateBasedMailer {
790
		return $this->newTemplateMailer(
791
			new TwigTemplate(
792
				$this->getTwig(),
793
				'Mail_Donation_Cancellation_Confirmation.twig',
794
				[ 'greeting_generator' => $this->getGreetingGenerator() ]
795
			),
796
			'mail_subject_confirm_cancellation'
797
		);
798
	}
799
800
	public function newAddDonationUseCase(): AddDonationUseCase {
801
		return new AddDonationUseCase(
802
			$this->getDonationRepository(),
803
			$this->newDonationValidator(),
804
			$this->newDonationPolicyValidator(),
805
			$this->newReferrerGeneralizer(),
806
			$this->newDonationConfirmationMailer(),
807
			$this->newBankTransferCodeGenerator(),
808
			$this->newDonationTokenFetcher()
809
		);
810
	}
811
812
	private function newBankTransferCodeGenerator(): TransferCodeGenerator {
813
		return new UniqueTransferCodeGenerator(
814
			new SimpleTransferCodeGenerator(),
815
			$this->getEntityManager()
816
		);
817
	}
818
819
	private function newDonationValidator(): AddDonationValidator {
820
		return new AddDonationValidator(
821
			$this->newAmountValidator(),
822
			$this->newBankDataValidator(),
823
			$this->getEmailValidator()
824
		);
825
	}
826
827
	public function newPersonalInfoValidator(): PersonalInfoValidator {
828
		return new PersonalInfoValidator(
829
			new PersonNameValidator(),
830
			new PhysicalAddressValidator(),
831
			$this->getEmailValidator()
832
		);
833
	}
834
835
	private function newDonationConfirmationMailer(): DonationConfirmationMailer {
836
		return new DonationConfirmationMailer(
837
			$this->newTemplateMailer(
838
				new TwigTemplate(
839
					$this->getTwig(),
840
					'Mail_Donation_Confirmation.twig', // TODO: ongoing unification of different templates
841
					[
842
						'basepath' => $this->config['web-basepath'],
843
						'greeting_generator' => $this->getGreetingGenerator()
844
					]
845
				),
846
				'mail_subject_confirm_donation'
847
			)
848
		);
849
	}
850
851
	public function newPayPalUrlGenerator() {
852
		return new PayPalUrlGenerator( $this->getPayPalUrlConfig() );
853
	}
854
855
	private function getPayPalUrlConfig() {
856
		return PayPalUrlConfig::newFromConfig( $this->config['paypal'] );
857
	}
858
859
	private function newCreditCardUrlGenerator() {
860
		return new CreditCardUrlGenerator( $this->newCreditCardUrlConfig() );
861
	}
862
863
	private function newCreditCardUrlConfig() {
864
		return CreditCardUrlConfig::newFromConfig( $this->config['creditcard'] );
865
	}
866
867
	public function getDonationRepository(): DonationRepository {
868
		return $this->pimple['donation_repository'];
869
	}
870
871
	public function newAmountValidator(): AmountValidator {
872
		return new AmountValidator( 1 );
873
	}
874
875
	private function newAmountFormatter(): AmountFormatter {
876
		return new AmountFormatter( $this->config['locale'] );
877
	}
878
879
	public function newDecimalNumberFormatter(): NumberFormatter {
880
		return new NumberFormatter( $this->config['locale'], NumberFormatter::DECIMAL );
881
	}
882
883
	public function newAddCommentUseCase( string $updateToken ): AddCommentUseCase {
884
		return new AddCommentUseCase(
885
			$this->getDonationRepository(),
886
			$this->newDonationAuthorizer( $updateToken ),
887
			$this->newCommentPolicyValidator(),
888
			$this->newAddCommentValidator()
889
		);
890
	}
891
892
	private function newDonationAuthorizer( string $updateToken = null, string $accessToken = null ): DonationAuthorizer {
893
		return new DoctrineDonationAuthorizer(
894
			$this->getEntityManager(),
895
			$updateToken,
896
			$accessToken
897
		);
898
	}
899
900
	public function getTokenGenerator(): TokenGenerator {
901
		return $this->pimple['token_generator'];
902
	}
903
904
	public function newDonationConfirmationPresenter() {
905
		return new DonationConfirmationHtmlPresenter(
906
			$this->getIncludeTemplate( 'DonationConfirmation.twig' )
907
		);
908
	}
909
910
	public function newCreditCardPaymentHtmlPresenter() {
911
		return new CreditCardPaymentHtmlPresenter(
912
			$this->getIncludeTemplate( 'CreditCardPaymentIframe.twig' ),
913
			$this->getTranslator(),
914
			$this->newCreditCardUrlGenerator()
915
		);
916
	}
917
918
	public function newCancelDonationHtmlPresenter() {
919
		return new CancelDonationHtmlPresenter(
920
			$this->getIncludeTemplate( 'Donation_Cancellation_Confirmation.twig' )
921
		);
922
	}
923
924
	public function newApplyForMembershipUseCase(): ApplyForMembershipUseCase {
925
		return new ApplyForMembershipUseCase(
926
			$this->getMembershipApplicationRepository(),
927
			$this->newMembershipApplicationTokenFetcher(),
928
			$this->newApplyForMembershipMailer(),
929
			$this->newMembershipApplicationValidator(),
930
			$this->newMembershipApplicationTracker(),
931
			$this->newMembershipApplicationPiwikTracker()
932
		);
933
	}
934
935
	private function newApplyForMembershipMailer(): TemplateBasedMailer {
936
		return $this->newTemplateMailer(
937
			new TwigTemplate(
938
				$this->getTwig(),
939
				'Mail_Membership_Application_Confirmation.twig',
940
				[ 'greeting_generator' => $this->getGreetingGenerator() ]
941
			),
942
			'mail_subject_confirm_membership_application'
943
		);
944
	}
945
946
	private function newMembershipApplicationValidator(): MembershipApplicationValidator {
947
		return new MembershipApplicationValidator(
948
			new MembershipFeeValidator(),
949
			$this->newBankDataValidator(),
950
			$this->getEmailValidator()
951
		);
952
	}
953
954
	private function newMembershipApplicationTracker(): MembershipApplicationTracker {
955
		return new DoctrineMembershipApplicationTracker( $this->getEntityManager() );
956
	}
957
958
	private function newMembershipApplicationPiwikTracker(): MembershipApplicationPiwikTracker {
959
		return new DoctrineMembershipApplicationPiwikTracker( $this->getEntityManager() );
960
	}
961
962
	public function newCancelMembershipApplicationUseCase( string $updateToken ): CancelMembershipApplicationUseCase {
963
		return new CancelMembershipApplicationUseCase(
964
			$this->newMembershipApplicationAuthorizer( $updateToken ),
965
			$this->getMembershipApplicationRepository(),
966
			$this->newCancelMembershipApplicationMailer()
967
		);
968
	}
969
970
	private function newMembershipApplicationAuthorizer(
971
		string $updateToken = null, string $accessToken = null ): MembershipApplicationAuthorizer {
972
973
		return new DoctrineMembershipApplicationAuthorizer(
974
			$this->getEntityManager(),
975
			$updateToken,
976
			$accessToken
977
		);
978
	}
979
980
	public function getMembershipApplicationRepository(): MembershipApplicationRepository {
981
		return $this->pimple['membership_application_repository'];
982
	}
983
984
	private function newCancelMembershipApplicationMailer(): TemplateBasedMailer {
985
		return $this->newTemplateMailer(
986
			new TwigTemplate(
987
				$this->getTwig(),
988
				'Mail_Membership_Application_Cancellation_Confirmation.twig',
989
				[ 'greeting_generator' => $this->getGreetingGenerator() ]
990
			),
991
			'mail_subject_confirm_membership_application_cancellation'
992
		);
993
	}
994
995
	public function newMembershipApplicationConfirmationUseCase( string $accessToken ) {
996
		return new ShowMembershipApplicationConfirmationUseCase(
997
			$this->newMembershipApplicationAuthorizer( null, $accessToken ), $this->getMembershipApplicationRepository(),
998
			$this->newMembershipApplicationTokenFetcher()
999
		);
1000
	}
1001
1002
	public function newShowDonationConfirmationUseCase( string $accessToken ): ShowDonationConfirmationUseCase {
1003
		return new ShowDonationConfirmationUseCase(
1004
			$this->newDonationAuthorizer( null, $accessToken ),
1005
			$this->getDonationRepository()
1006
		);
1007
	}
1008
1009
	public function setDonationConfirmationPageSelector( DonationConfirmationPageSelector $selector ) {
1010
		$this->pimple['confirmation-page-selector'] = $selector;
1011
	}
1012
1013
	public function getDonationConfirmationPageSelector() {
1014
		return $this->pimple['confirmation-page-selector'];
1015
	}
1016
1017
	public function newDonationFormViolationPresenter() {
1018
		$template = $this->getLayoutTemplate( 'DisplayPageLayout.twig' );
1019
		// TODO make this dependent on the 'form' value from the HTTP POST request
1020
		// (we need different form pages for A/B testing)
1021
		$template->context['main_template'] = 'DonationForm.twig';
0 ignored issues
show
Bug introduced by
The property context does not seem to exist in WMDE\Fundraising\Fronten...esentation\TwigTemplate.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1022
		return new DonationFormViolationPresenter( $template, $this->newAmountFormatter() );
1023
	}
1024
1025
	public function newHandlePayPalPaymentNotificationUseCase( string $updateToken ) {
1026
		return new HandlePayPalPaymentNotificationUseCase(
1027
			$this->getDonationRepository(),
1028
			$this->newDonationAuthorizer( $updateToken ),
1029
			$this->newDonationConfirmationMailer(),
1030
			$this->getLogger(),
1031
			$this->newDonationEventLogger()
1032
		);
1033
	}
1034
1035
	public function getPayPalPaymentNotificationVerifier(): PaymentNotificationVerifier {
1036
		return $this->pimple['paypal-payment-notification-verifier'];
1037
	}
1038
1039
	public function setPayPalPaymentNotificationVerifier( PaymentNotificationVerifier $verifier ) {
1040
		$this->pimple['paypal-payment-notification-verifier'] = $verifier;
1041
	}
1042
1043
	public function newCreditCardNotificationUseCase( string $updateToken ) {
1044
		return new CreditCardNotificationUseCase(
1045
			$this->getDonationRepository(),
1046
			$this->newDonationAuthorizer( $updateToken ),
1047
			$this->getCreditCardService(),
1048
			$this->newDonationConfirmationMailer(),
1049
			$this->getLogger(),
1050
			$this->newDonationEventLogger()
1051
		);
1052
	}
1053
1054
	public function newCancelMembershipApplicationHtmlPresenter() {
1055
		return new CancelMembershipApplicationHtmlPresenter(
1056
			$this->getIncludeTemplate( 'Membership_Application_Cancellation_Confirmation.twig' )
1057
		);
1058
	}
1059
1060
	public function newMembershipApplicationConfirmationHtmlPresenter() {
1061
		return new MembershipApplicationConfirmationHtmlPresenter(
1062
			$this->getIncludeTemplate( 'MembershipApplicationConfirmation.twig' )
1063
		);
1064
	}
1065
1066
	public function newMembershipFormViolationPresenter() {
1067
		return new MembershipFormViolationPresenter(
1068
			$this->getIncludeTemplate( 'MembershipApplication.twig' )
1069
		);
1070
	}
1071
1072
	public function setCreditCardService( CreditCardService $ccService ) {
1073
		$this->pimple['credit-card-api-service'] = $ccService;
1074
	}
1075
1076
	public function getCreditCardService(): CreditCardService {
1077
		return $this->pimple['credit-card-api-service'];
1078
	}
1079
1080
	public function newCreditCardNotificationPresenter(): CreditCardNotificationPresenter {
1081
		return new CreditCardNotificationPresenter(
1082
			new TwigTemplate(
1083
				$this->getTwig(),
1084
				'CreditCardPaymentNotification.twig',
1085
				[ 'returnUrl' => $this->config['creditcard']['return-url'] ]
1086
			)
1087
		);
1088
	}
1089
1090
	private function newDoctrineDonationPrePersistSubscriber(): DoctrineDonationPrePersistSubscriber {
1091
		$tokenGenerator = $this->getTokenGenerator();
1092
		return new DoctrineDonationPrePersistSubscriber(
1093
			$tokenGenerator,
1094
			$tokenGenerator
1095
		);
1096
	}
1097
1098
	private function newDoctrineMembershipApplicationPrePersistSubscriber(): DoctrineMembershipApplicationPrePersistSubscriber {
1099
		$tokenGenerator = $this->getTokenGenerator();
1100
		return new DoctrineMembershipApplicationPrePersistSubscriber(
1101
			$tokenGenerator,
1102
			$tokenGenerator
1103
		);
1104
	}
1105
1106
	public function setTokenGenerator( TokenGenerator $tokenGenerator ) {
1107
		$this->pimple['token_generator'] = $tokenGenerator;
1108
	}
1109
1110
	public function disableDoctrineSubscribers() {
1111
		$this->addDoctrineSubscribers = false;
1112
	}
1113
1114
	private function newDonationTokenFetcher(): DonationTokenFetcher {
1115
		return new DoctrineDonationTokenFetcher(
1116
			$this->getEntityManager()
1117
		);
1118
	}
1119
1120
	private function newMembershipApplicationTokenFetcher(): MembershipApplicationTokenFetcher {
1121
		return new DoctrineMembershipApplicationTokenFetcher(
1122
			$this->getEntityManager()
1123
		);
1124
	}
1125
1126
	private function newDonationPolicyValidator(): AddDonationPolicyValidator {
1127
		return new AddDonationPolicyValidator(
1128
			$this->newDonationAmountPolicyValidator(),
1129
			$this->newTextPolicyValidator( 'fields' )
1130
		);
1131
	}
1132
1133
	private function newDonationAmountPolicyValidator(): AmountPolicyValidator {
1134
		// in the future, this might come from the configuration
1135
		return new AmountPolicyValidator( 1000, 200, 300 );
1136
	}
1137
1138
	public function getDonationTimeframeLimit() {
1139
		return $this->config['donation-timeframe-limit'];
1140
	}
1141
1142
	public function newSystemMessageResponse( string $message ) {
1143
		$test = $this->getIncludeTemplate( 'System_Message.twig' );
1144
		return $test->render( [ 'message' => $message ] );
1145
	}
1146
1147
	public function getMembershipApplicationTimeframeLimit() {
1148
		return $this->config['membership-application-timeframe-limit'];
1149
	}
1150
1151
	private function newAddCommentValidator(): AddCommentValidator {
1152
		return new AddCommentValidator();
1153
	}
1154
1155
	private function getPageCache(): Cache {
1156
		return $this->pimple['page_cache'];
1157
	}
1158
1159
	public function enablePageCache() {
1160
		$this->pimple['page_cache'] = $this->pimple->share( function() {
1161
			return new FilesystemCache( $this->getCachePath() . '/pages' );
1162
		} );
1163
	}
1164
1165
	private function addProfilingDecorator( $objectToDecorate, string $profilingLabel ) {
1166
		if ( $this->profiler === null ) {
1167
			return $objectToDecorate;
1168
		}
1169
1170
		$builder = new ProfilingDecoratorBuilder( $this->profiler );
1171
1172
		return $builder->decorate( $objectToDecorate, $profilingLabel );
1173
	}
1174
1175
	public function setProfiler( Stopwatch $profiler ) {
1176
		$this->profiler = $profiler;
1177
	}
1178
1179
	public function setLogger( LoggerInterface $logger ) {
1180
		$this->pimple['logger'] = $logger;
1181
	}
1182
1183
}
1184