Completed
Push — master ( 919a96...568a86 )
by wiese
73:55 queued 09:12
created

FunFunFactory::getRenderedPageCache()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\Fundraising\Frontend\Factories;
6
7
use Doctrine\Common\Cache\Cache;
8
use Doctrine\Common\Cache\FilesystemCache;
9
use Doctrine\Common\Cache\VoidCache;
10
use Doctrine\DBAL\Connection;
11
use Doctrine\DBAL\DriverManager;
12
use Doctrine\ORM\EntityManager;
13
use 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\PaymentContext\Domain\DefaultPaymentDelayCalculator;
39
use WMDE\Fundraising\Frontend\PaymentContext\Domain\Model\PaymentType;
40
use WMDE\Fundraising\Frontend\PaymentContext\Domain\PaymentDelayCalculator;
41
use WMDE\Fundraising\Frontend\Presentation\ContentPage\PageSelector;
42
use WMDE\Fundraising\Frontend\Presentation\Honorifics;
43
use WMDE\Fundraising\Frontend\Presentation\Presenters\PageNotFoundPresenter;
44
use WMDE\Fundraising\Frontend\Presentation\SofortUrlConfig;
45
use WMDE\Fundraising\Frontend\Presentation\SofortUrlGenerator;
46
use WMDE\Fundraising\Frontend\Infrastructure\Sofort\Transfer\Client as SofortClient;
47
use WMDE\Fundraising\Frontend\UseCases\GetInTouch\GetInTouchUseCase;
48
use WMDE\Fundraising\Frontend\Infrastructure\Cache\AuthorizedCachePurger;
49
use WMDE\Fundraising\Frontend\DonationContext\Authorization\DonationAuthorizer;
50
use WMDE\Fundraising\Frontend\DonationContext\Authorization\DonationTokenFetcher;
51
use WMDE\Fundraising\Frontend\DonationContext\DataAccess\DoctrineCommentFinder;
52
use WMDE\Fundraising\Frontend\DonationContext\DataAccess\DoctrineDonationAuthorizer;
53
use WMDE\Fundraising\Frontend\DonationContext\DataAccess\DoctrineDonationEventLogger;
54
use WMDE\Fundraising\Frontend\DonationContext\DataAccess\DoctrineDonationPrePersistSubscriber;
55
use WMDE\Fundraising\Frontend\DonationContext\DataAccess\DoctrineDonationRepository;
56
use WMDE\Fundraising\Frontend\DonationContext\DataAccess\DoctrineDonationTokenFetcher;
57
use WMDE\Fundraising\Frontend\DonationContext\Domain\Repositories\CommentFinder;
58
use WMDE\Fundraising\Frontend\DonationContext\Domain\Repositories\DonationRepository;
59
use WMDE\Fundraising\Frontend\DonationContext\Infrastructure\BestEffortDonationEventLogger;
60
use WMDE\Fundraising\Frontend\DonationContext\Infrastructure\DonationConfirmationMailer;
61
use WMDE\Fundraising\Frontend\DonationContext\Infrastructure\DonationEventLogger;
62
use WMDE\Fundraising\Frontend\DonationContext\Infrastructure\LoggingCommentFinder;
63
use WMDE\Fundraising\Frontend\DonationContext\Infrastructure\LoggingDonationRepository;
64
use WMDE\Fundraising\Frontend\DonationContext\UseCases\AddComment\AddCommentUseCase;
65
use WMDE\Fundraising\Frontend\DonationContext\UseCases\AddComment\AddCommentValidator;
66
use WMDE\Fundraising\Frontend\DonationContext\UseCases\AddDonation\AddDonationPolicyValidator;
67
use WMDE\Fundraising\Frontend\DonationContext\UseCases\AddDonation\AddDonationUseCase;
68
use WMDE\Fundraising\Frontend\DonationContext\UseCases\AddDonation\AddDonationValidator;
69
use WMDE\Fundraising\Frontend\DonationContext\UseCases\AddDonation\ReferrerGeneralizer;
70
use WMDE\Fundraising\Frontend\DonationContext\UseCases\CancelDonation\CancelDonationUseCase;
71
use WMDE\Fundraising\Frontend\DonationContext\UseCases\CreditCardPaymentNotification\CreditCardNotificationUseCase;
72
use WMDE\Fundraising\Frontend\DonationContext\UseCases\HandlePayPalPaymentNotification\HandlePayPalPaymentNotificationUseCase;
73
use WMDE\Fundraising\Frontend\DonationContext\UseCases\ListComments\ListCommentsUseCase;
74
use WMDE\Fundraising\Frontend\DonationContext\UseCases\ShowDonationConfirmation\ShowDonationConfirmationUseCase;
75
use WMDE\Fundraising\Frontend\DonationContext\Validation\DonorAddressValidator;
76
use WMDE\Fundraising\Frontend\DonationContext\Validation\DonorNameValidator;
77
use WMDE\Fundraising\Frontend\DonationContext\Validation\DonorValidator;
78
use WMDE\Fundraising\Frontend\Infrastructure\InternetDomainNameValidator;
79
use WMDE\Fundraising\Frontend\Infrastructure\LoggingMailer;
80
use WMDE\Fundraising\Frontend\Infrastructure\LoggingPaymentNotificationVerifier;
81
use WMDE\Fundraising\Frontend\Infrastructure\Messenger;
82
use WMDE\Fundraising\Frontend\Infrastructure\OperatorMailer;
83
use WMDE\Fundraising\Frontend\Infrastructure\PaymentNotificationVerifier;
84
use WMDE\Fundraising\Frontend\Infrastructure\PayPalPaymentNotificationVerifier;
85
use WMDE\Fundraising\Frontend\Infrastructure\ProfilerDataCollector;
86
use WMDE\Fundraising\Frontend\Infrastructure\ProfilingDecoratorBuilder;
87
use WMDE\Fundraising\Frontend\Infrastructure\RandomTokenGenerator;
88
use WMDE\Fundraising\Frontend\Infrastructure\TemplateBasedMailer;
89
use WMDE\Fundraising\Frontend\Infrastructure\TemplateMailerInterface;
90
use WMDE\Fundraising\Frontend\Infrastructure\TokenGenerator;
91
use WMDE\Fundraising\Frontend\MembershipContext\Authorization\ApplicationAuthorizer;
92
use WMDE\Fundraising\Frontend\MembershipContext\Authorization\ApplicationTokenFetcher;
93
use WMDE\Fundraising\Frontend\MembershipContext\DataAccess\DoctrineApplicationAuthorizer;
94
use WMDE\Fundraising\Frontend\MembershipContext\DataAccess\DoctrineApplicationPiwikTracker;
95
use WMDE\Fundraising\Frontend\MembershipContext\DataAccess\DoctrineApplicationRepository;
96
use WMDE\Fundraising\Frontend\MembershipContext\DataAccess\DoctrineApplicationTokenFetcher;
97
use WMDE\Fundraising\Frontend\MembershipContext\DataAccess\DoctrineApplicationTracker;
98
use WMDE\Fundraising\Frontend\MembershipContext\DataAccess\DoctrineMembershipApplicationPrePersistSubscriber;
99
use WMDE\Fundraising\Frontend\MembershipContext\Domain\Model\EmailAddress;
100
use WMDE\Fundraising\Frontend\MembershipContext\Domain\Repositories\ApplicationRepository;
101
use WMDE\Fundraising\Frontend\MembershipContext\Infrastructure\LoggingApplicationRepository;
102
use WMDE\Fundraising\Frontend\MembershipContext\Tracking\ApplicationPiwikTracker;
103
use WMDE\Fundraising\Frontend\MembershipContext\Tracking\ApplicationTracker;
104
use WMDE\Fundraising\Frontend\MembershipContext\UseCases\ApplyForMembership\ApplyForMembershipUseCase;
105
use WMDE\Fundraising\Frontend\MembershipContext\UseCases\ApplyForMembership\MembershipApplicationValidator;
106
use WMDE\Fundraising\Frontend\MembershipContext\UseCases\CancelMembershipApplication\CancelMembershipApplicationUseCase;
107
use WMDE\Fundraising\Frontend\MembershipContext\UseCases\ShowMembershipApplicationConfirmation\ShowMembershipApplicationConfirmationUseCase;
108
use WMDE\Fundraising\Frontend\PaymentContext\DataAccess\McpCreditCardService;
109
use WMDE\Fundraising\Frontend\PaymentContext\DataAccess\UniqueTransferCodeGenerator;
110
use WMDE\Fundraising\Frontend\PaymentContext\Domain\BankDataConverter;
111
use WMDE\Fundraising\Frontend\PaymentContext\Domain\SimpleTransferCodeGenerator;
112
use WMDE\Fundraising\Frontend\PaymentContext\Domain\TransferCodeGenerator;
113
use WMDE\Fundraising\Frontend\PaymentContext\Infrastructure\CreditCardService;
114
use WMDE\Fundraising\Frontend\PaymentContext\UseCases\CheckIban\CheckIbanUseCase;
115
use WMDE\Fundraising\Frontend\PaymentContext\UseCases\GenerateIban\GenerateIbanUseCase;
116
use WMDE\Fundraising\Frontend\Presentation\AmountFormatter;
117
use WMDE\Fundraising\Frontend\Presentation\CreditCardUrlConfig;
118
use WMDE\Fundraising\Frontend\Presentation\CreditCardUrlGenerator;
119
use WMDE\Fundraising\Frontend\Presentation\DonationConfirmationPageSelector;
120
use WMDE\Fundraising\Frontend\Presentation\FilePrefixer;
121
use WMDE\Fundraising\Frontend\Presentation\GreetingGenerator;
122
use WMDE\Fundraising\Frontend\Presentation\PayPalUrlConfig;
123
use WMDE\Fundraising\Frontend\Presentation\PayPalUrlGenerator;
124
use WMDE\Fundraising\Frontend\Presentation\Presenters\AddSubscriptionHtmlPresenter;
125
use WMDE\Fundraising\Frontend\Presentation\Presenters\AddSubscriptionJsonPresenter;
126
use WMDE\Fundraising\Frontend\Presentation\Presenters\CancelDonationHtmlPresenter;
127
use WMDE\Fundraising\Frontend\Presentation\Presenters\CancelMembershipApplicationHtmlPresenter;
128
use WMDE\Fundraising\Frontend\Presentation\Presenters\CommentListHtmlPresenter;
129
use WMDE\Fundraising\Frontend\Presentation\Presenters\CommentListJsonPresenter;
130
use WMDE\Fundraising\Frontend\Presentation\Presenters\CommentListRssPresenter;
131
use WMDE\Fundraising\Frontend\Presentation\Presenters\ConfirmSubscriptionHtmlPresenter;
132
use WMDE\Fundraising\Frontend\Presentation\Presenters\CreditCardNotificationPresenter;
133
use WMDE\Fundraising\Frontend\Presentation\Presenters\CreditCardPaymentHtmlPresenter;
134
use WMDE\Fundraising\Frontend\Presentation\Presenters\DonationConfirmationHtmlPresenter;
135
use WMDE\Fundraising\Frontend\Presentation\Presenters\DonationFormPresenter;
136
use WMDE\Fundraising\Frontend\Presentation\Presenters\DonationFormViolationPresenter;
137
use WMDE\Fundraising\Frontend\Presentation\Presenters\GetInTouchHtmlPresenter;
138
use WMDE\Fundraising\Frontend\Presentation\Presenters\IbanPresenter;
139
use WMDE\Fundraising\Frontend\Presentation\Presenters\InternalErrorHtmlPresenter;
140
use WMDE\Fundraising\Frontend\Presentation\Presenters\MembershipApplicationConfirmationHtmlPresenter;
141
use WMDE\Fundraising\Frontend\Presentation\Presenters\MembershipFormViolationPresenter;
142
use WMDE\Fundraising\Frontend\Presentation\TwigTemplate;
143
use WMDE\Fundraising\Frontend\SubscriptionContext\DataAccess\DoctrineSubscriptionRepository;
144
use WMDE\Fundraising\Frontend\SubscriptionContext\Domain\Repositories\SubscriptionRepository;
145
use WMDE\Fundraising\Frontend\SubscriptionContext\Infrastructure\LoggingSubscriptionRepository;
146
use WMDE\Fundraising\Frontend\SubscriptionContext\UseCases\AddSubscription\AddSubscriptionUseCase;
147
use WMDE\Fundraising\Frontend\SubscriptionContext\UseCases\ConfirmSubscription\ConfirmSubscriptionUseCase;
148
use WMDE\Fundraising\Frontend\SubscriptionContext\Validation\SubscriptionDuplicateValidator;
149
use WMDE\Fundraising\Frontend\SubscriptionContext\Validation\SubscriptionValidator;
150
use WMDE\Fundraising\Frontend\Validation\AllowedValuesValidator;
151
use WMDE\Fundraising\Frontend\Validation\AmountPolicyValidator;
152
use WMDE\Fundraising\Frontend\Validation\PaymentDataValidator;
153
use WMDE\Fundraising\Frontend\Validation\BankDataValidator;
154
use WMDE\Fundraising\Frontend\Validation\EmailValidator;
155
use WMDE\Fundraising\Frontend\Validation\GetInTouchValidator;
156
use WMDE\Fundraising\Frontend\Validation\IbanValidator;
157
use WMDE\Fundraising\Frontend\Validation\MembershipFeeValidator;
158
use WMDE\Fundraising\Frontend\Validation\TemplateNameValidator;
159
use WMDE\Fundraising\Frontend\Validation\TextPolicyValidator;
160
use WMDE\Fundraising\ContentProvider\ContentProvider;
161
use WMDE\Fundraising\Store\Factory as StoreFactory;
162
use WMDE\Fundraising\Store\Installer;
163
164
/**
165
 * @licence GNU GPL v2+
166
 */
167
class FunFunFactory {
168
169
	private $config;
170
171
	/**
172
	 * @var Container
173
	 */
174
	private $pimple;
175
176
	private $addDoctrineSubscribers = true;
177 160
178 160
	/**
179 160
	 * @var Stopwatch|null
180 160
	 */
181
	private $profiler = null;
182 160
183 160
	public function __construct( array $config ) {
184
		$this->config = $config;
185
		$this->pimple = $this->newPimple();
186 119
	}
187
188
	private function newPimple(): Container {
189
		$pimple = new Container();
190 4
191
		$pimple['logger'] = function() {
192
			return new NullLogger();
193
		};
194
195
		$pimple['paypal_logger'] = function() {
196
			return new NullLogger();
197
		};
198 160
199
		$pimple['profiler_data_collector'] = function() {
200
			return new ProfilerDataCollector();
201
		};
202 90
203 90
		$pimple['dbal_connection'] = function() {
204 90
			return DriverManager::getConnection( $this->config['db'] );
205 90
		};
206 90
207
		$pimple['entity_manager'] = function() {
208
			$entityManager = ( new StoreFactory( $this->getConnection(), $this->getVarPath() . '/doctrine_proxies' ) )
209 90
				->getEntityManager();
210
			if ( $this->addDoctrineSubscribers ) {
211
				$entityManager->getEventManager()->addEventSubscriber( $this->newDoctrineDonationPrePersistSubscriber() );
212
				$entityManager->getEventManager()->addEventSubscriber( $this->newDoctrineMembershipApplicationPrePersistSubscriber() );
213 9
			}
214 9
215 9
			return $entityManager;
216
		};
217
218
		$pimple['subscription_repository'] = function() {
219
			return new LoggingSubscriptionRepository(
220 47
				new DoctrineSubscriptionRepository( $this->getEntityManager() ),
221 47
				$this->getLogger()
222 47
			);
223
		};
224
225
		$pimple['donation_repository'] = function() {
226
			return new LoggingDonationRepository(
227 14
				new DoctrineDonationRepository( $this->getEntityManager() ),
228 14
				$this->getLogger()
229 14
			);
230
		};
231
232
		$pimple['membership_application_repository'] = function() {
233
			return new LoggingApplicationRepository(
234 12
				new DoctrineApplicationRepository( $this->getEntityManager() ),
235 12
				$this->getLogger()
236 12
			);
237
		};
238
239 12
		$pimple['comment_repository'] = function() {
240
			$finder = new LoggingCommentFinder(
241
				new DoctrineCommentFinder( $this->getEntityManager() ),
242
				$this->getLogger()
243 44
			);
244
245
			return $this->addProfilingDecorator( $finder, 'CommentFinder' );
246
		};
247 7
248 7
		$pimple['mail_validator'] = function() {
249 7
			return new EmailValidator( new InternetDomainNameValidator() );
250 7
		};
251 7
252
		$pimple['subscription_validator'] = function() {
253
			return new SubscriptionValidator(
254
				$this->getEmailValidator(),
255
				$this->newTextPolicyValidator( 'fields' ),
256 8
				$this->newSubscriptionDuplicateValidator(),
257
				$this->newHonorificValidator()
258
			);
259
		};
260 3
261
		$pimple['template_name_validator'] = function() {
262
			return new TemplateNameValidator( $this->getTwig() );
263
		};
264 56
265
		$pimple['contact_validator'] = function() {
266
			return new GetInTouchValidator( $this->getEmailValidator() );
267
		};
268 102
269 102
		$pimple['greeting_generator'] = function() {
270 102
			return new GreetingGenerator();
271
		};
272
273
		$pimple['translator'] = function() {
274
			$translationFactory = new TranslationFactory();
275 102
			$loaders = [
276 102
				'json' => $translationFactory->newJsonLoader()
277
			];
278 102
			$locale = $this->config['locale'];
279 102
			$messagesPath = $this->getI18nDirectory() . $this->config['translation']['message-dir'];
280
			$translator = $translationFactory->create( $loaders, $locale );
281 102
			foreach ($this->config['translation']['files'] as $domain => $file) {
282 102
				$translator->addResource( 'json', $messagesPath . '/' . $file, $locale, $domain );
283 102
			}
284
285
			return $translator;
286
		};
287 102
288
		// In the future, this could be locale-specific or filled from a DB table
289
		$pimple['honorifics'] = function() {
290
			return new Honorifics( [
291 114
				'' => 'Kein Titel',
292
				'Dr.' => 'Dr.',
293 114
				'Prof.' => 'Prof.',
294
				'Prof. Dr.' => 'Prof. Dr.'
295 114
			] );
296 114
		};
297 114
298 114
		$pimple['twig_factory'] = function () {
299 114
			return new TwigFactory(
300
				array_merge_recursive(
301
					$this->config['twig'],
302
					['web-basepath' => $this->config['web-basepath']]
303 114
				),
304 114
				$this->getCachePath() . '/twig',
305 114
				$this->config['locale']
306
			);
307 114
		};
308
309
		$pimple['twig'] = function() {
310 114
			$twigFactory = $this->getTwigFactory();
311 114
			$configurator = $twigFactory->newTwigEnvironmentConfigurator();
312 114
313
			$loaders = array_filter( [
314 114
				$twigFactory->newFileSystemLoader(),
315
				$twigFactory->newArrayLoader(), // This is just a fallback for testing
316
			] );
317 114
			$extensions = [
318 114
				$twigFactory->newTranslationExtension( $this->getTranslator() ),
319 114
				new Twig_Extensions_Extension_Intl()
320
			];
321 114
			$filters = [
322
				$twigFactory->newFilePrefixFilter(
323
					$this->getFilePrefixer()
324 114
				)
325 114
			];
326 114
			$functions = [
327
				new Twig_SimpleFunction(
328 114
					'web_content',
329
					function( string $name, array $context = [] ) {
330
						return $this->getContentProvider()->getWeb( $name, $context );
331 114
					},
332
					[ 'is_safe' => [ 'html' ] ]
333
				),
334
				new Twig_SimpleFunction(
335
					'mail_content',
336 78
					function( string $name, array $context = [] ) {
337 78
						return $this->getContentProvider()->getMail( $name, $context );
338
					},
339
					[ 'is_safe' => [ 'all' ] ]
340
				)
341
			];
342
343
			return $configurator->getEnvironment( $this->pimple['twig_environment'], $loaders, $extensions, $filters, $functions );
344
		};
345 109
346
		$pimple['messenger_suborganization'] = function() {
347
			return new Messenger(
348
				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...
349 109
				$this->getSubOrganizationEmailAddress(),
350 109
				$this->config['contact-info']['suborganization']['name']
351 109
			);
352 109
		};
353 109
354 109
		$pimple['messenger_organization'] = function() {
355 109
			return new Messenger(
356
				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...
357
				$this->getOrganizationEmailAddress(),
358
				$this->config['contact-info']['organization']['name']
359 109
			);
360 109
		};
361
362
		$pimple['confirmation-page-selector'] = function() {
363 109
			return new DonationConfirmationPageSelector( $this->config['confirmation-pages'] );
364 109
		};
365
366
		$pimple['paypal-payment-notification-verifier'] = function() {
367
			return new LoggingPaymentNotificationVerifier(
368 109
				new PayPalPaymentNotificationVerifier(
369
					new Client(),
370
					$this->config['paypal-donation']['base-url'],
371
					$this->config['paypal-donation']['account-address']
372
				),
373
				$this->getLogger()
374
			);
375
		};
376
377
		$pimple['paypal-membership-fee-notification-verifier'] = function() {
378
			return new LoggingPaymentNotificationVerifier(
379
				new PayPalPaymentNotificationVerifier(
380
					new Client(),
381
					$this->config['paypal-membership']['base-url'],
382
					$this->config['paypal-membership']['account-address']
383
				),
384
				$this->getLogger()
385
			);
386
		};
387
388 6
		$pimple['credit-card-api-service'] = function() {
389
			return new McpCreditCardService(
390
				new TNvpServiceDispatcher(
391
					'IMcpCreditcardService_v1_5',
392
					'https://sipg.micropayment.de/public/creditcard/v1.5/nvp/'
393
				),
394
				$this->config['creditcard']['access-key'],
395
				$this->config['creditcard']['testmode']
396
			);
397
		};
398
399
		$pimple['token_generator'] = function() {
400
			return new RandomTokenGenerator(
401
				$this->config['token-length'],
402
				new \DateInterval( $this->config['token-validity-timestamp'] )
403
			);
404
		};
405
406
		$pimple['page_cache'] = function() {
407
			return new VoidCache();
408
		};
409
410
		$pimple['rendered_page_cache'] = function() {
411
			return new VoidCache();
412
		};
413
414 69
		$pimple['page_view_tracker'] = function () {
415 69
			return new PageViewTracker( $this->newServerSideTracker(), $this->config['piwik']['siteUrlBase'] );
416 69
		};
417
418
		$pimple['cachebusting_fileprefixer'] = function () {
419
			return new FilePrefixer( $this->getFilePrefix() );
420
		};
421 112
422
		$pimple['content_page_selector'] = function () {
423
			$json = (new SimpleFileFetcher())->fetchFile( $this->getI18nDirectory() . '/data/pages.json' );
424
			$config = json_decode( $json, true ) ?? [];
425 109
426
			return new PageSelector( $config );
427
		};
428
429
		$pimple['content_provider'] = function () {
430
			return new ContentProvider( [
431
				'content_path' => $this->getI18nDirectory(),
432 160
				'cache' => $this->config['twig']['enable-cache'] ? $this->getCachePath() . '/content' : false,
433
				'globals' => [
434
					'basepath' => $this->config['web-basepath']
435 160
				]
436 160
			] );
437
		};
438
439 90
		$pimple['payment-delay-calculator'] = function() {
440 90
			return new DefaultPaymentDelayCalculator( $this->getPayPalUrlConfigForMembershipApplications()->getDelayInDays() );
441
		};
442
443 11
		$pimple['sofort-client'] = function () {
444 11
			$config = $this->config['sofort'];
445 11
			return new SofortClient( $config['config-key'] );
446 11
		};
447
448
		return $pimple;
449
	}
450 160
451 160
	public function getConnection(): Connection {
452
		return $this->pimple['dbal_connection'];
453
	}
454 12
455 12
	public function getEntityManager(): EntityManager {
456
		return $this->pimple['entity_manager'];
457
	}
458 6
459 6
	private function newDonationEventLogger(): DonationEventLogger {
460
		return new BestEffortDonationEventLogger(
461
			new DoctrineDonationEventLogger( $this->getEntityManager() ),
462 2
			$this->getLogger()
463 2
		);
464 2
	}
465 2
466
	public function newInstaller(): Installer {
467
		return ( new StoreFactory( $this->getConnection() ) )->newInstaller();
468
	}
469 4
470 4
	public function newListCommentsUseCase(): ListCommentsUseCase {
471
		return new ListCommentsUseCase( $this->getCommentFinder() );
472
	}
473 12
474 12
	public function newCommentListJsonPresenter(): CommentListJsonPresenter {
475
		return new CommentListJsonPresenter();
476
	}
477 10
478 10
	public function newCommentListRssPresenter(): CommentListRssPresenter {
479
		return new CommentListRssPresenter( new TwigTemplate(
480
			$this->getTwig(),
481 1
			'Comment_List.rss.twig'
482 1
		) );
483 1
	}
484
485 7
	public function newCommentListHtmlPresenter(): CommentListHtmlPresenter {
486 7
		return new CommentListHtmlPresenter( $this->getLayoutTemplate( 'Comment_List.html.twig', [ 'piwikGoals' => [ 1 ] ] ) );
487
	}
488
489 46
	private function getCommentFinder(): CommentFinder {
490 46
		return $this->pimple['comment_repository'];
491
	}
492
493 8
	public function getSubscriptionRepository(): SubscriptionRepository {
494 8
		return $this->pimple['subscription_repository'];
495
	}
496
497 1
	public function setSubscriptionRepository( SubscriptionRepository $subscriptionRepository ) {
498 1
		$this->pimple['subscription_repository'] = $subscriptionRepository;
499
	}
500
501 3
	private function getSubscriptionValidator(): SubscriptionValidator {
502 3
		return $this->pimple['subscription_validator'];
503 3
	}
504 3
505
	public function getEmailValidator(): EmailValidator {
506
		return $this->pimple['mail_validator'];
507
	}
508 3
509 3
	public function getTemplateNameValidator(): TemplateNameValidator {
510
		return $this->pimple['template_name_validator'];
511
	}
512 1
513 1
	public function newAddSubscriptionHtmlPresenter(): AddSubscriptionHtmlPresenter {
514
		return new AddSubscriptionHtmlPresenter( $this->getLayoutTemplate( 'Subscription_Form.html.twig' ), $this->getTranslator() );
515
	}
516 160
517 160
	public function newConfirmSubscriptionHtmlPresenter(): ConfirmSubscriptionHtmlPresenter {
518 160
		return new ConfirmSubscriptionHtmlPresenter(
519
			$this->getLayoutTemplate( 'Confirm_Subscription.twig' ),
520 109
			$this->getTranslator()
521 109
		);
522
	}
523
524
	public function newAddSubscriptionJsonPresenter(): AddSubscriptionJsonPresenter {
525
		return new AddSubscriptionJsonPresenter( $this->getTranslator() );
526
	}
527
528
	public function newGetInTouchHtmlPresenter(): GetInTouchHtmlPresenter {
529
		return new GetInTouchHtmlPresenter( $this->getLayoutTemplate( 'contact_form.html.twig' ), $this->getTranslator() );
530
	}
531 43
532 43
	public function setTwigEnvironment( Twig_Environment $twig ) {
533 43
		$this->pimple['twig_environment'] = $twig;
534
	}
535 43
536
	public function getTwig(): Twig_Environment {
537
		return $this->pimple['twig'];
538
	}
539
540
	/**
541
	 * Get a template, with the content for the layout areas filled in.
542
	 *
543
	 * @param string $templateName
544
	 * @param array $context Additional variables for the template
545 30
	 * @return TwigTemplate
546 30
	 */
547 30
	public function getLayoutTemplate( string $templateName, array $context = [] ): TwigTemplate {
548 30
		 return new TwigTemplate(
549
			$this->getTwig(),
550 30
			$templateName,
551 30
			array_merge( $this->getDefaultTwigVariables(), $context )
552
		);
553
	}
554
555
	/**
556
	 * Get a layouted template that includes another template
557 72
	 *
558
	 * @deprecated Change the template to use extend and block and call getLayoutTemplate instead.
559 72
	 *
560 72
	 * @param string $templateName Template to include
561 72
	 * @return TwigTemplate
562 72
	 */
563 72
	private function getIncludeTemplate( string $templateName, array $context = [] ): TwigTemplate {
564 72
		return new TwigTemplate(
565
			$this->getTwig(),
566
			'Include_in_Layout.twig',
567
			array_merge(
568 20
				$this->getDefaultTwigVariables(),
569 20
				[ 'main_template' => $templateName ],
570 20
				$context
571 20
			)
572
		);
573
	}
574
575 112
	private function getDefaultTwigVariables() {
576 112
		return [
577
			'honorifics' => $this->getHonorifics()->getList(),
578
			'header_template' => $this->config['default-layout-templates']['header'],
579 10
			'footer_template' => $this->config['default-layout-templates']['footer'],
580 10
			'no_js_notice_template' => $this->config['default-layout-templates']['no-js-notice'],
581 10
			'piwik' => $this->config['piwik'],
582
			'locale' => $this->config['locale'],
583 102
		];
584 102
	}
585
586
	private function newReferrerGeneralizer() {
587 112
		return new ReferrerGeneralizer(
588 112
			$this->config['referrer-generalization']['default'],
589 112
			$this->config['referrer-generalization']['domain-map']
590 112
		);
591
	}
592
593 112
	public function getLogger(): LoggerInterface {
594
		return $this->pimple['logger'];
595
	}
596 109
597 109
	public function getPaypalLogger(): LoggerInterface {
598 109
		return $this->pimple['paypal_logger'];
599 109
	}
600
601
	private function getVarPath(): string {
602 109
		return __DIR__ . '/../../var';
603
	}
604
605 112
	public function getCachePath(): string {
606 112
		return $this->getVarPath() . '/cache';
607 112
	}
608 112
609 112
	public function getLoggingPath(): string {
610 112
		return $this->getVarPath() . '/log';
611 112
	}
612
613
	public function getTemplatePath(): string {
614
		return __DIR__ . '/../../app/fundraising-frontend-content/templates';
615 109
	}
616 109
617 109
	public function newAddSubscriptionUseCase(): AddSubscriptionUseCase {
618 109
		return new AddSubscriptionUseCase(
619 109
			$this->getSubscriptionRepository(),
620 109
			$this->getSubscriptionValidator(),
621 109
			$this->newAddSubscriptionMailer()
622
		);
623
	}
624
625 119
	public function newConfirmSubscriptionUseCase(): ConfirmSubscriptionUseCase {
626 119
		return new ConfirmSubscriptionUseCase(
627
			$this->getSubscriptionRepository(),
628
			$this->newConfirmSubscriptionMailer()
629 6
		);
630 6
	}
631
632
	private function newAddSubscriptionMailer(): TemplateMailerInterface {
633 127
		return $this->newTemplateMailer(
634 127
			$this->getSuborganizationMessenger(),
635
			new TwigTemplate(
636
				$this->getTwig(),
637 109
				'Mail_Subscription_Request.txt.twig',
638 109
				[
639
					'greeting_generator' => $this->getGreetingGenerator()
640
				]
641
			),
642
			'mail_subject_subscription'
643
		);
644
	}
645
646
	private function newConfirmSubscriptionMailer(): TemplateMailerInterface {
647
		return $this->newTemplateMailer(
648
			$this->getSuborganizationMessenger(),
649 7
			new TwigTemplate(
650 7
					$this->getTwig(),
651 7
					'Mail_Subscription_Confirmation.txt.twig',
652 7
					[ 'greeting_generator' => $this->getGreetingGenerator() ]
653 7
			),
654
			'mail_subject_subscription_confirmed'
655
		);
656
	}
657 3
658 3
	/**
659 3
	 * Create a new TemplateMailer instance
660 3
	 *
661
	 * So much decoration going on that explicitly hinting what we return (Robustness principle) would be confusing
662
	 * (you'd expect a TemplateBasedMailer, not a LoggingMailer), so we hint the interface instead.
663
	 */
664 7
	private function newTemplateMailer( Messenger $messenger, TwigTemplate $template, string $messageKey ): TemplateMailerInterface {
665 7
		$mailer = new TemplateBasedMailer(
666 7
			$messenger,
667 7
			$template,
668 7
			$this->getTranslator()->trans( $messageKey )
669 7
		);
670
671 7
		$mailer = new LoggingMailer( $mailer, $this->getLogger() );
672 7
673
		return $this->addProfilingDecorator( $mailer, 'Mailer' );
674
	}
675 7
676
	public function getGreetingGenerator() {
677
		return $this->pimple['greeting_generator'];
678
	}
679 3
680 3
	public function newCheckIbanUseCase(): CheckIbanUseCase {
681 3
		return new CheckIbanUseCase( $this->newBankDataConverter(), $this->newIbanValidator() );
682 3
	}
683 3
684 3
	public function newGenerateIbanUseCase(): GenerateIbanUseCase {
685 3
		return new GenerateIbanUseCase( $this->newBankDataConverter(), $this->newIbanValidator() );
686
	}
687 3
688
	public function newIbanPresenter(): IbanPresenter {
689
		return new IbanPresenter();
690
	}
691 59
692 59
	public function newBankDataConverter() {
693
		return new BankDataConverter( $this->config['bank-data-file'] );
694
	}
695 59
696
	public function setSubscriptionValidator( SubscriptionValidator $subscriptionValidator ) {
697
		$this->pimple['subscription_validator'] = $subscriptionValidator;
698 59
	}
699
700 59
	public function newGetInTouchUseCase() {
701
		return new GetInTouchUseCase(
702
			$this->getContactValidator(),
703 56
			$this->newContactOperatorMailer(),
704 56
			$this->newContactUserMailer()
705
		);
706
	}
707
708
	private function newContactUserMailer(): TemplateMailerInterface {
709
		return $this->newTemplateMailer(
710
			$this->getSuborganizationMessenger(),
711
			new TwigTemplate( $this->getTwig(), 'Mail_Contact_Confirm_to_User.txt.twig' ),
712
			'mail_subject_getintouch'
713
		);
714
	}
715
716
	private function newContactOperatorMailer(): OperatorMailer {
717
		return new OperatorMailer(
718
			$this->getSuborganizationMessenger(),
719 31
			new TwigTemplate( $this->getTwig(), 'Mail_Contact_Forward_to_Operator.txt.twig' ),
720 31
			$this->getTranslator()->trans( 'mail_subject_getintouch_forward' )
721
		);
722
	}
723
724
	private function getContactValidator(): GetInTouchValidator {
725
		return $this->pimple['contact_validator'];
726
	}
727
728
	private function newSubscriptionDuplicateValidator(): SubscriptionDuplicateValidator {
729
		return new SubscriptionDuplicateValidator(
730
				$this->getSubscriptionRepository(),
731 3
				$this->newSubscriptionDuplicateCutoffDate()
732 3
		);
733 3
	}
734 3
735 3
	private function newSubscriptionDuplicateCutoffDate(): \DateTime {
736
		$cutoffDateTime = new \DateTime();
737
		$cutoffDateTime->sub( new \DateInterval( $this->config['subscription-interval'] ) );
738
		return $cutoffDateTime;
739 3
	}
740 3
741 3
	private function newHonorificValidator(): AllowedValuesValidator {
742 3
		return new AllowedValuesValidator( $this->getHonorifics()->getKeys() );
743 3
	}
744
745
	private function getHonorifics(): Honorifics {
746
		return $this->pimple['honorifics'];
747 3
	}
748 3
749 3
	public function newAuthorizedCachePurger(): AuthorizedCachePurger {
750 3
		return new AuthorizedCachePurger(
751 3
			new AllOfTheCachePurger( $this->getTwig(), $this->getPageCache(), $this->getRenderedPageCache() ),
752
			$this->config['purging-secret']
753
		);
754
	}
755 3
756 3
	private function newBankDataValidator(): BankDataValidator {
757
		return new BankDataValidator( $this->newIbanValidator() );
758
	}
759 7
760 7
	private function getSuborganizationMessenger(): Messenger {
761 7
		return $this->pimple['messenger_suborganization'];
762 7
	}
763
764
	public function setSuborganizationMessenger( Messenger $messenger ) {
765
		$this->pimple['messenger_suborganization'] = $messenger;
766 7
	}
767 7
768 7
	private function getOrganizationMessenger(): Messenger {
769 7
		return $this->pimple['messenger_organization'];
770
	}
771
772 7
	public function setOrganizationMessenger( Messenger $messenger ) {
773 7
		$this->pimple['messenger_organization'] = $messenger;
774
	}
775
776 78
	public function setNullMessenger() {
777 78
		$this->setSuborganizationMessenger( new Messenger(
778
			Swift_NullTransport::newInstance(),
779
			$this->getSubOrganizationEmailAddress()
780 1
		) );
781 1
		$this->setOrganizationMessenger( new Messenger(
782 1
			Swift_NullTransport::newInstance(),
783 1
			$this->getOrganizationEmailAddress()
784
		) );
785
	}
786
787 31
	public function getSubOrganizationEmailAddress(): EmailAddress {
788 31
		return new EmailAddress( $this->config['contact-info']['suborganization']['email'] );
789
	}
790
791 46
	public function getOrganizationEmailAddress() {
792 46
		return new EmailAddress( $this->config['contact-info']['organization']['email'] );
793
	}
794
795 160
	public function newInternalErrorHtmlPresenter(): InternalErrorHtmlPresenter {
796 160
		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...
797 160
	}
798
799 13
	public function newAccessDeniedHtmlPresenter(): InternalErrorHtmlPresenter {
800 13
		return new InternalErrorHtmlPresenter( $this->getLayoutTemplate( 'Access_Denied.twig' ) );
801
	}
802
803 160
	public function getTranslator(): TranslatorInterface {
804 160
		return $this->pimple['translator'];
805 160
	}
806
807 160
	public function setTranslator( TranslatorInterface $translator ) {
808 160
		$this->pimple['translator'] = $translator;
809 160
	}
810 160
811
	public function getTwigFactory(): TwigFactory {
812 160
		return $this->pimple['twig_factory'];
813 160
	}
814 160
815
	private function newTextPolicyValidator( string $policyName ): TextPolicyValidator {
816 160
		$fetcher = new ErrorLoggingFileFetcher(
817
			new SimpleFileFetcher(),
818 160
			$this->getLogger()
819 160
		);
820
		$textPolicyConfig = $this->config['text-policies'][$policyName];
821
		return new TextPolicyValidator(
822 160
			new WordListFileReader(
823 160
				$fetcher,
824
				$textPolicyConfig['badwords'] ? $this->getAbsolutePath( $textPolicyConfig['badwords'] ) : ''
825
			),
826 3
			new WordListFileReader(
827 3
				$fetcher,
828
				$textPolicyConfig['whitewords'] ? $this->getAbsolutePath( $textPolicyConfig['whitewords'] ) : ''
829
			)
830 3
		);
831 3
	}
832
833
	private function newCommentPolicyValidator(): TextPolicyValidator {
834 116
		return $this->newTextPolicyValidator( 'comment' );
835 116
	}
836
837
	public function newCancelDonationUseCase( string $updateToken ): CancelDonationUseCase {
838 2
		return new CancelDonationUseCase(
839 2
			$this->getDonationRepository(),
840 2
			$this->newCancelDonationMailer(),
841
			$this->newDonationAuthorizer( $updateToken ),
842 109
			$this->newDonationEventLogger()
843 109
		);
844
	}
845
846 41
	private function newCancelDonationMailer(): TemplateMailerInterface {
847 41
		return $this->newTemplateMailer(
848 41
			$this->getSuborganizationMessenger(),
849
			new TwigTemplate(
850 41
				$this->getTwig(),
851 41
				'Mail_Donation_Cancellation_Confirmation.txt.twig',
852 41
				[ 'greeting_generator' => $this->getGreetingGenerator() ]
853
			),
854
			'mail_subject_confirm_cancellation'
855
		);
856 3
	}
857 3
858
	public function newAddDonationUseCase(): AddDonationUseCase {
859
		return new AddDonationUseCase(
860 5
			$this->getDonationRepository(),
861 5
			$this->newDonationValidator(),
862 5
			$this->newDonationPolicyValidator(),
863 5
			$this->newReferrerGeneralizer(),
864 5
			$this->newDonationConfirmationMailer(),
865 5
			$this->newBankTransferCodeGenerator(),
866
			$this->newDonationTokenFetcher()
867
		);
868
	}
869 5
870 5
	private function newBankTransferCodeGenerator(): TransferCodeGenerator {
871 5
		return new UniqueTransferCodeGenerator(
872 5
			new SimpleTransferCodeGenerator(),
873 5
			$this->getEntityManager()
874 5
		);
875 5
	}
876
877 5
	private function newDonationValidator(): AddDonationValidator {
878
		return new AddDonationValidator(
879
			$this->newPaymentDataValidator(),
880
			$this->newBankDataValidator(),
881 20
			$this->getEmailValidator()
882 20
		);
883 20
	}
884 20
885 20
	public function newPersonalInfoValidator(): DonorValidator {
886 20
		return new DonorValidator(
887 20
			new DonorNameValidator(),
888 20
			new DonorAddressValidator(),
889 20
			$this->getEmailValidator()
890
		);
891
	}
892
893 20
	private function newDonationConfirmationMailer(): DonationConfirmationMailer {
894 20
		return new DonationConfirmationMailer(
895 20
			$this->newTemplateMailer(
896 20
				$this->getSuborganizationMessenger(),
897
				new TwigTemplate(
898
					$this->getTwig(),
899
					'Mail_Donation_Confirmation.txt.twig',
900 20
					[
901 20
						'greeting_generator' => $this->getGreetingGenerator()
902 20
					]
903 20
				),
904 20
				'mail_subject_confirm_donation'
905
			)
906
		);
907
	}
908 2
909 2
	public function newPayPalUrlGeneratorForDonations() {
910 2
		return new PayPalUrlGenerator( $this->getPayPalUrlConfigForDonations() );
911 2
	}
912 2
913
	public function newPayPalUrlGeneratorForMembershipApplications() {
914
		return new PayPalUrlGenerator( $this->getPayPalUrlConfigForMembershipApplications() );
915
	}
916 28
917 28
	private function getPayPalUrlConfigForDonations() {
918 28
		return PayPalUrlConfig::newFromConfig( $this->config['paypal-donation'] );
919 28
	}
920 28
921 28
	private function getPayPalUrlConfigForMembershipApplications() {
922 28
		return PayPalUrlConfig::newFromConfig( $this->config['paypal-membership'] );
923
	}
924 28
925 28
	public function newSofortUrlGeneratorForDonations(): SofortUrlGenerator {
926
		$config = $this->config['sofort'];
927
928 28
		return new SofortUrlGenerator(
929
			new SofortUrlConfig(
930
				$this->getTranslator()->trans( 'item_name_donation', [], 'messages' ),
931
				$config['return-url'],
932
				$config['cancel-url']
933 2
			),
934 2
			$this->getSofortClient()
935
		);
936
	}
937 2
938 2
	public function setSofortClient( SofortClient $client ): void {
939
		$this->pimple['sofort-client'] = $client;
940
	}
941 2
942 2
	private function getSofortClient(): SofortClient {
943
		return $this->pimple['sofort-client'];
944
	}
945 2
946 2
	private function newCreditCardUrlGenerator() {
947
		return new CreditCardUrlGenerator( $this->newCreditCardUrlConfig() );
948
	}
949 3
950 3
	private function newCreditCardUrlConfig() {
951
		return CreditCardUrlConfig::newFromConfig( $this->config['creditcard'] );
952
	}
953 3
954 3
	public function getDonationRepository(): DonationRepository {
955
		return $this->pimple['donation_repository'];
956
	}
957 47
958 47
	public function newPaymentDataValidator(): PaymentDataValidator {
959
		return new PaymentDataValidator(
960
			$this->config['donation-minimum-amount'],
961 36
			$this->config['donation-maximum-amount'],
962 36
			$this->getEnabledDonationPaymentTypes()
963
		);
964
	}
965 19
966 19
	private function newAmountFormatter(): AmountFormatter {
967
		return new AmountFormatter( $this->config['locale'] );
968
	}
969 2
970 2
	public function newDecimalNumberFormatter(): NumberFormatter {
971
		return new NumberFormatter( $this->config['locale'], NumberFormatter::DECIMAL );
972
	}
973 3
974 3
	public function newAddCommentUseCase( string $updateToken ): AddCommentUseCase {
975 3
		return new AddCommentUseCase(
976 3
			$this->getDonationRepository(),
977 3
			$this->newDonationAuthorizer( $updateToken ),
978 3
			$this->newCommentPolicyValidator(),
979
			$this->newAddCommentValidator()
980
		);
981
	}
982 29
983 29
	private function newDonationAuthorizer( string $updateToken = null, string $accessToken = null ): DonationAuthorizer {
984 29
		return new DoctrineDonationAuthorizer(
985
			$this->getEntityManager(),
986
			$updateToken,
987
			$accessToken
988
		);
989
	}
990 90
991 90
	public function getTokenGenerator(): TokenGenerator {
992
		return $this->pimple['token_generator'];
993
	}
994 10
995 10
	public function newDonationConfirmationPresenter() {
996 10
		return new DonationConfirmationHtmlPresenter(
997
			$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...
998
		);
999
	}
1000 3
1001 3
	public function newCreditCardPaymentHtmlPresenter() {
1002 3
		return new CreditCardPaymentHtmlPresenter(
1003 3
			$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...
1004 3
			$this->getTranslator(),
1005
			$this->newCreditCardUrlGenerator()
1006
		);
1007
	}
1008 5
1009 5
	public function newCancelDonationHtmlPresenter() {
1010 5
		return new CancelDonationHtmlPresenter(
1011
			$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...
1012
		);
1013
	}
1014 11
1015 11
	public function newApplyForMembershipUseCase(): ApplyForMembershipUseCase {
1016 11
		return new ApplyForMembershipUseCase(
1017 11
			$this->getMembershipApplicationRepository(),
1018 11
			$this->newMembershipApplicationTokenFetcher(),
1019 11
			$this->newApplyForMembershipMailer(),
1020 11
			$this->newMembershipApplicationValidator(),
1021 11
			$this->newApplyForMembershipPolicyValidator(),
1022 11
			$this->newMembershipApplicationTracker(),
1023
			$this->newMembershipApplicationPiwikTracker(),
1024
			$this->getPaymentDelayCalculator()
1025
		);
1026 11
	}
1027 11
1028 11
	private function newApplyForMembershipMailer(): TemplateMailerInterface {
1029 11
		return $this->newTemplateMailer(
1030 11
			$this->getOrganizationMessenger(),
1031 11
			new TwigTemplate(
1032 11
				$this->getTwig(),
1033
				'Mail_Membership_Application_Confirmation.txt.twig',
1034 11
				[ 'greeting_generator' => $this->getGreetingGenerator() ]
1035
			),
1036
			'mail_subject_confirm_membership_application'
1037
		);
1038 11
	}
1039 11
1040 11
	private function newMembershipApplicationValidator(): MembershipApplicationValidator {
1041 11
		return new MembershipApplicationValidator(
1042 11
			new MembershipFeeValidator(),
1043
			$this->newBankDataValidator(),
1044
			$this->getEmailValidator()
1045
		);
1046 11
	}
1047 11
1048
	private function newMembershipApplicationTracker(): ApplicationTracker {
1049
		return new DoctrineApplicationTracker( $this->getEntityManager() );
1050 11
	}
1051 11
1052
	private function newMembershipApplicationPiwikTracker(): ApplicationPiwikTracker {
1053
		return new DoctrineApplicationPiwikTracker( $this->getEntityManager() );
1054 11
	}
1055 11
1056
	private function getPaymentDelayCalculator() {
1057
		return $this->pimple['payment-delay-calculator'];
1058 2
	}
1059 2
1060 2
	public function setPaymentDelayCalculator( PaymentDelayCalculator $paymentDelayCalculator ) {
1061 2
		$this->pimple['payment-delay-calculator'] = $paymentDelayCalculator;
1062 2
	}
1063
1064
	private function newApplyForMembershipPolicyValidator(): ApplyForMembershipPolicyValidator {
1065
		return new ApplyForMembershipPolicyValidator(
1066 3
			$this->newTextPolicyValidator( 'fields' ),
1067
			$this->config['email-address-blacklist']
1068
		);
1069 3
	}
1070 3
1071
	public function newCancelMembershipApplicationUseCase( string $updateToken ): CancelMembershipApplicationUseCase {
1072
		return new CancelMembershipApplicationUseCase(
1073
			$this->newMembershipApplicationAuthorizer( $updateToken ),
1074
			$this->getMembershipApplicationRepository(),
1075
			$this->newCancelMembershipApplicationMailer()
1076 14
		);
1077 14
	}
1078
1079
	private function newMembershipApplicationAuthorizer(
1080 2
		string $updateToken = null, string $accessToken = null ): ApplicationAuthorizer {
1081 2
1082 2
		return new DoctrineApplicationAuthorizer(
1083 2
			$this->getEntityManager(),
1084 2
			$updateToken,
1085 2
			$accessToken
1086 2
		);
1087
	}
1088 2
1089
	public function getMembershipApplicationRepository(): ApplicationRepository {
1090
		return $this->pimple['membership_application_repository'];
1091
	}
1092 1
1093 1
	private function newCancelMembershipApplicationMailer(): TemplateMailerInterface {
1094 1
		return $this->newTemplateMailer(
1095 1
			$this->getOrganizationMessenger(),
1096
			new TwigTemplate(
1097
				$this->getTwig(),
1098
				'Mail_Membership_Application_Cancellation_Confirmation.txt.twig',
1099 13
				[ 'greeting_generator' => $this->getGreetingGenerator() ]
1100 13
			),
1101 13
			'mail_subject_confirm_membership_application_cancellation'
1102 13
		);
1103 13
	}
1104
1105
	public function newMembershipApplicationConfirmationUseCase( string $accessToken ) {
1106
		return new ShowMembershipApplicationConfirmationUseCase(
1107 7
			$this->newMembershipApplicationAuthorizer( null, $accessToken ), $this->getMembershipApplicationRepository(),
1108 7
			$this->newMembershipApplicationTokenFetcher()
1109 7
		);
1110
	}
1111 10
1112 10
	public function newShowDonationConfirmationUseCase( string $accessToken ): ShowDonationConfirmationUseCase {
1113
		return new ShowDonationConfirmationUseCase(
1114
			$this->newDonationAuthorizer( null, $accessToken ),
1115 4
			$this->newDonationTokenFetcher(),
1116
			$this->getDonationRepository()
1117
		);
1118 4
	}
1119 4
1120
	public function setDonationConfirmationPageSelector( DonationConfirmationPageSelector $selector ) {
1121
		$this->pimple['confirmation-page-selector'] = $selector;
1122 15
	}
1123
1124
	public function getDonationConfirmationPageSelector(): DonationConfirmationPageSelector {
1125 15
		return $this->pimple['confirmation-page-selector'];
1126 15
	}
1127
1128
	public function newDonationFormViolationPresenter() {
1129 4
		return new DonationFormViolationPresenter( $this->getDonationFormTemplate(), $this->newAmountFormatter() );
1130 4
	}
1131 4
1132 4
	public function newDonationFormPresenter() {
1133 4
		return new DonationFormPresenter( $this->getDonationFormTemplate(), $this->newAmountFormatter() );
1134 4
	}
1135
1136
	private function getDonationFormTemplate(): TwigTemplate {
1137
		// TODO make the template name dependent on the 'form' value from the HTTP POST request
1138 7
		// (we need different form pages for A/B testing)
1139 7
		return $this->getLayoutTemplate( 'Donation_Form.html.twig', [
1140
			'paymentTypes' => $this->getEnabledDonationPaymentTypes()
1141
		] );
1142 7
	}
1143 7
1144 7
	private function getEnabledDonationPaymentTypes(): array {
1145
		return array_keys( array_filter( $this->config['payment-types'], function ( $config ) {
1146 2
			return ( $config['donation-enabled'] === true );
1147 2
		} ) );
1148 2
	}
1149 2
1150 2
	public function newHandlePayPalPaymentNotificationUseCase( string $updateToken ) {
1151 2
		return new HandlePayPalPaymentNotificationUseCase(
1152 2
			$this->getDonationRepository(),
1153 2
			$this->newDonationAuthorizer( $updateToken ),
1154
			$this->newDonationConfirmationMailer(),
1155
			$this->newDonationEventLogger()
1156
		);
1157 2
	}
1158 2
1159 2
	public function newMembershipApplicationSubscriptionSignupNotificationUseCase( string $updateToken ) {
1160
		return new HandleSubscriptionSignupNotificationUseCase(
1161
			$this->getMembershipApplicationRepository(),
1162
			$this->newMembershipApplicationAuthorizer( $updateToken ),
1163 1
			$this->newApplyForMembershipMailer(),
1164 1
			$this->getLogger()
1165 1
		);
1166
	}
1167
1168
	public function newMembershipApplicationSubscriptionPaymentNotificationUseCase( string $updateToken ) {
1169 2
		return new HandleSubscriptionPaymentNotificationUseCase(
1170 2
			$this->getMembershipApplicationRepository(),
1171 2
			$this->newMembershipApplicationAuthorizer( $updateToken ),
1172
			$this->newApplyForMembershipMailer(),
1173
			$this->getLogger()
1174
		);
1175 2
	}
1176 2
1177 2
	public function getPayPalPaymentNotificationVerifier(): PaymentNotificationVerifier {
1178
		return $this->pimple['paypal-payment-notification-verifier'];
1179 2
	}
1180 2
1181
	public function setPayPalPaymentNotificationVerifier( PaymentNotificationVerifier $verifier ) {
1182
		$this->pimple['paypal-payment-notification-verifier'] = $verifier;
1183 2
	}
1184 2
1185 2
	public function getPayPalMembershipFeeNotificationVerifier(): PaymentNotificationVerifier {
1186 2
		return $this->pimple['paypal-membership-fee-notification-verifier'];
1187 2
	}
1188 2
1189
	public function setPayPalMembershipFeeNotificationVerifier( PaymentNotificationVerifier $verifier ) {
1190
		$this->pimple['paypal-membership-fee-notification-verifier'] = $verifier;
1191
	}
1192
1193 90
	public function newCreditCardNotificationUseCase( string $updateToken ) {
1194 90
		return new CreditCardNotificationUseCase(
1195 90
			$this->getDonationRepository(),
1196
			$this->newDonationAuthorizer( $updateToken ),
1197
			$this->getCreditCardService(),
1198
			$this->newDonationConfirmationMailer(),
1199
			$this->getLogger(),
1200
			$this->newDonationEventLogger()
1201 90
		);
1202 90
	}
1203 90
1204
	public function newCancelMembershipApplicationHtmlPresenter() {
1205
		return new CancelMembershipApplicationHtmlPresenter(
1206
			$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...
1207
		);
1208
	}
1209 21
1210 21
	public function newMembershipApplicationConfirmationHtmlPresenter() {
1211 21
		return new MembershipApplicationConfirmationHtmlPresenter(
1212
			$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...
1213
		);
1214
	}
1215
1216
	public function newMembershipFormViolationPresenter() {
1217 30
		return new MembershipFormViolationPresenter(
1218 30
			$this->getLayoutTemplate( 'Membership_Application.html.twig' )
1219 30
		);
1220
	}
1221
1222
	public function setCreditCardService( CreditCardService $ccService ) {
1223 12
		$this->pimple['credit-card-api-service'] = $ccService;
1224 12
	}
1225 12
1226
	public function getCreditCardService(): CreditCardService {
1227
		return $this->pimple['credit-card-api-service'];
1228
	}
1229 20
1230 20
	public function newCreditCardNotificationPresenter(): CreditCardNotificationPresenter {
1231 20
		return new CreditCardNotificationPresenter(
1232 20
			new TwigTemplate(
1233
				$this->getTwig(),
1234
				'Credit_Card_Payment_Notification.txt.twig',
1235
				[ 'returnUrl' => $this->config['creditcard']['return-url'] ]
1236 20
			)
1237
		);
1238 20
	}
1239
1240
	private function newDoctrineDonationPrePersistSubscriber(): DoctrineDonationPrePersistSubscriber {
1241 2
		$tokenGenerator = $this->getTokenGenerator();
1242 2
		return new DoctrineDonationPrePersistSubscriber(
1243
			$tokenGenerator,
1244
			$tokenGenerator
1245 2
		);
1246 2
	}
1247 2
1248
	private function newDoctrineMembershipApplicationPrePersistSubscriber(): DoctrineMembershipApplicationPrePersistSubscriber {
1249
		$tokenGenerator = $this->getTokenGenerator();
1250 2
		return new DoctrineMembershipApplicationPrePersistSubscriber(
1251 2
			$tokenGenerator,
1252
			$tokenGenerator
1253
		);
1254 3
	}
1255 3
1256
	public function setTokenGenerator( TokenGenerator $tokenGenerator ) {
1257
		$this->pimple['token_generator'] = $tokenGenerator;
1258 112
	}
1259 112
1260
	public function disableDoctrineSubscribers() {
1261
		$this->addDoctrineSubscribers = false;
1262 109
	}
1263 109
1264
	private function newDonationTokenFetcher(): DonationTokenFetcher {
1265
		return new DoctrineDonationTokenFetcher(
1266
			$this->getEntityManager()
1267
		);
1268
	}
1269
1270
	private function newMembershipApplicationTokenFetcher(): ApplicationTokenFetcher {
1271
		return new DoctrineApplicationTokenFetcher(
1272
			$this->getEntityManager()
1273
		);
1274
	}
1275
1276 118
	private function newDonationPolicyValidator(): AddDonationPolicyValidator {
1277 118
		return new AddDonationPolicyValidator(
1278 118
			$this->newDonationAmountPolicyValidator(),
1279
			$this->newTextPolicyValidator( 'fields' ),
1280
			$this->config['email-address-blacklist']
1281
		);
1282
	}
1283
1284
	private function newDonationAmountPolicyValidator(): AmountPolicyValidator {
1285
		// in the future, this might come from the configuration
1286
		return new AmountPolicyValidator( 1000, 1000 );
1287
	}
1288
1289
	public function getDonationTimeframeLimit() {
1290 2
		return $this->config['donation-timeframe-limit'];
1291 2
	}
1292 2
1293
	public function newSystemMessageResponse( string $message ) {
1294
		$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...
1295
		return $test->render( [ 'message' => $message ] );
1296
	}
1297
1298 2
	public function getMembershipApplicationTimeframeLimit() {
1299 2
		return $this->config['membership-application-timeframe-limit'];
1300 2
	}
1301
1302
	private function newAddCommentValidator(): AddCommentValidator {
1303
		return new AddCommentValidator();
1304
	}
1305
1306 31
	private function getPageCache(): Cache {
1307 31
		return $this->pimple['page_cache'];
1308
	}
1309
1310 109
	private function getRenderedPageCache(): Cache {
1311 109
		return $this->pimple['rendered_page_cache'];
1312
	}
1313
1314 109
	public function enablePageCache() {
1315 109
		$this->pimple['page_cache'] = function() {
1316 109
			return new FilesystemCache( $this->getCachePath() . '/pages/raw' );
1317 109
		};
1318
1319
		$this->pimple['rendered_page_cache'] = function() {
1320
			return new FilesystemCache( $this->getCachePath() . '/pages/rendered' );
1321
		};
1322 2
	}
1323 2
1324 2
	private function addProfilingDecorator( $objectToDecorate, string $profilingLabel ) {
1325 2
		if ( $this->profiler === null ) {
1326 2
			return $objectToDecorate;
1327
		}
1328
1329
		$builder = new ProfilingDecoratorBuilder( $this->profiler, $this->getProfilerDataCollector() );
1330 11
1331 11
		return $builder->decorate( $objectToDecorate, $profilingLabel );
1332
	}
1333
1334
	public function setProfiler( Stopwatch $profiler ) {
1335 1
		$this->profiler = $profiler;
1336 1
	}
1337
1338 2
	public function setEmailValidator( EmailValidator $validator ) {
1339
		$this->pimple['mail_validator'] = $validator;
1340 1
	}
1341 1
1342
	public function setLogger( LoggerInterface $logger ) {
1343
		$this->pimple['logger'] = $logger;
1344
	}
1345
1346
	public function setPaypalLogger( LoggerInterface $logger ) {
1347
		$this->pimple['paypal_logger'] = $logger;
1348
	}
1349
1350
	public function getProfilerDataCollector(): ProfilerDataCollector {
1351
		return $this->pimple['profiler_data_collector'];
1352
	}
1353
1354
	private function newIbanValidator(): IbanValidator {
1355
		return new IbanValidator( $this->newBankDataConverter(), $this->config['banned-ibans'] );
1356
	}
1357
1358
	public function setFilePrefixer( FilePrefixer $prefixer ): void {
1359
		$this->pimple['cachebusting_fileprefixer'] = $prefixer;
1360
	}
1361
1362
	private function getFilePrefixer(): FilePrefixer {
1363
		return $this->pimple['cachebusting_fileprefixer'];
1364
	}
1365
1366
	private function getFilePrefix(): string {
1367
		$prefixContentFile = $this->getVarPath() . '/file_prefix.txt';
1368
		if ( !file_exists( $prefixContentFile ) ) {
1369
			return '';
1370
		}
1371
		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...
1372
	}
1373
1374
	public function newDonationAcceptedEventHandler( string $updateToken ): DonationAcceptedEventHandler {
1375
		return new DonationAcceptedEventHandler(
1376
			$this->newDonationAuthorizer( $updateToken ),
1377
			$this->getDonationRepository(),
1378
			$this->newDonationConfirmationMailer()
1379
		);
1380
	}
1381
1382
	public function newPageNotFoundHtmlPresenter(): PageNotFoundPresenter {
1383
		return new PageNotFoundPresenter( $this->getLayoutTemplate( 'Page_not_found.html.twig' ) );
1384
	}
1385
1386
	public function setPageViewTracker( PageViewTracker $tracker ) {
1387
		$this->pimple['page_view_tracker'] = function () use ( $tracker )  {
1388
			return $tracker;
1389
		};
1390
	}
1391
1392
	public function getPageViewTracker(): PageViewTracker {
1393
		return $this->pimple['page_view_tracker'];
1394
	}
1395
1396
	public function newServerSideTracker(): ServerSideTracker {
1397
		// the "https:" prefix does NOT get any slashes because baseURL is stored in a protocol-agnostic way
1398
		// (e.g. "//tracking.wikimedia.de" )
1399
		return new PiwikServerSideTracker(
1400
			new \PiwikTracker( $this->config['piwik']['siteId'], 'https:' . $this->config['piwik']['baseUrl'] )
1401
		);
1402
	}
1403
1404
	public function getI18nDirectory(): string {
1405
		return $this->getAbsolutePath( $this->config['i18n-base-path'] ) . '/' . $this->config['locale'];
1406
	}
1407
1408
	/**
1409
	 * If the pathname does not start with a slash, make the path absolute to root dir of application
1410
	 */
1411
	private function getAbsolutePath( string $path ): string {
1412
		if ( $path[0] === '/' ) {
1413
			return $path;
1414
		}
1415
		return __DIR__ . '/../../' . $path;
1416
	}
1417
1418
	public function setContentPagePageSelector( PageSelector $pageSelector ): void {
1419
		$this->pimple['content_page_selector'] = $pageSelector;
1420
	}
1421
1422
	public function getContentPagePageSelector(): PageSelector {
1423
		return $this->pimple['content_page_selector'];
1424
	}
1425
1426
	public function setContentProvider( ContentProvider $contentProvider ): void {
1427
		$this->pimple['content_provider'] = $contentProvider;
1428
	}
1429
1430
	private function getContentProvider(): ContentProvider {
1431
		return $this->pimple['content_provider'];
1432
	}
1433
1434
	public function newMailTemplateFilenameTraversable(): MailTemplateFilenameTraversable {
1435
		return new MailTemplateFilenameTraversable(
1436
			$this->config['twig']['loaders']['filesystem']['template-dir']
1437
		);
1438
	}
1439
1440
}
1441