Completed
Push — master ( c82b55...112ae2 )
by Jeroen De
53:00 queued 30:55
created

FunFunFactory::newAddCommentUseCase()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

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