Completed
Push — master ( c0f76f...37333c )
by Jeroen De
299:55 queued 234:55
created

FunFunFactory::newBankTransferCodeGenerator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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