Completed
Pull Request — master (#1084)
by wiese
65:33
created

FunFunFactory::enablePageCache()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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