Completed
Push — master ( 98b65c...d629c6 )
by Jeroen De
121:01 queued 56:02
created

FunFunFactory::newCreditCardNotificationUseCase()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1.064

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
ccs 3
cts 5
cp 0.6
cc 1
eloc 8
nc 1
nop 1
crap 1.064
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\Fundraising\Frontend\Factories;
6
7
use Doctrine\Common\Cache\Cache;
8
use Doctrine\Common\Cache\FilesystemCache;
9
use Doctrine\Common\Cache\VoidCache;
10
use Doctrine\DBAL\Connection;
11
use Doctrine\DBAL\DriverManager;
12
use Doctrine\ORM\EntityManager;
13
use FileFetcher\ErrorLoggingFileFetcher;
14
use FileFetcher\SimpleFileFetcher;
15
use GuzzleHttp\Client;
16
use NumberFormatter;
17
use Pimple\Container;
18
use Psr\Log\LoggerInterface;
19
use Psr\Log\NullLogger;
20
use Swift_MailTransport;
21
use Swift_NullTransport;
22
use Symfony\Component\Stopwatch\Stopwatch;
23
use Symfony\Component\Translation\TranslatorInterface;
24
use TNvpServiceDispatcher;
25
use Twig_Environment;
26
use Twig_Extensions_Extension_Intl;
27
use Twig_SimpleFunction;
28
use WMDE\Fundraising\ContentProvider\ContentProvider;
29
use WMDE\Fundraising\Frontend\DonationContext\Authorization\DonationAuthorizer;
30
use WMDE\Fundraising\Frontend\DonationContext\Authorization\DonationTokenFetcher;
31
use WMDE\Fundraising\Frontend\DonationContext\DataAccess\DoctrineCommentFinder;
32
use WMDE\Fundraising\Frontend\DonationContext\DataAccess\DoctrineDonationAuthorizer;
33
use WMDE\Fundraising\Frontend\DonationContext\DataAccess\DoctrineDonationEventLogger;
34
use WMDE\Fundraising\Frontend\DonationContext\DataAccess\DoctrineDonationPrePersistSubscriber;
35
use WMDE\Fundraising\Frontend\DonationContext\DataAccess\DoctrineDonationRepository;
36
use WMDE\Fundraising\Frontend\DonationContext\DataAccess\DoctrineDonationTokenFetcher;
37
use WMDE\Fundraising\Frontend\DonationContext\Domain\Repositories\CommentFinder;
38
use WMDE\Fundraising\Frontend\DonationContext\Domain\Repositories\DonationRepository;
39
use WMDE\Fundraising\Frontend\DonationContext\DonationAcceptedEventHandler;
40
use WMDE\Fundraising\Frontend\DonationContext\Infrastructure\BestEffortDonationEventLogger;
41
use WMDE\Fundraising\Frontend\DonationContext\Infrastructure\DonationConfirmationMailer;
42
use WMDE\Fundraising\Frontend\DonationContext\Infrastructure\DonationEventLogger;
43
use WMDE\Fundraising\Frontend\DonationContext\Infrastructure\LoggingCommentFinder;
44
use WMDE\Fundraising\Frontend\DonationContext\Infrastructure\LoggingDonationRepository;
45
use WMDE\Fundraising\Frontend\DonationContext\UseCases\AddComment\AddCommentUseCase;
46
use WMDE\Fundraising\Frontend\DonationContext\UseCases\AddComment\AddCommentValidator;
47
use WMDE\Fundraising\Frontend\DonationContext\UseCases\AddDonation\AddDonationPolicyValidator;
48
use WMDE\Fundraising\Frontend\DonationContext\UseCases\AddDonation\AddDonationUseCase;
49
use WMDE\Fundraising\Frontend\DonationContext\UseCases\AddDonation\AddDonationValidator;
50
use WMDE\Fundraising\Frontend\DonationContext\UseCases\AddDonation\InitialDonationStatusPicker;
51
use WMDE\Fundraising\Frontend\DonationContext\UseCases\AddDonation\ReferrerGeneralizer;
52
use WMDE\Fundraising\Frontend\DonationContext\UseCases\CancelDonation\CancelDonationUseCase;
53
use WMDE\Fundraising\Frontend\DonationContext\UseCases\CreditCardPaymentNotification\CreditCardNotificationUseCase;
54
use WMDE\Fundraising\Frontend\DonationContext\UseCases\HandlePayPalPaymentNotification\HandlePayPalPaymentNotificationUseCase;
55
use WMDE\Fundraising\Frontend\DonationContext\UseCases\ListComments\ListCommentsUseCase;
56
use WMDE\Fundraising\Frontend\DonationContext\UseCases\ShowDonationConfirmation\ShowDonationConfirmationUseCase;
57
use WMDE\Fundraising\Frontend\DonationContext\UseCases\SofortPaymentNotification\SofortPaymentNotificationUseCase;
58
use WMDE\Fundraising\Frontend\DonationContext\Validation\DonorAddressValidator;
59
use WMDE\Fundraising\Frontend\DonationContext\Validation\DonorNameValidator;
60
use WMDE\Fundraising\Frontend\DonationContext\Validation\DonorValidator;
61
use WMDE\Fundraising\Frontend\Infrastructure\Cache\AllOfTheCachePurger;
62
use WMDE\Fundraising\Frontend\Infrastructure\Cache\AuthorizedCachePurger;
63
use WMDE\Fundraising\Frontend\Infrastructure\EmailAddress;
64
use WMDE\Fundraising\Frontend\Infrastructure\InternetDomainNameValidator;
65
use WMDE\Fundraising\Frontend\Infrastructure\LoggingMailer;
66
use WMDE\Fundraising\Frontend\Infrastructure\LoggingPaymentNotificationVerifier;
67
use WMDE\Fundraising\Frontend\Infrastructure\MailTemplateFilenameTraversable;
68
use WMDE\Fundraising\Frontend\Infrastructure\Messenger;
69
use WMDE\Fundraising\Frontend\Infrastructure\OperatorMailer;
70
use WMDE\Fundraising\Frontend\Infrastructure\PageViewTracker;
71
use WMDE\Fundraising\Frontend\Infrastructure\PaymentNotificationVerifier;
72
use WMDE\Fundraising\Frontend\Infrastructure\PayPalPaymentNotificationVerifier;
73
use WMDE\Fundraising\Frontend\Infrastructure\PiwikServerSideTracker;
74
use WMDE\Fundraising\Frontend\Infrastructure\ProfilerDataCollector;
75
use WMDE\Fundraising\Frontend\Infrastructure\ProfilingDecoratorBuilder;
76
use WMDE\Fundraising\Frontend\Infrastructure\RandomTokenGenerator;
77
use WMDE\Fundraising\Frontend\Infrastructure\ServerSideTracker;
78
use WMDE\Fundraising\Frontend\Infrastructure\TemplateBasedMailer;
79
use WMDE\Fundraising\Frontend\Infrastructure\TemplateMailerInterface;
80
use WMDE\Fundraising\Frontend\Infrastructure\TokenGenerator;
81
use WMDE\Fundraising\Frontend\Infrastructure\UrlGenerator;
82
use WMDE\Fundraising\Frontend\Infrastructure\WordListFileReader;
83
use WMDE\Fundraising\Frontend\MembershipContext\Authorization\ApplicationAuthorizer;
84
use WMDE\Fundraising\Frontend\MembershipContext\Authorization\ApplicationTokenFetcher;
85
use WMDE\Fundraising\Frontend\MembershipContext\DataAccess\DoctrineApplicationAuthorizer;
86
use WMDE\Fundraising\Frontend\MembershipContext\DataAccess\DoctrineApplicationPiwikTracker;
87
use WMDE\Fundraising\Frontend\MembershipContext\DataAccess\DoctrineApplicationRepository;
88
use WMDE\Fundraising\Frontend\MembershipContext\DataAccess\DoctrineApplicationTokenFetcher;
89
use WMDE\Fundraising\Frontend\MembershipContext\DataAccess\DoctrineApplicationTracker;
90
use WMDE\Fundraising\Frontend\MembershipContext\DataAccess\DoctrineMembershipApplicationPrePersistSubscriber;
91
use WMDE\Fundraising\Frontend\MembershipContext\Domain\Repositories\ApplicationRepository;
92
use WMDE\Fundraising\Frontend\MembershipContext\Infrastructure\LoggingApplicationRepository;
93
use WMDE\Fundraising\Frontend\MembershipContext\Tracking\ApplicationPiwikTracker;
94
use WMDE\Fundraising\Frontend\MembershipContext\Tracking\ApplicationTracker;
95
use WMDE\Fundraising\Frontend\MembershipContext\UseCases\ApplyForMembership\ApplyForMembershipPolicyValidator;
96
use WMDE\Fundraising\Frontend\MembershipContext\UseCases\ApplyForMembership\ApplyForMembershipUseCase;
97
use WMDE\Fundraising\Frontend\MembershipContext\UseCases\ApplyForMembership\MembershipApplicationValidator;
98
use WMDE\Fundraising\Frontend\MembershipContext\UseCases\CancelMembershipApplication\CancelMembershipApplicationUseCase;
99
use WMDE\Fundraising\Frontend\MembershipContext\UseCases\HandleSubscriptionPaymentNotification\HandleSubscriptionPaymentNotificationUseCase;
100
use WMDE\Fundraising\Frontend\MembershipContext\UseCases\HandleSubscriptionSignupNotification\HandleSubscriptionSignupNotificationUseCase;
101
use WMDE\Fundraising\Frontend\MembershipContext\UseCases\ShowMembershipApplicationConfirmation\ShowMembershipApplicationConfirmationUseCase;
102
use WMDE\Fundraising\Frontend\PaymentContext\DataAccess\McpCreditCardService;
103
use WMDE\Fundraising\Frontend\PaymentContext\DataAccess\Sofort\Transfer\Client as SofortClient;
104
use WMDE\Fundraising\Frontend\PaymentContext\DataAccess\UniqueTransferCodeGenerator;
105
use WMDE\Fundraising\Frontend\PaymentContext\Domain\BankDataConverter;
106
use WMDE\Fundraising\Frontend\PaymentContext\Domain\DefaultPaymentDelayCalculator;
107
use WMDE\Fundraising\Frontend\PaymentContext\Domain\PaymentDelayCalculator;
108
use WMDE\Fundraising\Frontend\PaymentContext\Domain\PaymentUrlGenerator\CreditCard as CreditCardUrlGenerator;
109
use WMDE\Fundraising\Frontend\PaymentContext\Domain\PaymentUrlGenerator\CreditCardConfig;
110
use WMDE\Fundraising\Frontend\PaymentContext\Domain\PaymentUrlGenerator\PayPal as PayPalUrlGenerator;
111
use WMDE\Fundraising\Frontend\PaymentContext\Domain\PaymentUrlGenerator\PayPalConfig;
112
use WMDE\Fundraising\Frontend\PaymentContext\Domain\PaymentUrlGenerator\Sofort as SofortUrlGenerator;
113
use WMDE\Fundraising\Frontend\PaymentContext\Domain\PaymentUrlGenerator\SofortConfig;
114
use WMDE\Fundraising\Frontend\PaymentContext\Domain\SimpleTransferCodeGenerator;
115
use WMDE\Fundraising\Frontend\PaymentContext\Domain\TransferCodeGenerator;
116
use WMDE\Fundraising\Frontend\PaymentContext\Infrastructure\CreditCardService;
117
use WMDE\Fundraising\Frontend\PaymentContext\UseCases\CheckIban\CheckIbanUseCase;
118
use WMDE\Fundraising\Frontend\PaymentContext\UseCases\GenerateIban\GenerateIbanUseCase;
119
use WMDE\Fundraising\Frontend\Presentation\AmountFormatter;
120
use WMDE\Fundraising\Frontend\Presentation\ContentPage\PageSelector;
121
use WMDE\Fundraising\Frontend\Presentation\DonationConfirmationPageSelector;
122
use WMDE\Fundraising\Frontend\Presentation\FilePrefixer;
123
use WMDE\Fundraising\Frontend\Presentation\GreetingGenerator;
124
use WMDE\Fundraising\Frontend\Presentation\Honorifics;
125
use WMDE\Fundraising\Frontend\Presentation\Presenters\AddSubscriptionHtmlPresenter;
126
use WMDE\Fundraising\Frontend\Presentation\Presenters\AddSubscriptionJsonPresenter;
127
use WMDE\Fundraising\Frontend\Presentation\Presenters\CancelDonationHtmlPresenter;
128
use WMDE\Fundraising\Frontend\Presentation\Presenters\CancelMembershipApplicationHtmlPresenter;
129
use WMDE\Fundraising\Frontend\Presentation\Presenters\CommentListHtmlPresenter;
130
use WMDE\Fundraising\Frontend\Presentation\Presenters\CommentListJsonPresenter;
131
use WMDE\Fundraising\Frontend\Presentation\Presenters\CommentListRssPresenter;
132
use WMDE\Fundraising\Frontend\Presentation\Presenters\ConfirmSubscriptionHtmlPresenter;
133
use WMDE\Fundraising\Frontend\Presentation\Presenters\CreditCardNotificationPresenter;
134
use WMDE\Fundraising\Frontend\Presentation\Presenters\CreditCardPaymentHtmlPresenter;
135
use WMDE\Fundraising\Frontend\Presentation\Presenters\DonationConfirmationHtmlPresenter;
136
use WMDE\Fundraising\Frontend\Presentation\Presenters\DonationFormPresenter;
137
use WMDE\Fundraising\Frontend\Presentation\Presenters\DonationFormViolationPresenter;
138
use WMDE\Fundraising\Frontend\Presentation\Presenters\GetInTouchHtmlPresenter;
139
use WMDE\Fundraising\Frontend\Presentation\Presenters\IbanPresenter;
140
use WMDE\Fundraising\Frontend\Presentation\Presenters\InternalErrorHtmlPresenter;
141
use WMDE\Fundraising\Frontend\Presentation\Presenters\MembershipApplicationConfirmationHtmlPresenter;
142
use WMDE\Fundraising\Frontend\Presentation\Presenters\MembershipFormViolationPresenter;
143
use WMDE\Fundraising\Frontend\Presentation\Presenters\PageNotFoundPresenter;
144
use WMDE\Fundraising\Frontend\Presentation\TwigTemplate;
145
use WMDE\Fundraising\Frontend\SubscriptionContext\DataAccess\DoctrineSubscriptionRepository;
146
use WMDE\Fundraising\Frontend\SubscriptionContext\Domain\Repositories\SubscriptionRepository;
147
use WMDE\Fundraising\Frontend\SubscriptionContext\Infrastructure\LoggingSubscriptionRepository;
148
use WMDE\Fundraising\Frontend\SubscriptionContext\UseCases\AddSubscription\AddSubscriptionUseCase;
149
use WMDE\Fundraising\Frontend\SubscriptionContext\UseCases\ConfirmSubscription\ConfirmSubscriptionUseCase;
150
use WMDE\Fundraising\Frontend\SubscriptionContext\Validation\SubscriptionDuplicateValidator;
151
use WMDE\Fundraising\Frontend\SubscriptionContext\Validation\SubscriptionValidator;
152
use WMDE\Fundraising\Frontend\UseCases\GetInTouch\GetInTouchUseCase;
153
use WMDE\Fundraising\Frontend\Validation\AllowedValuesValidator;
154
use WMDE\Fundraising\Frontend\Validation\AmountPolicyValidator;
155
use WMDE\Fundraising\Frontend\Validation\BankDataValidator;
156
use WMDE\Fundraising\Frontend\Validation\EmailValidator;
157
use WMDE\Fundraising\Frontend\Validation\GetInTouchValidator;
158
use WMDE\Fundraising\Frontend\Validation\KontoCheckIbanValidator;
159
use WMDE\Fundraising\Frontend\Validation\MembershipFeeValidator;
160
use WMDE\Fundraising\Frontend\Validation\PaymentDataValidator;
161
use WMDE\Fundraising\Frontend\Validation\TemplateNameValidator;
162
use WMDE\Fundraising\Frontend\Validation\TextPolicyValidator;
163
use WMDE\Fundraising\Store\Factory as StoreFactory;
164
use WMDE\Fundraising\Store\Installer;
165
166
/**
167
 * @licence GNU GPL v2+
168
 */
169
class FunFunFactory {
170
171
	private $config;
172
173
	/**
174
	 * @var Container
175
	 */
176
	private $pimple;
177 160
178 160
	private $addDoctrineSubscribers = true;
179 160
180 160
	/**
181
	 * @var Stopwatch|null
182 160
	 */
183 160
	private $profiler = null;
184
185
	public function __construct( array $config ) {
186 119
		$this->config = $config;
187
		$this->pimple = $this->newPimple();
188
	}
189
190 4
	private function newPimple(): Container {
191
		$pimple = new Container();
192
193
		$pimple['logger'] = function() {
194
			return new NullLogger();
195
		};
196
197
		$pimple['paypal_logger'] = function() {
198 160
			return new NullLogger();
199
		};
200
201
		$pimple['sofort_logger'] = function() {
202 90
			return new NullLogger();
203 90
		};
204 90
205 90
		$pimple['profiler_data_collector'] = function() {
206 90
			return new ProfilerDataCollector();
207
		};
208
209 90
		$pimple['dbal_connection'] = function() {
210
			return DriverManager::getConnection( $this->config['db'] );
211
		};
212
213 9
		$pimple['entity_manager'] = function() {
214 9
			$entityManager = ( new StoreFactory( $this->getConnection(), $this->getVarPath() . '/doctrine_proxies' ) )
215 9
				->getEntityManager();
216
			if ( $this->addDoctrineSubscribers ) {
217
				$entityManager->getEventManager()->addEventSubscriber( $this->newDoctrineDonationPrePersistSubscriber() );
218
				$entityManager->getEventManager()->addEventSubscriber( $this->newDoctrineMembershipApplicationPrePersistSubscriber() );
219
			}
220 47
221 47
			return $entityManager;
222 47
		};
223
224
		$pimple['subscription_repository'] = function() {
225
			return new LoggingSubscriptionRepository(
226
				new DoctrineSubscriptionRepository( $this->getEntityManager() ),
227 14
				$this->getLogger()
228 14
			);
229 14
		};
230
231
		$pimple['donation_repository'] = function() {
232
			return new LoggingDonationRepository(
233
				new DoctrineDonationRepository( $this->getEntityManager() ),
234 12
				$this->getLogger()
235 12
			);
236 12
		};
237
238
		$pimple['membership_application_repository'] = function() {
239 12
			return new LoggingApplicationRepository(
240
				new DoctrineApplicationRepository( $this->getEntityManager() ),
241
				$this->getLogger()
242
			);
243 44
		};
244
245
		$pimple['comment_repository'] = function() {
246
			$finder = new LoggingCommentFinder(
247 7
				new DoctrineCommentFinder( $this->getEntityManager() ),
248 7
				$this->getLogger()
249 7
			);
250 7
251 7
			return $this->addProfilingDecorator( $finder, 'CommentFinder' );
252
		};
253
254
		$pimple['mail_validator'] = function() {
255
			return new EmailValidator( new InternetDomainNameValidator() );
256 8
		};
257
258
		$pimple['subscription_validator'] = function() {
259
			return new SubscriptionValidator(
260 3
				$this->getEmailValidator(),
261
				$this->newTextPolicyValidator( 'fields' ),
262
				$this->newSubscriptionDuplicateValidator(),
263
				$this->newHonorificValidator()
264 56
			);
265
		};
266
267
		$pimple['template_name_validator'] = function() {
268 102
			return new TemplateNameValidator( $this->getSkinTwig() );
269 102
		};
270 102
271
		$pimple['contact_validator'] = function() {
272
			return new GetInTouchValidator( $this->getEmailValidator() );
273
		};
274
275 102
		$pimple['greeting_generator'] = function() {
276 102
			return new GreetingGenerator();
277
		};
278 102
279 102
		$pimple['translator'] = function() {
280
			$translationFactory = new TranslationFactory();
281 102
			$loaders = [
282 102
				'json' => $translationFactory->newJsonLoader()
283 102
			];
284
			$locale = $this->config['locale'];
285
			$messagesPath = $this->getI18nDirectory() . $this->config['translation']['message-dir'];
286
			$translator = $translationFactory->create( $loaders, $locale );
287 102
			foreach ($this->config['translation']['files'] as $domain => $file) {
288
				$translator->addResource( 'json', $messagesPath . '/' . $file, $locale, $domain );
289
			}
290
291 114
			return $translator;
292
		};
293 114
294
		// In the future, this could be locale-specific or filled from a DB table
295 114
		$pimple['honorifics'] = function() {
296 114
			return new Honorifics( [
297 114
				'' => 'Kein Titel',
298 114
				'Dr.' => 'Dr.',
299 114
				'Prof.' => 'Prof.',
300
				'Prof. Dr.' => 'Prof. Dr.'
301
			] );
302
		};
303 114
304 114
		$pimple['twig'] = function() {
305 114
			$twigFactory = $this->newTwigFactory( $this->config['twig'] );
306
			$configurator = $twigFactory->newTwigEnvironmentConfigurator();
307 114
308
			$loaders = array_filter( [
309
				$twigFactory->newFileSystemLoader(),
310 114
				$twigFactory->newArrayLoader(), // This is just a fallback for testing
311 114
			] );
312 114
			$extensions = [
313
				$twigFactory->newTranslationExtension( $this->getTranslator() ),
314 114
				new Twig_Extensions_Extension_Intl()
315
			];
316
			$filters = [
317 114
				$twigFactory->newFilePrefixFilter(
318 114
					$this->getFilePrefixer()
319 114
				)
320
			];
321 114
			$functions = [
322
				new Twig_SimpleFunction(
323
					'web_content',
324 114
					function( string $name, array $context = [] ): string {
325 114
						return $this->getContentProvider()->getWeb( $name, $context );
326 114
					},
327
					[ 'is_safe' => [ 'html' ] ]
328 114
				),
329
			];
330
331 114
			return $configurator->getEnvironment( $this->pimple['skin_twig_environment'], $loaders, $extensions, $filters, $functions );
332
		};
333
334
		$pimple['mailer_twig'] = function() {
335
			$twigFactory = $this->newTwigFactory( $this->config['mailer-twig'] );
336 78
			$configurator = $twigFactory->newTwigEnvironmentConfigurator();
337 78
338
			$loaders = array_filter( [
339
				$twigFactory->newFileSystemLoader(),
340
				$twigFactory->newArrayLoader(), // This is just a fallback for testing
341
			] );
342
			$extensions = [
343
				$twigFactory->newTranslationExtension( $this->getTranslator() ),
344
				new Twig_Extensions_Extension_Intl(),
345 109
			];
346
			$filters = [];
347
			$functions = [
348
				new Twig_SimpleFunction(
349 109
					'mail_content',
350 109
					function( string $name, array $context = [] ): string {
351 109
						return $this->getContentProvider()->getMail( $name, $context );
352 109
					},
353 109
					[ 'is_safe' => [ 'all' ] ]
354 109
				),
355 109
				new Twig_SimpleFunction(
356
					'url',
357
					function( string $name, array $parameters = [] ): string {
358
						return $this->getUrlGenerator()->generateUrl( $name, $parameters );
359 109
					}
360 109
				)
361
			];
362
363 109
			$twigEnvironment = new Twig_Environment();
364 109
365
			return $configurator->getEnvironment( $twigEnvironment, $loaders, $extensions, $filters, $functions );
366
		};
367
368 109
		$pimple['messenger_suborganization'] = function() {
369
			return new Messenger(
370
				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...
371
				$this->getSubOrganizationEmailAddress(),
372
				$this->config['contact-info']['suborganization']['name']
373
			);
374
		};
375
376
		$pimple['messenger_organization'] = function() {
377
			return new Messenger(
378
				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...
379
				$this->getOrganizationEmailAddress(),
380
				$this->config['contact-info']['organization']['name']
381
			);
382
		};
383
384
		$pimple['confirmation-page-selector'] = function() {
385
			return new DonationConfirmationPageSelector( $this->config['confirmation-pages'] );
386
		};
387
388 6
		$pimple['paypal-payment-notification-verifier'] = function() {
389
			return new LoggingPaymentNotificationVerifier(
390
				new PayPalPaymentNotificationVerifier(
391
					new Client(),
392
					$this->config['paypal-donation']['base-url'],
393
					$this->config['paypal-donation']['account-address']
394
				),
395
				$this->getLogger()
396
			);
397
		};
398
399
		$pimple['paypal-membership-fee-notification-verifier'] = function() {
400
			return new LoggingPaymentNotificationVerifier(
401
				new PayPalPaymentNotificationVerifier(
402
					new Client(),
403
					$this->config['paypal-membership']['base-url'],
404
					$this->config['paypal-membership']['account-address']
405
				),
406
				$this->getLogger()
407
			);
408
		};
409
410
		$pimple['credit-card-api-service'] = function() {
411
			return new McpCreditCardService(
412
				new TNvpServiceDispatcher(
413
					'IMcpCreditcardService_v1_5',
414 69
					'https://sipg.micropayment.de/public/creditcard/v1.5/nvp/'
415 69
				),
416 69
				$this->config['creditcard']['access-key'],
417
				$this->config['creditcard']['testmode']
418
			);
419
		};
420
421 112
		$pimple['token_generator'] = function() {
422
			return new RandomTokenGenerator(
423
				$this->config['token-length'],
424
				new \DateInterval( $this->config['token-validity-timestamp'] )
425 109
			);
426
		};
427
428
		$pimple['page_cache'] = function() {
429
			return new VoidCache();
430
		};
431
432 160
		$pimple['rendered_page_cache'] = function() {
433
			return new VoidCache();
434
		};
435 160
436 160
		$pimple['page_view_tracker'] = function () {
437
			return new PageViewTracker( $this->newServerSideTracker(), $this->config['piwik']['siteUrlBase'] );
438
		};
439 90
440 90
		$pimple['cachebusting_fileprefixer'] = function () {
441
			return new FilePrefixer( $this->getFilePrefix() );
442
		};
443 11
444 11
		$pimple['content_page_selector'] = function () {
445 11
			$json = (new SimpleFileFetcher())->fetchFile( $this->getI18nDirectory() . '/data/pages.json' );
446 11
			$config = json_decode( $json, true ) ?? [];
447
448
			return new PageSelector( $config );
449
		};
450 160
451 160
		$pimple['content_provider'] = function () {
452
			return new ContentProvider( [
453
				'content_path' => $this->getI18nDirectory(),
454 12
				'cache' => $this->config['twig']['enable-cache'] ? $this->getCachePath() . '/content' : false,
455 12
				'globals' => [
456
					'basepath' => $this->config['web-basepath']
457
				]
458 6
			] );
459 6
		};
460
461
		$pimple['payment-delay-calculator'] = function() {
462 2
			return new DefaultPaymentDelayCalculator( $this->getPaymentDelayInDays() );
463 2
		};
464 2
465 2
		$pimple['sofort-client'] = function () {
466
			$config = $this->config['sofort'];
467
			return new SofortClient( $config['config-key'] );
468
		};
469 4
470 4
		return $pimple;
471
	}
472
473 12
	public function getConnection(): Connection {
474 12
		return $this->pimple['dbal_connection'];
475
	}
476
477 10
	public function getEntityManager(): EntityManager {
478 10
		return $this->pimple['entity_manager'];
479
	}
480
481 1
	private function newDonationEventLogger(): DonationEventLogger {
482 1
		return new BestEffortDonationEventLogger(
483 1
			new DoctrineDonationEventLogger( $this->getEntityManager() ),
484
			$this->getLogger()
485 7
		);
486 7
	}
487
488
	public function newInstaller(): Installer {
489 46
		return ( new StoreFactory( $this->getConnection() ) )->newInstaller();
490 46
	}
491
492
	public function newListCommentsUseCase(): ListCommentsUseCase {
493 8
		return new ListCommentsUseCase( $this->getCommentFinder() );
494 8
	}
495
496
	public function newCommentListJsonPresenter(): CommentListJsonPresenter {
497 1
		return new CommentListJsonPresenter();
498 1
	}
499
500
	public function newCommentListRssPresenter(): CommentListRssPresenter {
501 3
		return new CommentListRssPresenter( new TwigTemplate(
502 3
			$this->getSkinTwig(),
503 3
			'Comment_List.rss.twig'
504 3
		) );
505
	}
506
507
	public function newCommentListHtmlPresenter(): CommentListHtmlPresenter {
508 3
		return new CommentListHtmlPresenter( $this->getLayoutTemplate( 'Comment_List.html.twig', [ 'piwikGoals' => [ 1 ] ] ) );
509 3
	}
510
511
	private function getCommentFinder(): CommentFinder {
512 1
		return $this->pimple['comment_repository'];
513 1
	}
514
515
	public function getSubscriptionRepository(): SubscriptionRepository {
516 160
		return $this->pimple['subscription_repository'];
517 160
	}
518 160
519
	public function setSubscriptionRepository( SubscriptionRepository $subscriptionRepository ): void {
520 109
		$this->pimple['subscription_repository'] = $subscriptionRepository;
521 109
	}
522
523
	private function getSubscriptionValidator(): SubscriptionValidator {
524
		return $this->pimple['subscription_validator'];
525
	}
526
527
	public function getEmailValidator(): EmailValidator {
528
		return $this->pimple['mail_validator'];
529
	}
530
531 43
	public function getTemplateNameValidator(): TemplateNameValidator {
532 43
		return $this->pimple['template_name_validator'];
533 43
	}
534
535 43
	public function newAddSubscriptionHtmlPresenter(): AddSubscriptionHtmlPresenter {
536
		return new AddSubscriptionHtmlPresenter( $this->getLayoutTemplate( 'Subscription_Form.html.twig' ), $this->getTranslator() );
537
	}
538
539
	public function newConfirmSubscriptionHtmlPresenter(): ConfirmSubscriptionHtmlPresenter {
540
		return new ConfirmSubscriptionHtmlPresenter(
541
			$this->getLayoutTemplate( 'Confirm_Subscription.twig' ),
542
			$this->getTranslator()
543
		);
544
	}
545 30
546 30
	public function newAddSubscriptionJsonPresenter(): AddSubscriptionJsonPresenter {
547 30
		return new AddSubscriptionJsonPresenter( $this->getTranslator() );
548 30
	}
549
550 30
	public function newGetInTouchHtmlPresenter(): GetInTouchHtmlPresenter {
551 30
		return new GetInTouchHtmlPresenter( $this->getLayoutTemplate( 'contact_form.html.twig' ), $this->getTranslator() );
552
	}
553
554
	public function setSkinTwigEnvironment( Twig_Environment $twig ): void {
555
		$this->pimple['skin_twig_environment'] = $twig;
556
	}
557 72
558
	public function getSkinTwig(): Twig_Environment {
559 72
		return $this->pimple['twig'];
560 72
	}
561 72
562 72
	public function getMailerTwig(): Twig_Environment {
563 72
		return $this->pimple['mailer_twig'];
564 72
	}
565
566
	/**
567
	 * Get a template, with the content for the layout areas filled in.
568 20
	 *
569 20
	 * @param string $templateName
570 20
	 * @param array $context Additional variables for the template
571 20
	 * @return TwigTemplate
572
	 */
573
	public function getLayoutTemplate( string $templateName, array $context = [] ): TwigTemplate {
574
		 return new TwigTemplate(
575 112
			$this->getSkinTwig(),
576 112
			$templateName,
577
			array_merge( $this->getDefaultTwigVariables(), $context )
578
		);
579 10
	}
580 10
581 10
	public function getMailerTemplate( string $templateName, array $context = [] ): TwigTemplate {
582
		return new TwigTemplate(
583 102
			$this->getMailerTwig(),
584 102
			$templateName,
585
			array_merge( $this->getDefaultTwigVariables(), $context )
586
		);
587 112
	}
588 112
589 112
	/**
590 112
	 * Get a layouted template that includes another template
591
	 *
592
	 * @deprecated Change the template to use extend and block and call getLayoutTemplate instead.
593 112
	 *
594
	 * @param string $templateName Template to include
595
	 * @return TwigTemplate
596 109
	 */
597 109
	private function getIncludeTemplate( string $templateName, array $context = [] ): TwigTemplate {
598 109
		return new TwigTemplate(
599 109
			$this->getSkinTwig(),
600
			'Include_in_Layout.twig',
601
			array_merge(
602 109
				$this->getDefaultTwigVariables(),
603
				[ 'main_template' => $templateName ],
604
				$context
605 112
			)
606 112
		);
607 112
	}
608 112
609 112
	private function getDefaultTwigVariables(): array {
610 112
		return [
611 112
			'honorifics' => $this->getHonorifics()->getList(),
612
			'header_template' => $this->config['default-layout-templates']['header'],
613
			'footer_template' => $this->config['default-layout-templates']['footer'],
614
			'no_js_notice_template' => $this->config['default-layout-templates']['no-js-notice'],
615 109
			'piwik' => $this->config['piwik'],
616 109
			'locale' => $this->config['locale'],
617 109
		];
618 109
	}
619 109
620 109
	private function newReferrerGeneralizer(): ReferrerGeneralizer {
621 109
		return new ReferrerGeneralizer(
622
			$this->config['referrer-generalization']['default'],
623
			$this->config['referrer-generalization']['domain-map']
624
		);
625 119
	}
626 119
627
	public function getLogger(): LoggerInterface {
628
		return $this->pimple['logger'];
629 6
	}
630 6
631
	public function getPaypalLogger(): LoggerInterface {
632
		return $this->pimple['paypal_logger'];
633 127
	}
634 127
635
	public function getSofortLogger(): LoggerInterface {
636
		return $this->pimple['sofort_logger'];
637 109
	}
638 109
639
	private function getVarPath(): string {
640
		return __DIR__ . '/../../var';
641
	}
642
643
	public function getCachePath(): string {
644
		return $this->getVarPath() . '/cache';
645
	}
646
647
	public function getLoggingPath(): string {
648
		return $this->getVarPath() . '/log';
649 7
	}
650 7
651 7
	public function getTemplatePath(): string {
652 7
		return __DIR__ . '/../../app/fundraising-frontend-content/templates';
653 7
	}
654
655
	public function newAddSubscriptionUseCase(): AddSubscriptionUseCase {
656
		return new AddSubscriptionUseCase(
657 3
			$this->getSubscriptionRepository(),
658 3
			$this->getSubscriptionValidator(),
659 3
			$this->newAddSubscriptionMailer()
660 3
		);
661
	}
662
663
	public function newConfirmSubscriptionUseCase(): ConfirmSubscriptionUseCase {
664 7
		return new ConfirmSubscriptionUseCase(
665 7
			$this->getSubscriptionRepository(),
666 7
			$this->newConfirmSubscriptionMailer()
667 7
		);
668 7
	}
669 7
670
	private function newAddSubscriptionMailer(): TemplateMailerInterface {
671 7
		return $this->newTemplateMailer(
672 7
			$this->getSuborganizationMessenger(),
673
			new TwigTemplate(
674
				$this->getMailerTwig(),
675 7
				'Subscription_Request.txt.twig',
676
				[
677
					'greeting_generator' => $this->getGreetingGenerator()
678
				]
679 3
			),
680 3
			'mail_subject_subscription'
681 3
		);
682 3
	}
683 3
684 3
	private function newConfirmSubscriptionMailer(): TemplateMailerInterface {
685 3
		return $this->newTemplateMailer(
686
			$this->getSuborganizationMessenger(),
687 3
			new TwigTemplate(
688
					$this->getMailerTwig(),
689
					'Subscription_Confirmation.txt.twig',
690
					[ 'greeting_generator' => $this->getGreetingGenerator() ]
691 59
			),
692 59
			'mail_subject_subscription_confirmed'
693
		);
694
	}
695 59
696
	/**
697
	 * Create a new TemplateMailer instance
698 59
	 *
699
	 * So much decoration going on that explicitly hinting what we return (Robustness principle) would be confusing
700 59
	 * (you'd expect a TemplateBasedMailer, not a LoggingMailer), so we hint the interface instead.
701
	 */
702
	private function newTemplateMailer( Messenger $messenger, TwigTemplate $template, string $messageKey ): TemplateMailerInterface {
703 56
		$mailer = new TemplateBasedMailer(
704 56
			$messenger,
705
			$template,
706
			$this->getTranslator()->trans( $messageKey )
707
		);
708
709
		$mailer = new LoggingMailer( $mailer, $this->getLogger() );
710
711
		return $this->addProfilingDecorator( $mailer, 'Mailer' );
712
	}
713
714
	public function getGreetingGenerator(): GreetingGenerator {
715
		return $this->pimple['greeting_generator'];
716
	}
717
718
	public function newCheckIbanUseCase(): CheckIbanUseCase {
719 31
		return new CheckIbanUseCase( $this->newBankDataConverter(), $this->newIbanValidator() );
720 31
	}
721
722
	public function newGenerateIbanUseCase(): GenerateIbanUseCase {
723
		return new GenerateIbanUseCase( $this->newBankDataConverter(), $this->newIbanValidator() );
724
	}
725
726
	public function newIbanPresenter(): IbanPresenter {
727
		return new IbanPresenter();
728
	}
729
730
	public function newBankDataConverter(): BankDataConverter {
731 3
		return new BankDataConverter( $this->config['bank-data-file'] );
732 3
	}
733 3
734 3
	public function setSubscriptionValidator( SubscriptionValidator $subscriptionValidator ): void {
735 3
		$this->pimple['subscription_validator'] = $subscriptionValidator;
736
	}
737
738
	public function newGetInTouchUseCase(): GetInTouchUseCase {
739 3
		return new GetInTouchUseCase(
740 3
			$this->getContactValidator(),
741 3
			$this->newContactOperatorMailer(),
742 3
			$this->newContactUserMailer()
743 3
		);
744
	}
745
746
	private function newContactUserMailer(): TemplateMailerInterface {
747 3
		return $this->newTemplateMailer(
748 3
			$this->getSuborganizationMessenger(),
749 3
			new TwigTemplate( $this->getMailerTwig(), 'Contact_Confirm_to_User.txt.twig' ),
750 3
			'mail_subject_getintouch'
751 3
		);
752
	}
753
754
	private function newContactOperatorMailer(): OperatorMailer {
755 3
		return new OperatorMailer(
756 3
			$this->getSuborganizationMessenger(),
757
			new TwigTemplate( $this->getMailerTwig(), 'Contact_Forward_to_Operator.txt.twig' ),
758
			$this->getTranslator()->trans( 'mail_subject_getintouch_forward' )
759 7
		);
760 7
	}
761 7
762 7
	private function getContactValidator(): GetInTouchValidator {
763
		return $this->pimple['contact_validator'];
764
	}
765
766 7
	private function newSubscriptionDuplicateValidator(): SubscriptionDuplicateValidator {
767 7
		return new SubscriptionDuplicateValidator(
768 7
				$this->getSubscriptionRepository(),
769 7
				$this->newSubscriptionDuplicateCutoffDate()
770
		);
771
	}
772 7
773 7
	private function newSubscriptionDuplicateCutoffDate(): \DateTime {
774
		$cutoffDateTime = new \DateTime();
775
		$cutoffDateTime->sub( new \DateInterval( $this->config['subscription-interval'] ) );
776 78
		return $cutoffDateTime;
777 78
	}
778
779
	private function newHonorificValidator(): AllowedValuesValidator {
780 1
		return new AllowedValuesValidator( $this->getHonorifics()->getKeys() );
781 1
	}
782 1
783 1
	private function getHonorifics(): Honorifics {
784
		return $this->pimple['honorifics'];
785
	}
786
787 31
	public function newAuthorizedCachePurger(): AuthorizedCachePurger {
788 31
		return new AuthorizedCachePurger(
789
			new AllOfTheCachePurger( $this->getSkinTwig(), $this->getPageCache(), $this->getRenderedPageCache() ),
790
			$this->config['purging-secret']
791 46
		);
792 46
	}
793
794
	private function newBankDataValidator(): BankDataValidator {
795 160
		return new BankDataValidator( $this->newIbanValidator() );
796 160
	}
797 160
798
	private function getSuborganizationMessenger(): Messenger {
799 13
		return $this->pimple['messenger_suborganization'];
800 13
	}
801
802
	public function setSuborganizationMessenger( Messenger $messenger ): void {
803 160
		$this->pimple['messenger_suborganization'] = $messenger;
804 160
	}
805 160
806
	private function getOrganizationMessenger(): Messenger {
807 160
		return $this->pimple['messenger_organization'];
808 160
	}
809 160
810 160
	public function setOrganizationMessenger( Messenger $messenger ): void {
811
		$this->pimple['messenger_organization'] = $messenger;
812 160
	}
813 160
814 160
	public function setNullMessenger(): void {
815
		$this->setSuborganizationMessenger( new Messenger(
816 160
			Swift_NullTransport::newInstance(),
817
			$this->getSubOrganizationEmailAddress()
818 160
		) );
819 160
		$this->setOrganizationMessenger( new Messenger(
820
			Swift_NullTransport::newInstance(),
821
			$this->getOrganizationEmailAddress()
822 160
		) );
823 160
	}
824
825
	public function getSubOrganizationEmailAddress(): EmailAddress {
826 3
		return new EmailAddress( $this->config['contact-info']['suborganization']['email'] );
827 3
	}
828
829
	public function getOrganizationEmailAddress(): EmailAddress {
830 3
		return new EmailAddress( $this->config['contact-info']['organization']['email'] );
831 3
	}
832
833
	public function newInternalErrorHtmlPresenter(): InternalErrorHtmlPresenter {
834 116
		return new InternalErrorHtmlPresenter( $this->getIncludeTemplate( 'Error_Page.html.twig' ) );
0 ignored issues
show
Deprecated Code introduced by
The method WMDE\Fundraising\Fronten...y::getIncludeTemplate() has been deprecated with message: Change the template to use extend and block and call getLayoutTemplate instead.

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

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

Loading history...
835 116
	}
836
837
	public function newAccessDeniedHtmlPresenter(): InternalErrorHtmlPresenter {
838 2
		return new InternalErrorHtmlPresenter( $this->getLayoutTemplate( 'Access_Denied.twig' ) );
839 2
	}
840 2
841
	public function getTranslator(): TranslatorInterface {
842 109
		return $this->pimple['translator'];
843 109
	}
844
845
	public function setTranslator( TranslatorInterface $translator ): void {
846 41
		$this->pimple['translator'] = $translator;
847 41
	}
848 41
849
	private function newTwigFactory( array $twigConfig ): TwigFactory {
850 41
		return new TwigFactory(
851 41
			array_merge_recursive(
852 41
				$twigConfig,
853
				[ 'web-basepath' => $this->config['web-basepath'] ]
854
			),
855
			$this->getCachePath() . '/twig',
856 3
			$this->config['locale']
857 3
		);
858
	}
859
860 5
	private function newTextPolicyValidator( string $policyName ): TextPolicyValidator {
861 5
		$fetcher = new ErrorLoggingFileFetcher(
862 5
			new SimpleFileFetcher(),
863 5
			$this->getLogger()
864 5
		);
865 5
		$textPolicyConfig = $this->config['text-policies'][$policyName];
866
		return new TextPolicyValidator(
867
			new WordListFileReader(
868
				$fetcher,
869 5
				$textPolicyConfig['badwords'] ? $this->getAbsolutePath( $textPolicyConfig['badwords'] ) : ''
870 5
			),
871 5
			new WordListFileReader(
872 5
				$fetcher,
873 5
				$textPolicyConfig['whitewords'] ? $this->getAbsolutePath( $textPolicyConfig['whitewords'] ) : ''
874 5
			)
875 5
		);
876
	}
877 5
878
	private function newCommentPolicyValidator(): TextPolicyValidator {
879
		return $this->newTextPolicyValidator( 'comment' );
880
	}
881 20
882 20
	public function newCancelDonationUseCase( string $updateToken ): CancelDonationUseCase {
883 20
		return new CancelDonationUseCase(
884 20
			$this->getDonationRepository(),
885 20
			$this->newCancelDonationMailer(),
886 20
			$this->newDonationAuthorizer( $updateToken ),
887 20
			$this->newDonationEventLogger()
888 20
		);
889 20
	}
890
891
	private function newCancelDonationMailer(): TemplateMailerInterface {
892
		return $this->newTemplateMailer(
893 20
			$this->getSuborganizationMessenger(),
894 20
			new TwigTemplate(
895 20
				$this->getMailerTwig(),
896 20
				'Donation_Cancellation_Confirmation.txt.twig',
897
				[ 'greeting_generator' => $this->getGreetingGenerator() ]
898
			),
899
			'mail_subject_confirm_cancellation'
900 20
		);
901 20
	}
902 20
903 20
	public function newAddDonationUseCase(): AddDonationUseCase {
904 20
		return new AddDonationUseCase(
905
			$this->getDonationRepository(),
906
			$this->newDonationValidator(),
907
			$this->newDonationPolicyValidator(),
908 2
			$this->newReferrerGeneralizer(),
909 2
			$this->newDonationConfirmationMailer(),
910 2
			$this->newBankTransferCodeGenerator(),
911 2
			$this->newDonationTokenFetcher(),
912 2
			new InitialDonationStatusPicker()
913
		);
914
	}
915
916 28
	private function newBankTransferCodeGenerator(): TransferCodeGenerator {
917 28
		return new UniqueTransferCodeGenerator(
918 28
			new SimpleTransferCodeGenerator(),
919 28
			$this->getEntityManager()
920 28
		);
921 28
	}
922 28
923
	private function newDonationValidator(): AddDonationValidator {
924 28
		return new AddDonationValidator(
925 28
			$this->newPaymentDataValidator(),
926
			$this->newBankDataValidator(),
927
			$this->getEmailValidator()
928 28
		);
929
	}
930
931
	public function newPersonalInfoValidator(): DonorValidator {
932
		return new DonorValidator(
933 2
			new DonorNameValidator(),
934 2
			new DonorAddressValidator(),
935
			$this->getEmailValidator()
936
		);
937 2
	}
938 2
939
	private function newDonationConfirmationMailer(): DonationConfirmationMailer {
940
		return new DonationConfirmationMailer(
941 2
			$this->newTemplateMailer(
942 2
				$this->getSuborganizationMessenger(),
943
				new TwigTemplate(
944
					$this->getMailerTwig(),
945 2
					'Donation_Confirmation.txt.twig',
946 2
					[
947
						'greeting_generator' => $this->getGreetingGenerator()
948
					]
949 3
				),
950 3
				'mail_subject_confirm_donation'
951
			)
952
		);
953 3
	}
954 3
955
	public function newPayPalUrlGeneratorForDonations(): PayPalUrlGenerator {
956
		return new PayPalUrlGenerator(
957 47
			$this->getPayPalUrlConfigForDonations(),
958 47
			$this->getTranslator()->trans( 'item_name_donation' )
959
		);
960
	}
961 36
962 36
	public function newPayPalUrlGeneratorForMembershipApplications(): PayPalUrlGenerator {
963
		return new PayPalUrlGenerator(
964
			$this->getPayPalUrlConfigForMembershipApplications(),
965 19
			$this->getTranslator()->trans( 'item_name_membership' )
966 19
		);
967
	}
968
969 2
	private function getPayPalUrlConfigForDonations(): PayPalConfig {
970 2
		return PayPalConfig::newFromConfig( $this->config['paypal-donation'] );
971
	}
972
973 3
	private function getPayPalUrlConfigForMembershipApplications(): PayPalConfig {
974 3
		return PayPalConfig::newFromConfig( $this->config['paypal-membership'] );
975 3
	}
976 3
977 3
	public function newSofortUrlGeneratorForDonations(): SofortUrlGenerator {
978 3
		$config = $this->config['sofort'];
979
980
		return new SofortUrlGenerator(
981
			new SofortConfig(
982 29
				$this->getTranslator()->trans( 'item_name_donation', [], 'messages' ),
983 29
				$config['return-url'],
984 29
				$config['cancel-url'],
985
				$config['notification-url']
986
			),
987
			$this->getSofortClient()
988
		);
989
	}
990 90
991 90
	public function setSofortClient( SofortClient $client ): void {
992
		$this->pimple['sofort-client'] = $client;
993
	}
994 10
995 10
	private function getSofortClient(): SofortClient {
996 10
		return $this->pimple['sofort-client'];
997
	}
998
999
	private function newCreditCardUrlGenerator(): CreditCardUrlGenerator {
1000 3
		return new CreditCardUrlGenerator( $this->newCreditCardUrlConfig() );
1001 3
	}
1002 3
1003 3
	private function newCreditCardUrlConfig(): CreditCardConfig {
1004 3
		return CreditCardConfig::newFromConfig( $this->config['creditcard'] );
1005
	}
1006
1007
	public function getDonationRepository(): DonationRepository {
1008 5
		return $this->pimple['donation_repository'];
1009 5
	}
1010 5
1011
	public function newPaymentDataValidator(): PaymentDataValidator {
1012
		return new PaymentDataValidator(
1013
			$this->config['donation-minimum-amount'],
1014 11
			$this->config['donation-maximum-amount'],
1015 11
			$this->getEnabledDonationPaymentTypes()
1016 11
		);
1017 11
	}
1018 11
1019 11
	private function newAmountFormatter(): AmountFormatter {
1020 11
		return new AmountFormatter( $this->config['locale'] );
1021 11
	}
1022 11
1023
	public function newDecimalNumberFormatter(): NumberFormatter {
1024
		return new NumberFormatter( $this->config['locale'], NumberFormatter::DECIMAL );
1025
	}
1026 11
1027 11
	public function newAddCommentUseCase( string $updateToken ): AddCommentUseCase {
1028 11
		return new AddCommentUseCase(
1029 11
			$this->getDonationRepository(),
1030 11
			$this->newDonationAuthorizer( $updateToken ),
1031 11
			$this->newCommentPolicyValidator(),
1032 11
			$this->newAddCommentValidator()
1033
		);
1034 11
	}
1035
1036
	private function newDonationAuthorizer( string $updateToken = null, string $accessToken = null ): DonationAuthorizer {
1037
		return new DoctrineDonationAuthorizer(
1038 11
			$this->getEntityManager(),
1039 11
			$updateToken,
1040 11
			$accessToken
1041 11
		);
1042 11
	}
1043
1044
	public function getTokenGenerator(): TokenGenerator {
1045
		return $this->pimple['token_generator'];
1046 11
	}
1047 11
1048
	public function newDonationConfirmationPresenter(): DonationConfirmationHtmlPresenter {
1049
		return new DonationConfirmationHtmlPresenter(
1050 11
			$this->getIncludeTemplate(
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...
1051 11
				'Donation_Confirmation.html.twig',
1052
				[
1053
					'piwikGoals' => [ 3 ],
1054 11
					'paymentTypes' => $this->getEnabledMembershipApplicationPaymentTypes()
1055 11
				]
1056
			)
1057
		);
1058 2
	}
1059 2
1060 2
	public function newCreditCardPaymentHtmlPresenter(): CreditCardPaymentHtmlPresenter {
1061 2
		return new CreditCardPaymentHtmlPresenter(
1062 2
			$this->getIncludeTemplate( 'Credit_Card_Payment_Iframe.html.twig' ),
0 ignored issues
show
Deprecated Code introduced by
The method WMDE\Fundraising\Fronten...y::getIncludeTemplate() has been deprecated with message: Change the template to use extend and block and call getLayoutTemplate instead.

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

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

Loading history...
1063
			$this->getTranslator(),
1064
			$this->newCreditCardUrlGenerator()
1065
		);
1066 3
	}
1067
1068
	public function newCancelDonationHtmlPresenter(): CancelDonationHtmlPresenter {
1069 3
		return new CancelDonationHtmlPresenter(
1070 3
			$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...
1071
		);
1072
	}
1073
1074
	public function newApplyForMembershipUseCase(): ApplyForMembershipUseCase {
1075
		return new ApplyForMembershipUseCase(
1076 14
			$this->getMembershipApplicationRepository(),
1077 14
			$this->newMembershipApplicationTokenFetcher(),
1078
			$this->newApplyForMembershipMailer(),
1079
			$this->newMembershipApplicationValidator(),
1080 2
			$this->newApplyForMembershipPolicyValidator(),
1081 2
			$this->newMembershipApplicationTracker(),
1082 2
			$this->newMembershipApplicationPiwikTracker(),
1083 2
			$this->getPaymentDelayCalculator()
1084 2
		);
1085 2
	}
1086 2
1087
	private function newApplyForMembershipMailer(): TemplateMailerInterface {
1088 2
		return $this->newTemplateMailer(
1089
			$this->getOrganizationMessenger(),
1090
			new TwigTemplate(
1091
				$this->getMailerTwig(),
1092 1
				'Membership_Application_Confirmation.txt.twig',
1093 1
				[ 'greeting_generator' => $this->getGreetingGenerator() ]
1094 1
			),
1095 1
			'mail_subject_confirm_membership_application'
1096
		);
1097
	}
1098
1099 13
	private function newMembershipApplicationValidator(): MembershipApplicationValidator {
1100 13
		return new MembershipApplicationValidator(
1101 13
			new MembershipFeeValidator(),
1102 13
			$this->newBankDataValidator(),
1103 13
			$this->getEmailValidator()
1104
		);
1105
	}
1106
1107 7
	private function newMembershipApplicationTracker(): ApplicationTracker {
1108 7
		return new DoctrineApplicationTracker( $this->getEntityManager() );
1109 7
	}
1110
1111 10
	private function newMembershipApplicationPiwikTracker(): ApplicationPiwikTracker {
1112 10
		return new DoctrineApplicationPiwikTracker( $this->getEntityManager() );
1113
	}
1114
1115 4
	private function getPaymentDelayCalculator(): PaymentDelayCalculator {
1116
		return $this->pimple['payment-delay-calculator'];
1117
	}
1118 4
1119 4
	public function getPaymentDelayInDays(): int {
1120
		return $this->getPayPalUrlConfigForMembershipApplications()->getDelayInDays();
1121
	}
1122 15
1123
	public function setPaymentDelayCalculator( PaymentDelayCalculator $paymentDelayCalculator ): void {
1124
		$this->pimple['payment-delay-calculator'] = $paymentDelayCalculator;
1125 15
	}
1126 15
1127
	private function newApplyForMembershipPolicyValidator(): ApplyForMembershipPolicyValidator {
1128
		return new ApplyForMembershipPolicyValidator(
1129 4
			$this->newTextPolicyValidator( 'fields' ),
1130 4
			$this->config['email-address-blacklist']
1131 4
		);
1132 4
	}
1133 4
1134 4
	public function newCancelMembershipApplicationUseCase( string $updateToken ): CancelMembershipApplicationUseCase {
1135
		return new CancelMembershipApplicationUseCase(
1136
			$this->newMembershipApplicationAuthorizer( $updateToken ),
1137
			$this->getMembershipApplicationRepository(),
1138 7
			$this->newCancelMembershipApplicationMailer()
1139 7
		);
1140
	}
1141
1142 7
	private function newMembershipApplicationAuthorizer(
1143 7
		string $updateToken = null, string $accessToken = null ): ApplicationAuthorizer {
1144 7
1145
		return new DoctrineApplicationAuthorizer(
1146 2
			$this->getEntityManager(),
1147 2
			$updateToken,
1148 2
			$accessToken
1149 2
		);
1150 2
	}
1151 2
1152 2
	public function getMembershipApplicationRepository(): ApplicationRepository {
1153 2
		return $this->pimple['membership_application_repository'];
1154
	}
1155
1156
	private function newCancelMembershipApplicationMailer(): TemplateMailerInterface {
1157 2
		return $this->newTemplateMailer(
1158 2
			$this->getOrganizationMessenger(),
1159 2
			new TwigTemplate(
1160
				$this->getMailerTwig(),
1161
				'Membership_Application_Cancellation_Confirmation.txt.twig',
1162
				[ 'greeting_generator' => $this->getGreetingGenerator() ]
1163 1
			),
1164 1
			'mail_subject_confirm_membership_application_cancellation'
1165 1
		);
1166
	}
1167
1168
	public function newMembershipApplicationConfirmationUseCase( string $accessToken ): ShowMembershipApplicationConfirmationUseCase {
1169 2
		return new ShowMembershipApplicationConfirmationUseCase(
1170 2
			$this->newMembershipApplicationAuthorizer( null, $accessToken ), $this->getMembershipApplicationRepository(),
1171 2
			$this->newMembershipApplicationTokenFetcher()
1172
		);
1173
	}
1174
1175 2
	public function newShowDonationConfirmationUseCase( string $accessToken ): ShowDonationConfirmationUseCase {
1176 2
		return new ShowDonationConfirmationUseCase(
1177 2
			$this->newDonationAuthorizer( null, $accessToken ),
1178
			$this->newDonationTokenFetcher(),
1179 2
			$this->getDonationRepository()
1180 2
		);
1181
	}
1182
1183 2
	public function setDonationConfirmationPageSelector( DonationConfirmationPageSelector $selector ): void {
1184 2
		$this->pimple['confirmation-page-selector'] = $selector;
1185 2
	}
1186 2
1187 2
	public function getDonationConfirmationPageSelector(): DonationConfirmationPageSelector {
1188 2
		return $this->pimple['confirmation-page-selector'];
1189
	}
1190
1191
	public function newDonationFormViolationPresenter(): DonationFormViolationPresenter {
1192
		return new DonationFormViolationPresenter( $this->getDonationFormTemplate(), $this->newAmountFormatter() );
1193 90
	}
1194 90
1195 90
	public function newDonationFormPresenter(): DonationFormPresenter {
1196
		return new DonationFormPresenter( $this->getDonationFormTemplate(), $this->newAmountFormatter() );
1197
	}
1198
1199
	private function getDonationFormTemplate(): TwigTemplate {
1200
		// TODO make the template name dependent on the 'form' value from the HTTP POST request
1201 90
		// (we need different form pages for A/B testing)
1202 90
		return $this->getLayoutTemplate( 'Donation_Form.html.twig', [
1203 90
			'paymentTypes' => $this->getEnabledDonationPaymentTypes()
1204
		] );
1205
	}
1206
1207
	private function getEnabledDonationPaymentTypes(): array {
1208
		return array_keys( array_filter( $this->config['payment-types'], function ( $config ) {
1209 21
			return ( $config['donation-enabled'] === true );
1210 21
		} ) );
1211 21
	}
1212
1213
	public function getMembershipApplicationFormTemplate(): TwigTemplate {
1214
		return $this->getLayoutTemplate( 'Membership_Application.html.twig', [
1215
			'paymentTypes' => $this->getEnabledMembershipApplicationPaymentTypes()
1216
		] );
1217 30
	}
1218 30
1219 30
	private function getEnabledMembershipApplicationPaymentTypes(): array {
1220
		return array_keys( array_filter( $this->config['payment-types'], function ( $config ) {
1221
			return ( $config['membership-enabled'] === true );
1222
		} ) );
1223 12
	}
1224 12
1225 12
	public function newHandleSofortPaymentNotificationUseCase( string $updateToken ): SofortPaymentNotificationUseCase {
1226
		return new SofortPaymentNotificationUseCase(
1227
			$this->getDonationRepository(),
1228
			$this->newDonationAuthorizer( $updateToken ),
1229 20
			$this->newDonationConfirmationMailer()
1230 20
		);
1231 20
	}
1232 20
1233
	public function newHandlePayPalPaymentNotificationUseCase( string $updateToken ): HandlePayPalPaymentNotificationUseCase {
1234
		return new HandlePayPalPaymentNotificationUseCase(
1235
			$this->getDonationRepository(),
1236 20
			$this->newDonationAuthorizer( $updateToken ),
1237
			$this->newDonationConfirmationMailer(),
1238 20
			$this->newDonationEventLogger()
1239
		);
1240
	}
1241 2
1242 2
	public function newMembershipApplicationSubscriptionSignupNotificationUseCase( string $updateToken ): HandleSubscriptionSignupNotificationUseCase {
1243
		return new HandleSubscriptionSignupNotificationUseCase(
1244
			$this->getMembershipApplicationRepository(),
1245 2
			$this->newMembershipApplicationAuthorizer( $updateToken ),
1246 2
			$this->newApplyForMembershipMailer(),
1247 2
			$this->getLogger()
1248
		);
1249
	}
1250 2
1251 2
	public function newMembershipApplicationSubscriptionPaymentNotificationUseCase( string $updateToken ): HandleSubscriptionPaymentNotificationUseCase {
1252
		return new HandleSubscriptionPaymentNotificationUseCase(
1253
			$this->getMembershipApplicationRepository(),
1254 3
			$this->newMembershipApplicationAuthorizer( $updateToken ),
1255 3
			$this->newApplyForMembershipMailer(),
1256
			$this->getLogger()
1257
		);
1258 112
	}
1259 112
1260
	public function getPayPalPaymentNotificationVerifier(): PaymentNotificationVerifier {
1261
		return $this->pimple['paypal-payment-notification-verifier'];
1262 109
	}
1263 109
1264
	public function setPayPalPaymentNotificationVerifier( PaymentNotificationVerifier $verifier ): void {
1265
		$this->pimple['paypal-payment-notification-verifier'] = $verifier;
1266
	}
1267
1268
	public function getPayPalMembershipFeeNotificationVerifier(): PaymentNotificationVerifier {
1269
		return $this->pimple['paypal-membership-fee-notification-verifier'];
1270
	}
1271
1272
	public function setPayPalMembershipFeeNotificationVerifier( PaymentNotificationVerifier $verifier ): void {
1273
		$this->pimple['paypal-membership-fee-notification-verifier'] = $verifier;
1274
	}
1275
1276 118
	public function newCreditCardNotificationUseCase( string $updateToken ): CreditCardNotificationUseCase {
1277 118
		return new CreditCardNotificationUseCase(
1278 118
			$this->getDonationRepository(),
1279
			$this->newDonationAuthorizer( $updateToken ),
1280
			$this->getCreditCardService(),
1281
			$this->newDonationConfirmationMailer(),
1282
			$this->getLogger(),
1283
			$this->newDonationEventLogger()
1284
		);
1285
	}
1286
1287
	public function newCancelMembershipApplicationHtmlPresenter(): CancelMembershipApplicationHtmlPresenter {
1288
		return new CancelMembershipApplicationHtmlPresenter(
1289
			$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...
1290 2
		);
1291 2
	}
1292 2
1293
	public function newMembershipApplicationConfirmationHtmlPresenter(): MembershipApplicationConfirmationHtmlPresenter {
1294
		return new MembershipApplicationConfirmationHtmlPresenter(
1295
			$this->getIncludeTemplate( 'Membership_Application_Confirmation.html.twig' )
0 ignored issues
show
Deprecated Code introduced by
The method WMDE\Fundraising\Fronten...y::getIncludeTemplate() has been deprecated with message: Change the template to use extend and block and call getLayoutTemplate instead.

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

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

Loading history...
1296
		);
1297
	}
1298 2
1299 2
	public function newMembershipFormViolationPresenter(): MembershipFormViolationPresenter {
1300 2
		return new MembershipFormViolationPresenter(
1301
			$this->getMembershipApplicationFormTemplate()
1302
		);
1303
	}
1304
1305
	public function setCreditCardService( CreditCardService $ccService ): void {
1306 31
		$this->pimple['credit-card-api-service'] = $ccService;
1307 31
	}
1308
1309
	public function getCreditCardService(): CreditCardService {
1310 109
		return $this->pimple['credit-card-api-service'];
1311 109
	}
1312
1313
	public function newCreditCardNotificationPresenter(): CreditCardNotificationPresenter {
1314 109
		return new CreditCardNotificationPresenter(
1315 109
			new TwigTemplate(
1316 109
				$this->getSkinTwig(),
1317 109
				'Credit_Card_Payment_Notification.txt.twig',
1318
				[ 'returnUrl' => $this->config['creditcard']['return-url'] ]
1319
			)
1320
		);
1321
	}
1322 2
1323 2
	private function newDoctrineDonationPrePersistSubscriber(): DoctrineDonationPrePersistSubscriber {
1324 2
		$tokenGenerator = $this->getTokenGenerator();
1325 2
		return new DoctrineDonationPrePersistSubscriber(
1326 2
			$tokenGenerator,
1327
			$tokenGenerator
1328
		);
1329
	}
1330 11
1331 11
	private function newDoctrineMembershipApplicationPrePersistSubscriber(): DoctrineMembershipApplicationPrePersistSubscriber {
1332
		$tokenGenerator = $this->getTokenGenerator();
1333
		return new DoctrineMembershipApplicationPrePersistSubscriber(
1334
			$tokenGenerator,
1335 1
			$tokenGenerator
1336 1
		);
1337
	}
1338 2
1339
	public function setTokenGenerator( TokenGenerator $tokenGenerator ): void {
1340 1
		$this->pimple['token_generator'] = $tokenGenerator;
1341 1
	}
1342
1343
	public function disableDoctrineSubscribers(): void {
1344
		$this->addDoctrineSubscribers = false;
1345
	}
1346
1347
	private function newDonationTokenFetcher(): DonationTokenFetcher {
1348
		return new DoctrineDonationTokenFetcher(
1349
			$this->getEntityManager()
1350
		);
1351
	}
1352
1353
	private function newMembershipApplicationTokenFetcher(): ApplicationTokenFetcher {
1354
		return new DoctrineApplicationTokenFetcher(
1355
			$this->getEntityManager()
1356
		);
1357
	}
1358
1359
	private function newDonationPolicyValidator(): AddDonationPolicyValidator {
1360
		return new AddDonationPolicyValidator(
1361
			$this->newDonationAmountPolicyValidator(),
1362
			$this->newTextPolicyValidator( 'fields' ),
1363
			$this->config['email-address-blacklist']
1364
		);
1365
	}
1366
1367
	private function newDonationAmountPolicyValidator(): AmountPolicyValidator {
1368
		// in the future, this might come from the configuration
1369
		return new AmountPolicyValidator( 1000, 1000 );
1370
	}
1371
1372
	public function getDonationTimeframeLimit(): string {
1373
		return $this->config['donation-timeframe-limit'];
1374
	}
1375
1376
	public function newSystemMessageResponse( string $message ): string {
1377
		$test = $this->getIncludeTemplate( 'System_Message.html.twig' );
0 ignored issues
show
Deprecated Code introduced by
The method WMDE\Fundraising\Fronten...y::getIncludeTemplate() has been deprecated with message: Change the template to use extend and block and call getLayoutTemplate instead.

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

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

Loading history...
1378
		return $test->render( [ 'message' => $message ] );
1379
	}
1380
1381
	public function getMembershipApplicationTimeframeLimit(): string {
1382
		return $this->config['membership-application-timeframe-limit'];
1383
	}
1384
1385
	private function newAddCommentValidator(): AddCommentValidator {
1386
		return new AddCommentValidator();
1387
	}
1388
1389
	private function getPageCache(): Cache {
1390
		return $this->pimple['page_cache'];
1391
	}
1392
1393
	private function getRenderedPageCache(): Cache {
1394
		return $this->pimple['rendered_page_cache'];
1395
	}
1396
1397
	public function enablePageCache(): void {
1398
		$this->pimple['page_cache'] = function() {
1399
			return new FilesystemCache( $this->getCachePath() . '/pages/raw' );
1400
		};
1401
1402
		$this->pimple['rendered_page_cache'] = function() {
1403
			return new FilesystemCache( $this->getCachePath() . '/pages/rendered' );
1404
		};
1405
	}
1406
1407
	private function addProfilingDecorator( $objectToDecorate, string $profilingLabel ) {	// @codingStandardsIgnoreLine
1408
		if ( $this->profiler === null ) {
1409
			return $objectToDecorate;
1410
		}
1411
1412
		$builder = new ProfilingDecoratorBuilder( $this->profiler, $this->getProfilerDataCollector() );
1413
1414
		return $builder->decorate( $objectToDecorate, $profilingLabel );
1415
	}
1416
1417
	public function setProfiler( Stopwatch $profiler ): void {
1418
		$this->profiler = $profiler;
1419
	}
1420
1421
	public function setEmailValidator( EmailValidator $validator ): void {
1422
		$this->pimple['mail_validator'] = $validator;
1423
	}
1424
1425
	public function setLogger( LoggerInterface $logger ): void {
1426
		$this->pimple['logger'] = $logger;
1427
	}
1428
1429
	public function setPaypalLogger( LoggerInterface $logger ): void {
1430
		$this->pimple['paypal_logger'] = $logger;
1431
	}
1432
1433
	public function setSofortLogger( LoggerInterface $logger ): void {
1434
		$this->pimple['sofort_logger'] = $logger;
1435
	}
1436
1437
	public function getProfilerDataCollector(): ProfilerDataCollector {
1438
		return $this->pimple['profiler_data_collector'];
1439
	}
1440
1441
	private function newIbanValidator(): KontoCheckIbanValidator {
1442
		return new KontoCheckIbanValidator( $this->newBankDataConverter(), $this->config['banned-ibans'] );
1443
	}
1444
1445
	public function setFilePrefixer( FilePrefixer $prefixer ): void {
1446
		$this->pimple['cachebusting_fileprefixer'] = $prefixer;
1447
	}
1448
1449
	private function getFilePrefixer(): FilePrefixer {
1450
		return $this->pimple['cachebusting_fileprefixer'];
1451
	}
1452
1453
	private function getFilePrefix(): string {
1454
		$prefixContentFile = $this->getVarPath() . '/file_prefix.txt';
1455
		if ( !file_exists( $prefixContentFile ) ) {
1456
			return '';
1457
		}
1458
		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...
1459
	}
1460
1461
	public function newDonationAcceptedEventHandler( string $updateToken ): DonationAcceptedEventHandler {
1462
		return new DonationAcceptedEventHandler(
1463
			$this->newDonationAuthorizer( $updateToken ),
1464
			$this->getDonationRepository(),
1465
			$this->newDonationConfirmationMailer()
1466
		);
1467
	}
1468
1469
	public function newPageNotFoundHtmlPresenter(): PageNotFoundPresenter {
1470
		return new PageNotFoundPresenter( $this->getLayoutTemplate( 'Page_not_found.html.twig' ) );
1471
	}
1472
1473
	public function setPageViewTracker( PageViewTracker $tracker ): void {
1474
		$this->pimple['page_view_tracker'] = function () use ( $tracker )  {
1475
			return $tracker;
1476
		};
1477
	}
1478
1479
	public function getPageViewTracker(): PageViewTracker {
1480
		return $this->pimple['page_view_tracker'];
1481
	}
1482
1483
	public function newServerSideTracker(): ServerSideTracker {
1484
		// the "https:" prefix does NOT get any slashes because baseURL is stored in a protocol-agnostic way
1485
		// (e.g. "//tracking.wikimedia.de" )
1486
		return new PiwikServerSideTracker(
1487
			new \PiwikTracker( $this->config['piwik']['siteId'], 'https:' . $this->config['piwik']['baseUrl'] )
1488
		);
1489
	}
1490
1491
	public function getI18nDirectory(): string {
1492
		return $this->getAbsolutePath( $this->config['i18n-base-path'] ) . '/' . $this->config['locale'];
1493
	}
1494
1495
	/**
1496
	 * If the pathname does not start with a slash, make the path absolute to root dir of application
1497
	 */
1498
	private function getAbsolutePath( string $path ): string {
1499
		if ( $path[0] === '/' ) {
1500
			return $path;
1501
		}
1502
		return __DIR__ . '/../../' . $path;
1503
	}
1504
1505
	public function setContentPagePageSelector( PageSelector $pageSelector ): void {
1506
		$this->pimple['content_page_selector'] = $pageSelector;
1507
	}
1508
1509
	public function getContentPagePageSelector(): PageSelector {
1510
		return $this->pimple['content_page_selector'];
1511
	}
1512
1513
	public function setContentProvider( ContentProvider $contentProvider ): void {
1514
		$this->pimple['content_provider'] = $contentProvider;
1515
	}
1516
1517
	private function getContentProvider(): ContentProvider {
1518
		return $this->pimple['content_provider'];
1519
	}
1520
1521
	public function newMailTemplateFilenameTraversable(): MailTemplateFilenameTraversable {
1522
		return new MailTemplateFilenameTraversable(
1523
			$this->config['mailer-twig']['loaders']['filesystem']['template-dir']
1524
		);
1525
	}
1526
1527
	public function getUrlGenerator(): UrlGenerator {
1528
		return $this->pimple['url_generator'];
1529
	}
1530
1531
	public function setUrlGenerator( UrlGenerator $urlGenerator ): void {
1532
		$this->pimple['url_generator'] = $urlGenerator;
1533
	}
1534
1535
}
1536