Completed
Push — master ( 6d48a0...fb36d6 )
by Jeroen De
14s
created

FunFunFactory::newAddCommentValidator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\Fundraising\Frontend\Factories;
6
7
use Doctrine\Common\Cache\Cache;
8
use Doctrine\Common\Cache\FilesystemCache;
9
use Doctrine\Common\Cache\VoidCache;
10
use Doctrine\DBAL\Connection;
11
use Doctrine\DBAL\DriverManager;
12
use Doctrine\ORM\EntityManager;
13
use FileFetcher\ErrorLoggingFileFetcher;
14
use FileFetcher\SimpleFileFetcher;
15
use GuzzleHttp\Client;
16
use NumberFormatter;
17
use Pimple\Container;
18
use Psr\Log\LoggerInterface;
19
use Psr\Log\NullLogger;
20
use Swift_MailTransport;
21
use Swift_NullTransport;
22
use Symfony\Component\Stopwatch\Stopwatch;
23
use Symfony\Component\Translation\TranslatorInterface;
24
use TNvpServiceDispatcher;
25
use Twig_Environment;
26
use Twig_Extensions_Extension_Intl;
27
use Twig_SimpleFunction;
28
use WMDE\Fundraising\Frontend\DonationContext\DonationAcceptedEventHandler;
29
use WMDE\Fundraising\Frontend\Infrastructure\Cache\AllOfTheCachePurger;
30
use WMDE\Fundraising\Frontend\Infrastructure\MailTemplateFilenameTraversable;
31
use WMDE\Fundraising\Frontend\Infrastructure\WordListFileReader;
32
use WMDE\Fundraising\Frontend\Infrastructure\PageViewTracker;
33
use WMDE\Fundraising\Frontend\Infrastructure\PiwikServerSideTracker;
34
use WMDE\Fundraising\Frontend\Infrastructure\ServerSideTracker;
35
use WMDE\Fundraising\Frontend\MembershipContext\UseCases\ApplyForMembership\ApplyForMembershipPolicyValidator;
36
use WMDE\Fundraising\Frontend\MembershipContext\UseCases\HandleSubscriptionPaymentNotification\HandleSubscriptionPaymentNotificationUseCase;
37
use WMDE\Fundraising\Frontend\MembershipContext\UseCases\HandleSubscriptionSignupNotification\HandleSubscriptionSignupNotificationUseCase;
38
use WMDE\Fundraising\Frontend\Presentation\ContentPage\PageSelector;
39
use WMDE\Fundraising\Frontend\Presentation\Honorifics;
40
use WMDE\Fundraising\Frontend\Presentation\Presenters\PageNotFoundPresenter;
41
use WMDE\Fundraising\Frontend\UseCases\GetInTouch\GetInTouchUseCase;
42
use WMDE\Fundraising\Frontend\Infrastructure\Cache\AuthorizedCachePurger;
43
use WMDE\Fundraising\Frontend\DonationContext\Authorization\DonationAuthorizer;
44
use WMDE\Fundraising\Frontend\DonationContext\Authorization\DonationTokenFetcher;
45
use WMDE\Fundraising\Frontend\DonationContext\DataAccess\DoctrineCommentFinder;
46
use WMDE\Fundraising\Frontend\DonationContext\DataAccess\DoctrineDonationAuthorizer;
47
use WMDE\Fundraising\Frontend\DonationContext\DataAccess\DoctrineDonationEventLogger;
48
use WMDE\Fundraising\Frontend\DonationContext\DataAccess\DoctrineDonationPrePersistSubscriber;
49
use WMDE\Fundraising\Frontend\DonationContext\DataAccess\DoctrineDonationRepository;
50
use WMDE\Fundraising\Frontend\DonationContext\DataAccess\DoctrineDonationTokenFetcher;
51
use WMDE\Fundraising\Frontend\DonationContext\Domain\Repositories\CommentFinder;
52
use WMDE\Fundraising\Frontend\DonationContext\Domain\Repositories\DonationRepository;
53
use WMDE\Fundraising\Frontend\DonationContext\Infrastructure\BestEffortDonationEventLogger;
54
use WMDE\Fundraising\Frontend\DonationContext\Infrastructure\DonationConfirmationMailer;
55
use WMDE\Fundraising\Frontend\DonationContext\Infrastructure\DonationEventLogger;
56
use WMDE\Fundraising\Frontend\DonationContext\Infrastructure\LoggingCommentFinder;
57
use WMDE\Fundraising\Frontend\DonationContext\Infrastructure\LoggingDonationRepository;
58
use WMDE\Fundraising\Frontend\DonationContext\UseCases\AddComment\AddCommentUseCase;
59
use WMDE\Fundraising\Frontend\DonationContext\UseCases\AddComment\AddCommentValidator;
60
use WMDE\Fundraising\Frontend\DonationContext\UseCases\AddDonation\AddDonationPolicyValidator;
61
use WMDE\Fundraising\Frontend\DonationContext\UseCases\AddDonation\AddDonationUseCase;
62
use WMDE\Fundraising\Frontend\DonationContext\UseCases\AddDonation\AddDonationValidator;
63
use WMDE\Fundraising\Frontend\DonationContext\UseCases\AddDonation\ReferrerGeneralizer;
64
use WMDE\Fundraising\Frontend\DonationContext\UseCases\CancelDonation\CancelDonationUseCase;
65
use WMDE\Fundraising\Frontend\DonationContext\UseCases\CreditCardPaymentNotification\CreditCardNotificationUseCase;
66
use WMDE\Fundraising\Frontend\DonationContext\UseCases\HandlePayPalPaymentNotification\HandlePayPalPaymentNotificationUseCase;
67
use WMDE\Fundraising\Frontend\DonationContext\UseCases\ListComments\ListCommentsUseCase;
68
use WMDE\Fundraising\Frontend\DonationContext\UseCases\ShowDonationConfirmation\ShowDonationConfirmationUseCase;
69
use WMDE\Fundraising\Frontend\DonationContext\Validation\DonorAddressValidator;
70
use WMDE\Fundraising\Frontend\DonationContext\Validation\DonorNameValidator;
71
use WMDE\Fundraising\Frontend\DonationContext\Validation\DonorValidator;
72
use WMDE\Fundraising\Frontend\Infrastructure\InternetDomainNameValidator;
73
use WMDE\Fundraising\Frontend\Infrastructure\LoggingMailer;
74
use WMDE\Fundraising\Frontend\Infrastructure\LoggingPaymentNotificationVerifier;
75
use WMDE\Fundraising\Frontend\Infrastructure\Messenger;
76
use WMDE\Fundraising\Frontend\Infrastructure\OperatorMailer;
77
use WMDE\Fundraising\Frontend\Infrastructure\PaymentNotificationVerifier;
78
use WMDE\Fundraising\Frontend\Infrastructure\PayPalPaymentNotificationVerifier;
79
use WMDE\Fundraising\Frontend\Infrastructure\ProfilerDataCollector;
80
use WMDE\Fundraising\Frontend\Infrastructure\ProfilingDecoratorBuilder;
81
use WMDE\Fundraising\Frontend\Infrastructure\RandomTokenGenerator;
82
use WMDE\Fundraising\Frontend\Infrastructure\TemplateBasedMailer;
83
use WMDE\Fundraising\Frontend\Infrastructure\TemplateMailerInterface;
84
use WMDE\Fundraising\Frontend\Infrastructure\TokenGenerator;
85
use WMDE\Fundraising\Frontend\MembershipContext\Authorization\ApplicationAuthorizer;
86
use WMDE\Fundraising\Frontend\MembershipContext\Authorization\ApplicationTokenFetcher;
87
use WMDE\Fundraising\Frontend\MembershipContext\DataAccess\DoctrineApplicationAuthorizer;
88
use WMDE\Fundraising\Frontend\MembershipContext\DataAccess\DoctrineApplicationPiwikTracker;
89
use WMDE\Fundraising\Frontend\MembershipContext\DataAccess\DoctrineApplicationRepository;
90
use WMDE\Fundraising\Frontend\MembershipContext\DataAccess\DoctrineApplicationTokenFetcher;
91
use WMDE\Fundraising\Frontend\MembershipContext\DataAccess\DoctrineApplicationTracker;
92
use WMDE\Fundraising\Frontend\MembershipContext\DataAccess\DoctrineMembershipApplicationPrePersistSubscriber;
93
use WMDE\Fundraising\Frontend\MembershipContext\Domain\Model\EmailAddress;
94
use WMDE\Fundraising\Frontend\MembershipContext\Domain\Repositories\ApplicationRepository;
95
use WMDE\Fundraising\Frontend\MembershipContext\Infrastructure\LoggingApplicationRepository;
96
use WMDE\Fundraising\Frontend\MembershipContext\Tracking\ApplicationPiwikTracker;
97
use WMDE\Fundraising\Frontend\MembershipContext\Tracking\ApplicationTracker;
98
use WMDE\Fundraising\Frontend\MembershipContext\UseCases\ApplyForMembership\ApplyForMembershipUseCase;
99
use WMDE\Fundraising\Frontend\MembershipContext\UseCases\ApplyForMembership\MembershipApplicationValidator;
100
use WMDE\Fundraising\Frontend\MembershipContext\UseCases\CancelMembershipApplication\CancelMembershipApplicationUseCase;
101
use WMDE\Fundraising\Frontend\MembershipContext\UseCases\ShowMembershipApplicationConfirmation\ShowMembershipApplicationConfirmationUseCase;
102
use WMDE\Fundraising\Frontend\PaymentContext\DataAccess\McpCreditCardService;
103
use WMDE\Fundraising\Frontend\PaymentContext\DataAccess\UniqueTransferCodeGenerator;
104
use WMDE\Fundraising\Frontend\PaymentContext\Domain\BankDataConverter;
105
use WMDE\Fundraising\Frontend\PaymentContext\Domain\SimpleTransferCodeGenerator;
106
use WMDE\Fundraising\Frontend\PaymentContext\Domain\TransferCodeGenerator;
107
use WMDE\Fundraising\Frontend\PaymentContext\Infrastructure\CreditCardService;
108
use WMDE\Fundraising\Frontend\PaymentContext\UseCases\CheckIban\CheckIbanUseCase;
109
use WMDE\Fundraising\Frontend\PaymentContext\UseCases\GenerateIban\GenerateIbanUseCase;
110
use WMDE\Fundraising\Frontend\Presentation\AmountFormatter;
111
use WMDE\Fundraising\Frontend\Presentation\CreditCardUrlConfig;
112
use WMDE\Fundraising\Frontend\Presentation\CreditCardUrlGenerator;
113
use WMDE\Fundraising\Frontend\Presentation\DonationConfirmationPageSelector;
114
use WMDE\Fundraising\Frontend\Presentation\FilePrefixer;
115
use WMDE\Fundraising\Frontend\Presentation\GreetingGenerator;
116
use WMDE\Fundraising\Frontend\Presentation\PayPalUrlConfig;
117
use WMDE\Fundraising\Frontend\Presentation\PayPalUrlGenerator;
118
use WMDE\Fundraising\Frontend\Presentation\Presenters\AddSubscriptionHtmlPresenter;
119
use WMDE\Fundraising\Frontend\Presentation\Presenters\AddSubscriptionJsonPresenter;
120
use WMDE\Fundraising\Frontend\Presentation\Presenters\CancelDonationHtmlPresenter;
121
use WMDE\Fundraising\Frontend\Presentation\Presenters\CancelMembershipApplicationHtmlPresenter;
122
use WMDE\Fundraising\Frontend\Presentation\Presenters\CommentListHtmlPresenter;
123
use WMDE\Fundraising\Frontend\Presentation\Presenters\CommentListJsonPresenter;
124
use WMDE\Fundraising\Frontend\Presentation\Presenters\CommentListRssPresenter;
125
use WMDE\Fundraising\Frontend\Presentation\Presenters\ConfirmSubscriptionHtmlPresenter;
126
use WMDE\Fundraising\Frontend\Presentation\Presenters\CreditCardNotificationPresenter;
127
use WMDE\Fundraising\Frontend\Presentation\Presenters\CreditCardPaymentHtmlPresenter;
128
use WMDE\Fundraising\Frontend\Presentation\Presenters\DonationConfirmationHtmlPresenter;
129
use WMDE\Fundraising\Frontend\Presentation\Presenters\DonationFormPresenter;
130
use WMDE\Fundraising\Frontend\Presentation\Presenters\DonationFormViolationPresenter;
131
use WMDE\Fundraising\Frontend\Presentation\Presenters\GetInTouchHtmlPresenter;
132
use WMDE\Fundraising\Frontend\Presentation\Presenters\IbanPresenter;
133
use WMDE\Fundraising\Frontend\Presentation\Presenters\InternalErrorHtmlPresenter;
134
use WMDE\Fundraising\Frontend\Presentation\Presenters\MembershipApplicationConfirmationHtmlPresenter;
135
use WMDE\Fundraising\Frontend\Presentation\Presenters\MembershipFormViolationPresenter;
136
use WMDE\Fundraising\Frontend\Presentation\TwigTemplate;
137
use WMDE\Fundraising\Frontend\SubscriptionContext\DataAccess\DoctrineSubscriptionRepository;
138
use WMDE\Fundraising\Frontend\SubscriptionContext\Domain\Repositories\SubscriptionRepository;
139
use WMDE\Fundraising\Frontend\SubscriptionContext\Infrastructure\LoggingSubscriptionRepository;
140
use WMDE\Fundraising\Frontend\SubscriptionContext\UseCases\AddSubscription\AddSubscriptionUseCase;
141
use WMDE\Fundraising\Frontend\SubscriptionContext\UseCases\ConfirmSubscription\ConfirmSubscriptionUseCase;
142
use WMDE\Fundraising\Frontend\SubscriptionContext\Validation\SubscriptionDuplicateValidator;
143
use WMDE\Fundraising\Frontend\SubscriptionContext\Validation\SubscriptionValidator;
144
use WMDE\Fundraising\Frontend\Validation\AllowedValuesValidator;
145
use WMDE\Fundraising\Frontend\Validation\AmountPolicyValidator;
146
use WMDE\Fundraising\Frontend\Validation\PaymentDataValidator;
147
use WMDE\Fundraising\Frontend\Validation\BankDataValidator;
148
use WMDE\Fundraising\Frontend\Validation\EmailValidator;
149
use WMDE\Fundraising\Frontend\Validation\GetInTouchValidator;
150
use WMDE\Fundraising\Frontend\Validation\IbanValidator;
151
use WMDE\Fundraising\Frontend\Validation\MembershipFeeValidator;
152
use WMDE\Fundraising\Frontend\Validation\TemplateNameValidator;
153
use WMDE\Fundraising\Frontend\Validation\TextPolicyValidator;
154
use WMDE\Fundraising\ContentProvider\ContentProvider;
155
use WMDE\Fundraising\Store\Factory as StoreFactory;
156
use WMDE\Fundraising\Store\Installer;
157
158
/**
159
 * @licence GNU GPL v2+
160
 */
161
class FunFunFactory {
162
163
	private $config;
164
165
	/**
166
	 * @var Container
167
	 */
168
	private $pimple;
169
170
	private $addDoctrineSubscribers = true;
171
172
	/**
173
	 * @var Stopwatch|null
174
	 */
175
	private $profiler = null;
176
177 160
	public function __construct( array $config ) {
178 160
		$this->config = $config;
179 160
		$this->pimple = $this->newPimple();
180 160
	}
181
182 160
	private function newPimple(): Container {
183 160
		$pimple = new Container();
184
185
		$pimple['logger'] = function() {
186 119
			return new NullLogger();
187
		};
188
189
		$pimple['paypal_logger'] = function() {
190 4
			return new NullLogger();
191
		};
192
193
		$pimple['profiler_data_collector'] = function() {
194
			return new ProfilerDataCollector();
195
		};
196
197
		$pimple['dbal_connection'] = function() {
198 160
			return DriverManager::getConnection( $this->config['db'] );
199
		};
200
201
		$pimple['entity_manager'] = function() {
202 90
			$entityManager = ( new StoreFactory( $this->getConnection(), $this->getVarPath() . '/doctrine_proxies' ) )
203 90
				->getEntityManager();
204 90
			if ( $this->addDoctrineSubscribers ) {
205 90
				$entityManager->getEventManager()->addEventSubscriber( $this->newDoctrineDonationPrePersistSubscriber() );
206 90
				$entityManager->getEventManager()->addEventSubscriber( $this->newDoctrineMembershipApplicationPrePersistSubscriber() );
207
			}
208
209 90
			return $entityManager;
210
		};
211
212
		$pimple['subscription_repository'] = function() {
213 9
			return new LoggingSubscriptionRepository(
214 9
				new DoctrineSubscriptionRepository( $this->getEntityManager() ),
215 9
				$this->getLogger()
216
			);
217
		};
218
219
		$pimple['donation_repository'] = function() {
220 47
			return new LoggingDonationRepository(
221 47
				new DoctrineDonationRepository( $this->getEntityManager() ),
222 47
				$this->getLogger()
223
			);
224
		};
225
226
		$pimple['membership_application_repository'] = function() {
227 14
			return new LoggingApplicationRepository(
228 14
				new DoctrineApplicationRepository( $this->getEntityManager() ),
229 14
				$this->getLogger()
230
			);
231
		};
232
233
		$pimple['comment_repository'] = function() {
234 12
			$finder = new LoggingCommentFinder(
235 12
				new DoctrineCommentFinder( $this->getEntityManager() ),
236 12
				$this->getLogger()
237
			);
238
239 12
			return $this->addProfilingDecorator( $finder, 'CommentFinder' );
240
		};
241
242
		$pimple['mail_validator'] = function() {
243 44
			return new EmailValidator( new InternetDomainNameValidator() );
244
		};
245
246
		$pimple['subscription_validator'] = function() {
247 7
			return new SubscriptionValidator(
248 7
				$this->getEmailValidator(),
249 7
				$this->newTextPolicyValidator( 'fields' ),
250 7
				$this->newSubscriptionDuplicateValidator(),
251 7
				$this->newHonorificValidator()
252
			);
253
		};
254
255
		$pimple['template_name_validator'] = function() {
256 8
			return new TemplateNameValidator( $this->getTwig() );
257
		};
258
259
		$pimple['contact_validator'] = function() {
260 3
			return new GetInTouchValidator( $this->getEmailValidator() );
261
		};
262
263
		$pimple['greeting_generator'] = function() {
264 56
			return new GreetingGenerator();
265
		};
266
267
		$pimple['translator'] = function() {
268 102
			$translationFactory = new TranslationFactory();
269 102
			$loaders = [
270 102
				'json' => $translationFactory->newJsonLoader()
271
			];
272
			$locale = $this->config['locale'];
273
			$messagesPath = $this->getI18nDirectory() . $this->config['translation']['message-dir'];
274
			$translator = $translationFactory->create( $loaders, $locale );
275 102
			foreach ($this->config['translation']['files'] as $domain => $file) {
276 102
				$translator->addResource( 'json', $messagesPath . '/' . $file, $locale, $domain );
277
			}
278 102
279 102
			return $translator;
280
		};
281 102
282 102
		// In the future, this could be locale-specific or filled from a DB table
283 102
		$pimple['honorifics'] = function() {
284
			return new Honorifics( [
285
				'' => 'Kein Titel',
286
				'Dr.' => 'Dr.',
287 102
				'Prof.' => 'Prof.',
288
				'Prof. Dr.' => 'Prof. Dr.'
289
			] );
290
		};
291 114
292
		$pimple['twig_factory'] = function () {
293 114
			return new TwigFactory(
294
				array_merge_recursive(
295 114
					$this->config['twig'],
296 114
					['web-basepath' => $this->config['web-basepath']]
297 114
				),
298 114
				$this->getCachePath() . '/twig',
299 114
				$this->config['locale']
300
			);
301
		};
302
303 114
		$pimple['twig'] = function() {
304 114
			$twigFactory = $this->getTwigFactory();
305 114
			$configurator = $twigFactory->newTwigEnvironmentConfigurator();
306
307 114
			$loaders = array_filter( [
308
				$twigFactory->newFileSystemLoader(),
309
				$twigFactory->newArrayLoader(), // This is just a fallback for testing
310 114
			] );
311 114
			$extensions = [
312 114
				$twigFactory->newTranslationExtension( $this->getTranslator() ),
313
				new Twig_Extensions_Extension_Intl()
314 114
			];
315
			$filters = [
316
				$twigFactory->newFilePrefixFilter(
317 114
					$this->getFilePrefixer()
318 114
				)
319 114
			];
320
			$functions = [
321 114
				new Twig_SimpleFunction(
322
					'web_content',
323
					function( string $name, array $context = [] ) {
324 114
						return $this->getContentProvider()->getWeb( $name, $context );
325 114
					},
326 114
					[ 'is_safe' => [ 'html' ] ]
327
				),
328 114
				new Twig_SimpleFunction(
329
					'mail_content',
330
					function( string $name, array $context = [] ) {
331 114
						return $this->getContentProvider()->getMail( $name, $context );
332
					},
333
					[ 'is_safe' => [ 'all' ] ]
334
				)
335
			];
336 78
337 78
			return $configurator->getEnvironment( $this->pimple['twig_environment'], $loaders, $extensions, $filters, $functions );
338
		};
339
340
		$pimple['messenger_suborganization'] = function() {
341
			return new Messenger(
342
				new Swift_MailTransport(),
0 ignored issues
show
Deprecated Code introduced by
The class Swift_MailTransport has been deprecated with message: since 5.4.5 (to be removed in 6.0)

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
343
				$this->getSubOrganizationEmailAddress(),
344
				$this->config['contact-info']['suborganization']['name']
345 109
			);
346
		};
347
348
		$pimple['messenger_organization'] = function() {
349 109
			return new Messenger(
350 109
				new Swift_MailTransport(),
0 ignored issues
show
Deprecated Code introduced by
The class Swift_MailTransport has been deprecated with message: since 5.4.5 (to be removed in 6.0)

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
351 109
				$this->getOrganizationEmailAddress(),
352 109
				$this->config['contact-info']['organization']['name']
353 109
			);
354 109
		};
355 109
356
		$pimple['confirmation-page-selector'] = function() {
357
			return new DonationConfirmationPageSelector( $this->config['confirmation-pages'] );
358
		};
359 109
360 109
		$pimple['paypal-payment-notification-verifier'] = function() {
361
			return new LoggingPaymentNotificationVerifier(
362
				new PayPalPaymentNotificationVerifier(
363 109
					new Client(),
364 109
					$this->config['paypal-donation']['base-url'],
365
					$this->config['paypal-donation']['account-address']
366
				),
367
				$this->getLogger()
368 109
			);
369
		};
370
371
		$pimple['paypal-membership-fee-notification-verifier'] = function() {
372
			return new LoggingPaymentNotificationVerifier(
373
				new PayPalPaymentNotificationVerifier(
374
					new Client(),
375
					$this->config['paypal-membership']['base-url'],
376
					$this->config['paypal-membership']['account-address']
377
				),
378
				$this->getLogger()
379
			);
380
		};
381
382
		$pimple['credit-card-api-service'] = function() {
383
			return new McpCreditCardService(
384
				new TNvpServiceDispatcher(
385
					'IMcpCreditcardService_v1_5',
386
					'https://sipg.micropayment.de/public/creditcard/v1.5/nvp/'
387
				),
388 6
				$this->config['creditcard']['access-key'],
389
				$this->config['creditcard']['testmode']
390
			);
391
		};
392
393
		$pimple['token_generator'] = function() {
394
			return new RandomTokenGenerator(
395
				$this->config['token-length'],
396
				new \DateInterval( $this->config['token-validity-timestamp'] )
397
			);
398
		};
399
400
		$pimple['page_cache'] = function() {
401
			return new VoidCache();
402
		};
403
404
		$pimple['rendered_page_cache'] = function() {
405
			return new VoidCache();
406
		};
407
408
		$pimple['page_view_tracker'] = function () {
409
			return new PageViewTracker( $this->newServerSideTracker(), $this->config['piwik']['siteUrlBase'] );
410
		};
411
412
		$pimple['cachebusting_fileprefixer'] = function () {
413
			return new FilePrefixer( $this->getFilePrefix() );
414 69
		};
415 69
416 69
		$pimple['content_page_selector'] = function () {
417
			$json = (new SimpleFileFetcher())->fetchFile( $this->getI18nDirectory() . '/data/pages.json' );
418
			$config = json_decode( $json, true ) ?? [];
419
420
			return new PageSelector( $config );
421 112
		};
422
423
		$pimple['content_provider'] = function () {
424
			return new ContentProvider( [
425 109
				'content_path' => $this->getI18nDirectory(),
426
				'cache' => $this->config['twig']['enable-cache'] ? $this->getCachePath() . '/content' : false,
427
				'globals' => [
428
					'basepath' => $this->config['web-basepath']
429
				]
430
			] );
431
		};
432 160
433
		return $pimple;
434
	}
435 160
436 160
	public function getConnection(): Connection {
437
		return $this->pimple['dbal_connection'];
438
	}
439 90
440 90
	public function getEntityManager(): EntityManager {
441
		return $this->pimple['entity_manager'];
442
	}
443 11
444 11
	private function newDonationEventLogger(): DonationEventLogger {
445 11
		return new BestEffortDonationEventLogger(
446 11
			new DoctrineDonationEventLogger( $this->getEntityManager() ),
447
			$this->getLogger()
448
		);
449
	}
450 160
451 160
	public function newInstaller(): Installer {
452
		return ( new StoreFactory( $this->getConnection() ) )->newInstaller();
453
	}
454 12
455 12
	public function newListCommentsUseCase(): ListCommentsUseCase {
456
		return new ListCommentsUseCase( $this->getCommentFinder() );
457
	}
458 6
459 6
	public function newCommentListJsonPresenter(): CommentListJsonPresenter {
460
		return new CommentListJsonPresenter();
461
	}
462 2
463 2
	public function newCommentListRssPresenter(): CommentListRssPresenter {
464 2
		return new CommentListRssPresenter( new TwigTemplate(
465 2
			$this->getTwig(),
466
			'Comment_List.rss.twig'
467
		) );
468
	}
469 4
470 4
	public function newCommentListHtmlPresenter(): CommentListHtmlPresenter {
471
		return new CommentListHtmlPresenter( $this->getLayoutTemplate( 'Comment_List.html.twig', [ 'piwikGoals' => [ 1 ] ] ) );
472
	}
473 12
474 12
	private function getCommentFinder(): CommentFinder {
475
		return $this->pimple['comment_repository'];
476
	}
477 10
478 10
	public function getSubscriptionRepository(): SubscriptionRepository {
479
		return $this->pimple['subscription_repository'];
480
	}
481 1
482 1
	public function setSubscriptionRepository( SubscriptionRepository $subscriptionRepository ) {
483 1
		$this->pimple['subscription_repository'] = $subscriptionRepository;
484
	}
485 7
486 7
	private function getSubscriptionValidator(): SubscriptionValidator {
487
		return $this->pimple['subscription_validator'];
488
	}
489 46
490 46
	public function getEmailValidator(): EmailValidator {
491
		return $this->pimple['mail_validator'];
492
	}
493 8
494 8
	public function getTemplateNameValidator(): TemplateNameValidator {
495
		return $this->pimple['template_name_validator'];
496
	}
497 1
498 1
	public function newAddSubscriptionHtmlPresenter(): AddSubscriptionHtmlPresenter {
499
		return new AddSubscriptionHtmlPresenter( $this->getLayoutTemplate( 'Subscription_Form.html.twig' ), $this->getTranslator() );
500
	}
501 3
502 3
	public function newConfirmSubscriptionHtmlPresenter(): ConfirmSubscriptionHtmlPresenter {
503 3
		return new ConfirmSubscriptionHtmlPresenter(
504 3
			$this->getLayoutTemplate( 'Confirm_Subscription.twig' ),
505
			$this->getTranslator()
506
		);
507
	}
508 3
509 3
	public function newAddSubscriptionJsonPresenter(): AddSubscriptionJsonPresenter {
510
		return new AddSubscriptionJsonPresenter( $this->getTranslator() );
511
	}
512 1
513 1
	public function newGetInTouchHtmlPresenter(): GetInTouchHtmlPresenter {
514
		return new GetInTouchHtmlPresenter( $this->getLayoutTemplate( 'contact_form.html.twig' ), $this->getTranslator() );
515
	}
516 160
517 160
	public function setTwigEnvironment( Twig_Environment $twig ) {
518 160
		$this->pimple['twig_environment'] = $twig;
519
	}
520 109
521 109
	public function getTwig(): Twig_Environment {
522
		return $this->pimple['twig'];
523
	}
524
525
	/**
526
	 * Get a template, with the content for the layout areas filled in.
527
	 *
528
	 * @param string $templateName
529
	 * @param array $context Additional variables for the template
530
	 * @return TwigTemplate
531 43
	 */
532 43
	public function getLayoutTemplate( string $templateName, array $context = [] ): TwigTemplate {
533 43
		 return new TwigTemplate(
534
			$this->getTwig(),
535 43
			$templateName,
536
			array_merge( $this->getDefaultTwigVariables(), $context )
537
		);
538
	}
539
540
	/**
541
	 * Get a layouted template that includes another template
542
	 *
543
	 * @deprecated Change the template to use extend and block and call getLayoutTemplate instead.
544
	 *
545 30
	 * @param string $templateName Template to include
546 30
	 * @return TwigTemplate
547 30
	 */
548 30
	private function getIncludeTemplate( string $templateName, array $context = [] ): TwigTemplate {
549
		return new TwigTemplate(
550 30
			$this->getTwig(),
551 30
			'Include_in_Layout.twig',
552
			array_merge(
553
				$this->getDefaultTwigVariables(),
554
				[ 'main_template' => $templateName ],
555
				$context
556
			)
557 72
		);
558
	}
559 72
560 72
	private function getDefaultTwigVariables() {
561 72
		return [
562 72
			'honorifics' => $this->getHonorifics()->getList(),
563 72
			'header_template' => $this->config['default-layout-templates']['header'],
564 72
			'footer_template' => $this->config['default-layout-templates']['footer'],
565
			'no_js_notice_template' => $this->config['default-layout-templates']['no-js-notice'],
566
			'piwik' => $this->config['piwik'],
567
			'locale' => $this->config['locale'],
568 20
		];
569 20
	}
570 20
571 20
	private function newReferrerGeneralizer() {
572
		return new ReferrerGeneralizer(
573
			$this->config['referrer-generalization']['default'],
574
			$this->config['referrer-generalization']['domain-map']
575 112
		);
576 112
	}
577
578
	public function getLogger(): LoggerInterface {
579 10
		return $this->pimple['logger'];
580 10
	}
581 10
582
	public function getPaypalLogger(): LoggerInterface {
583 102
		return $this->pimple['paypal_logger'];
584 102
	}
585
586
	private function getVarPath(): string {
587 112
		return __DIR__ . '/../../var';
588 112
	}
589 112
590 112
	public function getCachePath(): string {
591
		return $this->getVarPath() . '/cache';
592
	}
593 112
594
	public function getLoggingPath(): string {
595
		return $this->getVarPath() . '/log';
596 109
	}
597 109
598 109
	public function getTemplatePath(): string {
599 109
		return __DIR__ . '/../../app/fundraising-frontend-content/templates';
600
	}
601
602 109
	public function newAddSubscriptionUseCase(): AddSubscriptionUseCase {
603
		return new AddSubscriptionUseCase(
604
			$this->getSubscriptionRepository(),
605 112
			$this->getSubscriptionValidator(),
606 112
			$this->newAddSubscriptionMailer()
607 112
		);
608 112
	}
609 112
610 112
	public function newConfirmSubscriptionUseCase(): ConfirmSubscriptionUseCase {
611 112
		return new ConfirmSubscriptionUseCase(
612
			$this->getSubscriptionRepository(),
613
			$this->newConfirmSubscriptionMailer()
614
		);
615 109
	}
616 109
617 109
	private function newAddSubscriptionMailer(): TemplateMailerInterface {
618 109
		return $this->newTemplateMailer(
619 109
			$this->getSuborganizationMessenger(),
620 109
			new TwigTemplate(
621 109
				$this->getTwig(),
622
				'Mail_Subscription_Request.txt.twig',
623
				[
624
					'greeting_generator' => $this->getGreetingGenerator()
625 119
				]
626 119
			),
627
			'mail_subject_subscription'
628
		);
629 6
	}
630 6
631
	private function newConfirmSubscriptionMailer(): TemplateMailerInterface {
632
		return $this->newTemplateMailer(
633 127
			$this->getSuborganizationMessenger(),
634 127
			new TwigTemplate(
635
					$this->getTwig(),
636
					'Mail_Subscription_Confirmation.txt.twig',
637 109
					[ 'greeting_generator' => $this->getGreetingGenerator() ]
638 109
			),
639
			'mail_subject_subscription_confirmed'
640
		);
641
	}
642
643
	/**
644
	 * Create a new TemplateMailer instance
645
	 *
646
	 * So much decoration going on that explicitly hinting what we return (Robustness principle) would be confusing
647
	 * (you'd expect a TemplateBasedMailer, not a LoggingMailer), so we hint the interface instead.
648
	 */
649 7
	private function newTemplateMailer( Messenger $messenger, TwigTemplate $template, string $messageKey ): TemplateMailerInterface {
650 7
		$mailer = new TemplateBasedMailer(
651 7
			$messenger,
652 7
			$template,
653 7
			$this->getTranslator()->trans( $messageKey )
654
		);
655
656
		$mailer = new LoggingMailer( $mailer, $this->getLogger() );
657 3
658 3
		return $this->addProfilingDecorator( $mailer, 'Mailer' );
659 3
	}
660 3
661
	public function getGreetingGenerator() {
662
		return $this->pimple['greeting_generator'];
663
	}
664 7
665 7
	public function newCheckIbanUseCase(): CheckIbanUseCase {
666 7
		return new CheckIbanUseCase( $this->newBankDataConverter(), $this->newIbanValidator() );
667 7
	}
668 7
669 7
	public function newGenerateIbanUseCase(): GenerateIbanUseCase {
670
		return new GenerateIbanUseCase( $this->newBankDataConverter(), $this->newIbanValidator() );
671 7
	}
672 7
673
	public function newIbanPresenter(): IbanPresenter {
674
		return new IbanPresenter();
675 7
	}
676
677
	public function newBankDataConverter() {
678
		return new BankDataConverter( $this->config['bank-data-file'] );
679 3
	}
680 3
681 3
	public function setSubscriptionValidator( SubscriptionValidator $subscriptionValidator ) {
682 3
		$this->pimple['subscription_validator'] = $subscriptionValidator;
683 3
	}
684 3
685 3
	public function newGetInTouchUseCase() {
686
		return new GetInTouchUseCase(
687 3
			$this->getContactValidator(),
688
			$this->newContactOperatorMailer(),
689
			$this->newContactUserMailer()
690
		);
691 59
	}
692 59
693
	private function newContactUserMailer(): TemplateMailerInterface {
694
		return $this->newTemplateMailer(
695 59
			$this->getSuborganizationMessenger(),
696
			new TwigTemplate( $this->getTwig(), 'Mail_Contact_Confirm_to_User.txt.twig' ),
697
			'mail_subject_getintouch'
698 59
		);
699
	}
700 59
701
	private function newContactOperatorMailer(): OperatorMailer {
702
		return new OperatorMailer(
703 56
			$this->getSuborganizationMessenger(),
704 56
			new TwigTemplate( $this->getTwig(), 'Mail_Contact_Forward_to_Operator.txt.twig' ),
705
			$this->getTranslator()->trans( 'mail_subject_getintouch_forward' )
706
		);
707
	}
708
709
	private function getContactValidator(): GetInTouchValidator {
710
		return $this->pimple['contact_validator'];
711
	}
712
713
	private function newSubscriptionDuplicateValidator(): SubscriptionDuplicateValidator {
714
		return new SubscriptionDuplicateValidator(
715
				$this->getSubscriptionRepository(),
716
				$this->newSubscriptionDuplicateCutoffDate()
717
		);
718
	}
719 31
720 31
	private function newSubscriptionDuplicateCutoffDate(): \DateTime {
721
		$cutoffDateTime = new \DateTime();
722
		$cutoffDateTime->sub( new \DateInterval( $this->config['subscription-interval'] ) );
723
		return $cutoffDateTime;
724
	}
725
726
	private function newHonorificValidator(): AllowedValuesValidator {
727
		return new AllowedValuesValidator( $this->getHonorifics()->getKeys() );
728
	}
729
730
	private function getHonorifics(): Honorifics {
731 3
		return $this->pimple['honorifics'];
732 3
	}
733 3
734 3
	public function newAuthorizedCachePurger(): AuthorizedCachePurger {
735 3
		return new AuthorizedCachePurger(
736
			new AllOfTheCachePurger( $this->getTwig(), $this->getPageCache(), $this->getRenderedPageCache() ),
737
			$this->config['purging-secret']
738
		);
739 3
	}
740 3
741 3
	private function newBankDataValidator(): BankDataValidator {
742 3
		return new BankDataValidator( $this->newIbanValidator() );
743 3
	}
744
745
	private function getSuborganizationMessenger(): Messenger {
746
		return $this->pimple['messenger_suborganization'];
747 3
	}
748 3
749 3
	public function setSuborganizationMessenger( Messenger $messenger ) {
750 3
		$this->pimple['messenger_suborganization'] = $messenger;
751 3
	}
752
753
	private function getOrganizationMessenger(): Messenger {
754
		return $this->pimple['messenger_organization'];
755 3
	}
756 3
757
	public function setOrganizationMessenger( Messenger $messenger ) {
758
		$this->pimple['messenger_organization'] = $messenger;
759 7
	}
760 7
761 7
	public function setNullMessenger() {
762 7
		$this->setSuborganizationMessenger( new Messenger(
763
			Swift_NullTransport::newInstance(),
764
			$this->getSubOrganizationEmailAddress()
765
		) );
766 7
		$this->setOrganizationMessenger( new Messenger(
767 7
			Swift_NullTransport::newInstance(),
768 7
			$this->getOrganizationEmailAddress()
769 7
		) );
770
	}
771
772 7
	public function getSubOrganizationEmailAddress(): EmailAddress {
773 7
		return new EmailAddress( $this->config['contact-info']['suborganization']['email'] );
774
	}
775
776 78
	public function getOrganizationEmailAddress() {
777 78
		return new EmailAddress( $this->config['contact-info']['organization']['email'] );
778
	}
779
780 1
	public function newInternalErrorHtmlPresenter(): InternalErrorHtmlPresenter {
781 1
		return new InternalErrorHtmlPresenter( $this->getIncludeTemplate( 'Error_Page.html.twig' ) );
0 ignored issues
show
Deprecated Code introduced by
The method WMDE\Fundraising\Fronten...y::getIncludeTemplate() has been deprecated with message: Change the template to use extend and block and call getLayoutTemplate instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
782 1
	}
783 1
784
	public function newAccessDeniedHtmlPresenter(): InternalErrorHtmlPresenter {
785
		return new InternalErrorHtmlPresenter( $this->getLayoutTemplate( 'Access_Denied.twig' ) );
786
	}
787 31
788 31
	public function getTranslator(): TranslatorInterface {
789
		return $this->pimple['translator'];
790
	}
791 46
792 46
	public function setTranslator( TranslatorInterface $translator ) {
793
		$this->pimple['translator'] = $translator;
794
	}
795 160
796 160
	public function getTwigFactory(): TwigFactory {
797 160
		return $this->pimple['twig_factory'];
798
	}
799 13
800 13
	private function newTextPolicyValidator( string $policyName ): TextPolicyValidator {
801
		$fetcher = new ErrorLoggingFileFetcher(
802
			new SimpleFileFetcher(),
803 160
			$this->getLogger()
804 160
		);
805 160
		$textPolicyConfig = $this->config['text-policies'][$policyName];
806
		return new TextPolicyValidator(
807 160
			new WordListFileReader(
808 160
				$fetcher,
809 160
				$textPolicyConfig['badwords'] ? $this->getAbsolutePath( $textPolicyConfig['badwords'] ) : ''
810 160
			),
811
			new WordListFileReader(
812 160
				$fetcher,
813 160
				$textPolicyConfig['whitewords'] ? $this->getAbsolutePath( $textPolicyConfig['whitewords'] ) : ''
814 160
			)
815
		);
816 160
	}
817
818 160
	private function newCommentPolicyValidator(): TextPolicyValidator {
819 160
		return $this->newTextPolicyValidator( 'comment' );
820
	}
821
822 160
	public function newCancelDonationUseCase( string $updateToken ): CancelDonationUseCase {
823 160
		return new CancelDonationUseCase(
824
			$this->getDonationRepository(),
825
			$this->newCancelDonationMailer(),
826 3
			$this->newDonationAuthorizer( $updateToken ),
827 3
			$this->newDonationEventLogger()
828
		);
829
	}
830 3
831 3
	private function newCancelDonationMailer(): TemplateMailerInterface {
832
		return $this->newTemplateMailer(
833
			$this->getSuborganizationMessenger(),
834 116
			new TwigTemplate(
835 116
				$this->getTwig(),
836
				'Mail_Donation_Cancellation_Confirmation.txt.twig',
837
				[ 'greeting_generator' => $this->getGreetingGenerator() ]
838 2
			),
839 2
			'mail_subject_confirm_cancellation'
840 2
		);
841
	}
842 109
843 109
	public function newAddDonationUseCase(): AddDonationUseCase {
844
		return new AddDonationUseCase(
845
			$this->getDonationRepository(),
846 41
			$this->newDonationValidator(),
847 41
			$this->newDonationPolicyValidator(),
848 41
			$this->newReferrerGeneralizer(),
849
			$this->newDonationConfirmationMailer(),
850 41
			$this->newBankTransferCodeGenerator(),
851 41
			$this->newDonationTokenFetcher()
852 41
		);
853
	}
854
855
	private function newBankTransferCodeGenerator(): TransferCodeGenerator {
856 3
		return new UniqueTransferCodeGenerator(
857 3
			new SimpleTransferCodeGenerator(),
858
			$this->getEntityManager()
859
		);
860 5
	}
861 5
862 5
	private function newDonationValidator(): AddDonationValidator {
863 5
		return new AddDonationValidator(
864 5
			$this->newPaymentDataValidator(),
865 5
			$this->newBankDataValidator(),
866
			$this->getEmailValidator()
867
		);
868
	}
869 5
870 5
	public function newPersonalInfoValidator(): DonorValidator {
871 5
		return new DonorValidator(
872 5
			new DonorNameValidator(),
873 5
			new DonorAddressValidator(),
874 5
			$this->getEmailValidator()
875 5
		);
876
	}
877 5
878
	private function newDonationConfirmationMailer(): DonationConfirmationMailer {
879
		return new DonationConfirmationMailer(
880
			$this->newTemplateMailer(
881 20
				$this->getSuborganizationMessenger(),
882 20
				new TwigTemplate(
883 20
					$this->getTwig(),
884 20
					'Mail_Donation_Confirmation.txt.twig',
885 20
					[
886 20
						'greeting_generator' => $this->getGreetingGenerator()
887 20
					]
888 20
				),
889 20
				'mail_subject_confirm_donation'
890
			)
891
		);
892
	}
893 20
894 20
	public function newPayPalUrlGeneratorForDonations() {
895 20
		return new PayPalUrlGenerator( $this->getPayPalUrlConfigForDonations() );
896 20
	}
897
898
	public function newPayPalUrlGeneratorForMembershipApplications() {
899
		return new PayPalUrlGenerator( $this->getPayPalUrlConfigForMembershipApplications() );
900 20
	}
901 20
902 20
	private function getPayPalUrlConfigForDonations() {
903 20
		return PayPalUrlConfig::newFromConfig( $this->config['paypal-donation'] );
904 20
	}
905
906
	private function getPayPalUrlConfigForMembershipApplications() {
907
		return PayPalUrlConfig::newFromConfig( $this->config['paypal-membership'] );
908 2
	}
909 2
910 2
	private function newCreditCardUrlGenerator() {
911 2
		return new CreditCardUrlGenerator( $this->newCreditCardUrlConfig() );
912 2
	}
913
914
	private function newCreditCardUrlConfig() {
915
		return CreditCardUrlConfig::newFromConfig( $this->config['creditcard'] );
916 28
	}
917 28
918 28
	public function getDonationRepository(): DonationRepository {
919 28
		return $this->pimple['donation_repository'];
920 28
	}
921 28
922 28
	public function newPaymentDataValidator(): PaymentDataValidator {
923
		return new PaymentDataValidator( $this->config['donation-minimum-amount'], $this->config['donation-maximum-amount'] );
924 28
	}
925 28
926
	private function newAmountFormatter(): AmountFormatter {
927
		return new AmountFormatter( $this->config['locale'] );
928 28
	}
929
930
	public function newDecimalNumberFormatter(): NumberFormatter {
931
		return new NumberFormatter( $this->config['locale'], NumberFormatter::DECIMAL );
932
	}
933 2
934 2
	public function newAddCommentUseCase( string $updateToken ): AddCommentUseCase {
935
		return new AddCommentUseCase(
936
			$this->getDonationRepository(),
937 2
			$this->newDonationAuthorizer( $updateToken ),
938 2
			$this->newCommentPolicyValidator(),
939
			$this->newAddCommentValidator()
940
		);
941 2
	}
942 2
943
	private function newDonationAuthorizer( string $updateToken = null, string $accessToken = null ): DonationAuthorizer {
944
		return new DoctrineDonationAuthorizer(
945 2
			$this->getEntityManager(),
946 2
			$updateToken,
947
			$accessToken
948
		);
949 3
	}
950 3
951
	public function getTokenGenerator(): TokenGenerator {
952
		return $this->pimple['token_generator'];
953 3
	}
954 3
955
	public function newDonationConfirmationPresenter() {
956
		return new DonationConfirmationHtmlPresenter(
957 47
			$this->getIncludeTemplate( 'Donation_Confirmation.html.twig', [ 'piwikGoals' => [ 3 ] ] )
0 ignored issues
show
Deprecated Code introduced by
The method WMDE\Fundraising\Fronten...y::getIncludeTemplate() has been deprecated with message: Change the template to use extend and block and call getLayoutTemplate instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
958 47
		);
959
	}
960
961 36
	public function newCreditCardPaymentHtmlPresenter() {
962 36
		return new CreditCardPaymentHtmlPresenter(
963
			$this->getIncludeTemplate( 'Credit_Card_Payment_Iframe.html.twig' ),
0 ignored issues
show
Deprecated Code introduced by
The method WMDE\Fundraising\Fronten...y::getIncludeTemplate() has been deprecated with message: Change the template to use extend and block and call getLayoutTemplate instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
964
			$this->getTranslator(),
965 19
			$this->newCreditCardUrlGenerator()
966 19
		);
967
	}
968
969 2
	public function newCancelDonationHtmlPresenter() {
970 2
		return new CancelDonationHtmlPresenter(
971
			$this->getIncludeTemplate( 'Donation_Cancellation_Confirmation.html.twig' )
0 ignored issues
show
Deprecated Code introduced by
The method WMDE\Fundraising\Fronten...y::getIncludeTemplate() has been deprecated with message: Change the template to use extend and block and call getLayoutTemplate instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
972
		);
973 3
	}
974 3
975 3
	public function newApplyForMembershipUseCase(): ApplyForMembershipUseCase {
976 3
		return new ApplyForMembershipUseCase(
977 3
			$this->getMembershipApplicationRepository(),
978 3
			$this->newMembershipApplicationTokenFetcher(),
979
			$this->newApplyForMembershipMailer(),
980
			$this->newMembershipApplicationValidator(),
981
			$this->newApplyForMembershipPolicyValidator(),
982 29
			$this->newMembershipApplicationTracker(),
983 29
			$this->newMembershipApplicationPiwikTracker()
984 29
		);
985
	}
986
987
	private function newApplyForMembershipMailer(): TemplateMailerInterface {
988
		return $this->newTemplateMailer(
989
			$this->getOrganizationMessenger(),
990 90
			new TwigTemplate(
991 90
				$this->getTwig(),
992
				'Mail_Membership_Application_Confirmation.txt.twig',
993
				[ 'greeting_generator' => $this->getGreetingGenerator() ]
994 10
			),
995 10
			'mail_subject_confirm_membership_application'
996 10
		);
997
	}
998
999
	private function newMembershipApplicationValidator(): MembershipApplicationValidator {
1000 3
		return new MembershipApplicationValidator(
1001 3
			new MembershipFeeValidator(),
1002 3
			$this->newBankDataValidator(),
1003 3
			$this->getEmailValidator()
1004 3
		);
1005
	}
1006
1007
	private function newMembershipApplicationTracker(): ApplicationTracker {
1008 5
		return new DoctrineApplicationTracker( $this->getEntityManager() );
1009 5
	}
1010 5
1011
	private function newMembershipApplicationPiwikTracker(): ApplicationPiwikTracker {
1012
		return new DoctrineApplicationPiwikTracker( $this->getEntityManager() );
1013
	}
1014 11
1015 11
	private function newApplyForMembershipPolicyValidator(): ApplyForMembershipPolicyValidator {
1016 11
		return new ApplyForMembershipPolicyValidator(
1017 11
			$this->newTextPolicyValidator( 'fields' ),
1018 11
			$this->config['email-address-blacklist']
1019 11
		);
1020 11
	}
1021 11
1022 11
	public function newCancelMembershipApplicationUseCase( string $updateToken ): CancelMembershipApplicationUseCase {
1023
		return new CancelMembershipApplicationUseCase(
1024
			$this->newMembershipApplicationAuthorizer( $updateToken ),
1025
			$this->getMembershipApplicationRepository(),
1026 11
			$this->newCancelMembershipApplicationMailer()
1027 11
		);
1028 11
	}
1029 11
1030 11
	private function newMembershipApplicationAuthorizer(
1031 11
		string $updateToken = null, string $accessToken = null ): ApplicationAuthorizer {
1032 11
1033
		return new DoctrineApplicationAuthorizer(
1034 11
			$this->getEntityManager(),
1035
			$updateToken,
1036
			$accessToken
1037
		);
1038 11
	}
1039 11
1040 11
	public function getMembershipApplicationRepository(): ApplicationRepository {
1041 11
		return $this->pimple['membership_application_repository'];
1042 11
	}
1043
1044
	private function newCancelMembershipApplicationMailer(): TemplateMailerInterface {
1045
		return $this->newTemplateMailer(
1046 11
			$this->getOrganizationMessenger(),
1047 11
			new TwigTemplate(
1048
				$this->getTwig(),
1049
				'Mail_Membership_Application_Cancellation_Confirmation.txt.twig',
1050 11
				[ 'greeting_generator' => $this->getGreetingGenerator() ]
1051 11
			),
1052
			'mail_subject_confirm_membership_application_cancellation'
1053
		);
1054 11
	}
1055 11
1056
	public function newMembershipApplicationConfirmationUseCase( string $accessToken ) {
1057
		return new ShowMembershipApplicationConfirmationUseCase(
1058 2
			$this->newMembershipApplicationAuthorizer( null, $accessToken ), $this->getMembershipApplicationRepository(),
1059 2
			$this->newMembershipApplicationTokenFetcher()
1060 2
		);
1061 2
	}
1062 2
1063
	public function newShowDonationConfirmationUseCase( string $accessToken ): ShowDonationConfirmationUseCase {
1064
		return new ShowDonationConfirmationUseCase(
1065
			$this->newDonationAuthorizer( null, $accessToken ),
1066 3
			$this->newDonationTokenFetcher(),
1067
			$this->getDonationRepository()
1068
		);
1069 3
	}
1070 3
1071
	public function setDonationConfirmationPageSelector( DonationConfirmationPageSelector $selector ) {
1072
		$this->pimple['confirmation-page-selector'] = $selector;
1073
	}
1074
1075
	public function getDonationConfirmationPageSelector(): DonationConfirmationPageSelector {
1076 14
		return $this->pimple['confirmation-page-selector'];
1077 14
	}
1078
1079
	public function newDonationFormViolationPresenter() {
1080 2
		// TODO make the template name dependent on the 'form' value from the HTTP POST request
1081 2
		// (we need different form pages for A/B testing)
1082 2
		$template = $this->getLayoutTemplate( 'Donation_Form.html.twig' );
1083 2
		return new DonationFormViolationPresenter( $template, $this->newAmountFormatter() );
1084 2
	}
1085 2
1086 2
	public function newDonationFormPresenter() {
1087
		// TODO make the template name dependent on the 'form' value from the HTTP POST request
1088 2
		// (we need different form pages for A/B testing)
1089
		$template = $this->getLayoutTemplate( 'Donation_Form.html.twig' );
1090
		return new DonationFormPresenter( $template, $this->newAmountFormatter() );
1091
	}
1092 1
1093 1
	public function newHandlePayPalPaymentNotificationUseCase( string $updateToken ) {
1094 1
		return new HandlePayPalPaymentNotificationUseCase(
1095 1
			$this->getDonationRepository(),
1096
			$this->newDonationAuthorizer( $updateToken ),
1097
			$this->newDonationConfirmationMailer(),
1098
			$this->newDonationEventLogger()
1099 13
		);
1100 13
	}
1101 13
1102 13
	public function newMembershipApplicationSubscriptionSignupNotificationUseCase( string $updateToken ) {
1103 13
		return new HandleSubscriptionSignupNotificationUseCase(
1104
			$this->getMembershipApplicationRepository(),
1105
			$this->newMembershipApplicationAuthorizer( $updateToken ),
1106
			$this->newApplyForMembershipMailer(),
1107 7
			$this->getLogger()
1108 7
		);
1109 7
	}
1110
1111 10
	public function newMembershipApplicationSubscriptionPaymentNotificationUseCase( string $updateToken ) {
1112 10
		return new HandleSubscriptionPaymentNotificationUseCase(
1113
			$this->getMembershipApplicationRepository(),
1114
			$this->newMembershipApplicationAuthorizer( $updateToken ),
1115 4
			$this->newApplyForMembershipMailer(),
1116
			$this->getLogger()
1117
		);
1118 4
	}
1119 4
1120
	public function getPayPalPaymentNotificationVerifier(): PaymentNotificationVerifier {
1121
		return $this->pimple['paypal-payment-notification-verifier'];
1122 15
	}
1123
1124
	public function setPayPalPaymentNotificationVerifier( PaymentNotificationVerifier $verifier ) {
1125 15
		$this->pimple['paypal-payment-notification-verifier'] = $verifier;
1126 15
	}
1127
1128
	public function getPayPalMembershipFeeNotificationVerifier(): PaymentNotificationVerifier {
1129 4
		return $this->pimple['paypal-membership-fee-notification-verifier'];
1130 4
	}
1131 4
1132 4
	public function setPayPalMembershipFeeNotificationVerifier( PaymentNotificationVerifier $verifier ) {
1133 4
		$this->pimple['paypal-membership-fee-notification-verifier'] = $verifier;
1134 4
	}
1135
1136
	public function newCreditCardNotificationUseCase( string $updateToken ) {
1137
		return new CreditCardNotificationUseCase(
1138 7
			$this->getDonationRepository(),
1139 7
			$this->newDonationAuthorizer( $updateToken ),
1140
			$this->getCreditCardService(),
1141
			$this->newDonationConfirmationMailer(),
1142 7
			$this->getLogger(),
1143 7
			$this->newDonationEventLogger()
1144 7
		);
1145
	}
1146 2
1147 2
	public function newCancelMembershipApplicationHtmlPresenter() {
1148 2
		return new CancelMembershipApplicationHtmlPresenter(
1149 2
			$this->getIncludeTemplate( 'Membership_Application_Cancellation_Confirmation.html.twig' )
0 ignored issues
show
Deprecated Code introduced by
The method WMDE\Fundraising\Fronten...y::getIncludeTemplate() has been deprecated with message: Change the template to use extend and block and call getLayoutTemplate instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
1150 2
		);
1151 2
	}
1152 2
1153 2
	public function newMembershipApplicationConfirmationHtmlPresenter() {
1154
		return new MembershipApplicationConfirmationHtmlPresenter(
1155
			$this->getIncludeTemplate( 'Membership_Application_Confirmation.html.twig' )
0 ignored issues
show
Deprecated Code introduced by
The method WMDE\Fundraising\Fronten...y::getIncludeTemplate() has been deprecated with message: Change the template to use extend and block and call getLayoutTemplate instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
1156
		);
1157 2
	}
1158 2
1159 2
	public function newMembershipFormViolationPresenter() {
1160
		return new MembershipFormViolationPresenter(
1161
			$this->getLayoutTemplate( 'Membership_Application.html.twig' )
1162
		);
1163 1
	}
1164 1
1165 1
	public function setCreditCardService( CreditCardService $ccService ) {
1166
		$this->pimple['credit-card-api-service'] = $ccService;
1167
	}
1168
1169 2
	public function getCreditCardService(): CreditCardService {
1170 2
		return $this->pimple['credit-card-api-service'];
1171 2
	}
1172
1173
	public function newCreditCardNotificationPresenter(): CreditCardNotificationPresenter {
1174
		return new CreditCardNotificationPresenter(
1175 2
			new TwigTemplate(
1176 2
				$this->getTwig(),
1177 2
				'Credit_Card_Payment_Notification.txt.twig',
1178
				[ 'returnUrl' => $this->config['creditcard']['return-url'] ]
1179 2
			)
1180 2
		);
1181
	}
1182
1183 2
	private function newDoctrineDonationPrePersistSubscriber(): DoctrineDonationPrePersistSubscriber {
1184 2
		$tokenGenerator = $this->getTokenGenerator();
1185 2
		return new DoctrineDonationPrePersistSubscriber(
1186 2
			$tokenGenerator,
1187 2
			$tokenGenerator
1188 2
		);
1189
	}
1190
1191
	private function newDoctrineMembershipApplicationPrePersistSubscriber(): DoctrineMembershipApplicationPrePersistSubscriber {
1192
		$tokenGenerator = $this->getTokenGenerator();
1193 90
		return new DoctrineMembershipApplicationPrePersistSubscriber(
1194 90
			$tokenGenerator,
1195 90
			$tokenGenerator
1196
		);
1197
	}
1198
1199
	public function setTokenGenerator( TokenGenerator $tokenGenerator ) {
1200
		$this->pimple['token_generator'] = $tokenGenerator;
1201 90
	}
1202 90
1203 90
	public function disableDoctrineSubscribers() {
1204
		$this->addDoctrineSubscribers = false;
1205
	}
1206
1207
	private function newDonationTokenFetcher(): DonationTokenFetcher {
1208
		return new DoctrineDonationTokenFetcher(
1209 21
			$this->getEntityManager()
1210 21
		);
1211 21
	}
1212
1213
	private function newMembershipApplicationTokenFetcher(): ApplicationTokenFetcher {
1214
		return new DoctrineApplicationTokenFetcher(
1215
			$this->getEntityManager()
1216
		);
1217 30
	}
1218 30
1219 30
	private function newDonationPolicyValidator(): AddDonationPolicyValidator {
1220
		return new AddDonationPolicyValidator(
1221
			$this->newDonationAmountPolicyValidator(),
1222
			$this->newTextPolicyValidator( 'fields' ),
1223 12
			$this->config['email-address-blacklist']
1224 12
		);
1225 12
	}
1226
1227
	private function newDonationAmountPolicyValidator(): AmountPolicyValidator {
1228
		// in the future, this might come from the configuration
1229 20
		return new AmountPolicyValidator( 1000, 1000 );
1230 20
	}
1231 20
1232 20
	public function getDonationTimeframeLimit() {
1233
		return $this->config['donation-timeframe-limit'];
1234
	}
1235
1236 20
	public function newSystemMessageResponse( string $message ) {
1237
		$test = $this->getIncludeTemplate( 'System_Message.html.twig' );
0 ignored issues
show
Deprecated Code introduced by
The method WMDE\Fundraising\Fronten...y::getIncludeTemplate() has been deprecated with message: Change the template to use extend and block and call getLayoutTemplate instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
1238 20
		return $test->render( [ 'message' => $message ] );
1239
	}
1240
1241 2
	public function getMembershipApplicationTimeframeLimit() {
1242 2
		return $this->config['membership-application-timeframe-limit'];
1243
	}
1244
1245 2
	private function newAddCommentValidator(): AddCommentValidator {
1246 2
		return new AddCommentValidator();
1247 2
	}
1248
1249
	private function getPageCache(): Cache {
1250 2
		return $this->pimple['page_cache'];
1251 2
	}
1252
1253
	private function getRenderedPageCache(): Cache {
1254 3
		return $this->pimple['rendered_page_cache'];
1255 3
	}
1256
1257
	public function enablePageCache() {
1258 112
		$this->pimple['page_cache'] = function() {
1259 112
			return new FilesystemCache( $this->getCachePath() . '/pages/raw' );
1260
		};
1261
1262 109
		$this->pimple['rendered_page_cache'] = function() {
1263 109
			return new FilesystemCache( $this->getCachePath() . '/pages/rendered' );
1264
		};
1265
	}
1266
1267
	private function addProfilingDecorator( $objectToDecorate, string $profilingLabel ) {
1268
		if ( $this->profiler === null ) {
1269
			return $objectToDecorate;
1270
		}
1271
1272
		$builder = new ProfilingDecoratorBuilder( $this->profiler, $this->getProfilerDataCollector() );
1273
1274
		return $builder->decorate( $objectToDecorate, $profilingLabel );
1275
	}
1276 118
1277 118
	public function setProfiler( Stopwatch $profiler ) {
1278 118
		$this->profiler = $profiler;
1279
	}
1280
1281
	public function setEmailValidator( EmailValidator $validator ) {
1282
		$this->pimple['mail_validator'] = $validator;
1283
	}
1284
1285
	public function setLogger( LoggerInterface $logger ) {
1286
		$this->pimple['logger'] = $logger;
1287
	}
1288
1289
	public function setPaypalLogger( LoggerInterface $logger ) {
1290 2
		$this->pimple['paypal_logger'] = $logger;
1291 2
	}
1292 2
1293
	public function getProfilerDataCollector(): ProfilerDataCollector {
1294
		return $this->pimple['profiler_data_collector'];
1295
	}
1296
1297
	private function newIbanValidator(): IbanValidator {
1298 2
		return new IbanValidator( $this->newBankDataConverter(), $this->config['banned-ibans'] );
1299 2
	}
1300 2
1301
	public function setFilePrefixer( FilePrefixer $prefixer ): void {
1302
		$this->pimple['cachebusting_fileprefixer'] = $prefixer;
1303
	}
1304
1305
	private function getFilePrefixer(): FilePrefixer {
1306 31
		return $this->pimple['cachebusting_fileprefixer'];
1307 31
	}
1308
1309
	private function getFilePrefix(): string {
1310 109
		$prefixContentFile = $this->getVarPath() . '/file_prefix.txt';
1311 109
		if ( !file_exists( $prefixContentFile ) ) {
1312
			return '';
1313
		}
1314 109
		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...
1315 109
	}
1316 109
1317 109
	public function newDonationAcceptedEventHandler( string $updateToken ): DonationAcceptedEventHandler {
1318
		return new DonationAcceptedEventHandler(
1319
			$this->newDonationAuthorizer( $updateToken ),
1320
			$this->getDonationRepository(),
1321
			$this->newDonationConfirmationMailer()
1322 2
		);
1323 2
	}
1324 2
1325 2
	public function newPageNotFoundHtmlPresenter(): PageNotFoundPresenter {
1326 2
		return new PageNotFoundPresenter( $this->getLayoutTemplate( 'Page_not_found.html.twig' ) );
1327
	}
1328
1329
	public function setPageViewTracker( PageViewTracker $tracker ) {
1330 11
		$this->pimple['page_view_tracker'] = function () use ( $tracker )  {
1331 11
			return $tracker;
1332
		};
1333
	}
1334
1335 1
	public function getPageViewTracker(): PageViewTracker {
1336 1
		return $this->pimple['page_view_tracker'];
1337
	}
1338 2
1339
	public function newServerSideTracker(): ServerSideTracker {
1340 1
		// the "https:" prefix does NOT get any slashes because baseURL is stored in a protocol-agnostic way
1341 1
		// (e.g. "//tracking.wikimedia.de" )
1342
		return new PiwikServerSideTracker(
1343
			new \PiwikTracker( $this->config['piwik']['siteId'], 'https:' . $this->config['piwik']['baseUrl'] )
1344
		);
1345
	}
1346
1347
	public function getI18nDirectory(): string {
1348
		return $this->getAbsolutePath( $this->config['i18n-base-path'] ) . '/' . $this->config['locale'];
1349
	}
1350
1351
	/**
1352
	 * If the pathname does not start with a slash, make the path absolute to root dir of application
1353
	 */
1354
	private function getAbsolutePath( string $path ): string {
1355
		if ( $path[0] === '/' ) {
1356
			return $path;
1357
		}
1358
		return __DIR__ . '/../../' . $path;
1359
	}
1360
1361
	public function setContentPagePageSelector( PageSelector $pageSelector ): void {
1362
		$this->pimple['content_page_selector'] = $pageSelector;
1363
	}
1364
1365
	public function getContentPagePageSelector(): PageSelector {
1366
		return $this->pimple['content_page_selector'];
1367
	}
1368
1369
	public function setContentProvider( ContentProvider $contentProvider ): void {
1370
		$this->pimple['content_provider'] = $contentProvider;
1371
	}
1372
1373
	private function getContentProvider(): ContentProvider {
1374
		return $this->pimple['content_provider'];
1375
	}
1376
1377
	public function newMailTemplateFilenameTraversable(): MailTemplateFilenameTraversable {
1378
		return new MailTemplateFilenameTraversable(
1379
			$this->config['twig']['loaders']['filesystem']['template-dir']
1380
		);
1381
	}
1382
1383
}
1384