Completed
Pull Request — master (#611)
by Gabriel
70:55 queued 66:26
created

FunFunFactory::getDonationTimeframeLimit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\Fundraising\Frontend\Factories;
6
7
use Doctrine\Common\Cache\Cache;
8
use Doctrine\Common\Cache\FilesystemCache;
9
use Doctrine\Common\Cache\VoidCache;
10
use Doctrine\DBAL\Connection;
11
use Doctrine\DBAL\DriverManager;
12
use Doctrine\ORM\EntityManager;
13
use GuzzleHttp\Client;
14
use GuzzleHttp\ClientInterface;
15
use GuzzleHttp\Handler\CurlHandler;
16
use GuzzleHttp\HandlerStack;
17
use Mediawiki\Api\ApiUser;
18
use Mediawiki\Api\Guzzle\MiddlewareFactory;
19
use Mediawiki\Api\MediawikiApi;
20
use NumberFormatter;
21
use Psr\Log\LoggerInterface;
22
use Psr\Log\NullLogger;
23
use Swift_MailTransport;
24
use Swift_NullTransport;
25
use Symfony\Component\Stopwatch\Stopwatch;
26
use Symfony\Component\Translation\TranslatorInterface;
27
use TNvpServiceDispatcher;
28
use Twig_Environment;
29
use Twig_Extensions_Extension_Intl;
30
use WMDE\Fundraising\Frontend\ApplicationContext\DataAccess\ApiBasedPageRetriever;
31
use WMDE\Fundraising\Frontend\ApplicationContext\Infrastructure\AllOfTheCachePurger;
32
use WMDE\Fundraising\Frontend\ApplicationContext\Infrastructure\PageRetriever;
33
use WMDE\Fundraising\Frontend\ApplicationContext\UseCases\DisplayPage\DisplayPageUseCase;
34
use WMDE\Fundraising\Frontend\ApplicationContext\UseCases\GetInTouch\GetInTouchUseCase;
35
use WMDE\Fundraising\Frontend\ApplicationContext\UseCases\PurgeCache\PurgeCacheUseCase;
36
use WMDE\Fundraising\Frontend\DonatingContext\Authorization\DonationAuthorizer;
37
use WMDE\Fundraising\Frontend\DonatingContext\Authorization\DonationTokenFetcher;
38
use WMDE\Fundraising\Frontend\DonatingContext\DataAccess\DoctrineCommentFinder;
39
use WMDE\Fundraising\Frontend\DonatingContext\DataAccess\DoctrineDonationAuthorizer;
40
use WMDE\Fundraising\Frontend\DonatingContext\DataAccess\DoctrineDonationEventLogger;
41
use WMDE\Fundraising\Frontend\DonatingContext\DataAccess\DoctrineDonationPrePersistSubscriber;
42
use WMDE\Fundraising\Frontend\DonatingContext\DataAccess\DoctrineDonationRepository;
43
use WMDE\Fundraising\Frontend\DonatingContext\DataAccess\DoctrineDonationTokenFetcher;
44
use WMDE\Fundraising\Frontend\DonatingContext\Domain\Repositories\CommentFinder;
45
use WMDE\Fundraising\Frontend\DonatingContext\Domain\Repositories\DonationRepository;
46
use WMDE\Fundraising\Frontend\DonatingContext\Infrastructure\BestEffortDonationEventLogger;
47
use WMDE\Fundraising\Frontend\DonatingContext\Infrastructure\DonationConfirmationMailer;
48
use WMDE\Fundraising\Frontend\DonatingContext\Infrastructure\DonationEventLogger;
49
use WMDE\Fundraising\Frontend\DonatingContext\Infrastructure\LoggingCommentFinder;
50
use WMDE\Fundraising\Frontend\DonatingContext\Infrastructure\LoggingDonationRepository;
51
use WMDE\Fundraising\Frontend\DonatingContext\UseCases\AddComment\AddCommentUseCase;
52
use WMDE\Fundraising\Frontend\DonatingContext\UseCases\AddComment\AddCommentValidator;
53
use WMDE\Fundraising\Frontend\DonatingContext\UseCases\AddDonation\AddDonationPolicyValidator;
54
use WMDE\Fundraising\Frontend\DonatingContext\UseCases\AddDonation\AddDonationUseCase;
55
use WMDE\Fundraising\Frontend\DonatingContext\UseCases\AddDonation\AddDonationValidator;
56
use WMDE\Fundraising\Frontend\DonatingContext\UseCases\AddDonation\ReferrerGeneralizer;
57
use WMDE\Fundraising\Frontend\DonatingContext\UseCases\CancelDonation\CancelDonationUseCase;
58
use WMDE\Fundraising\Frontend\DonatingContext\UseCases\CreditCardPaymentNotification\CreditCardNotificationUseCase;
59
use WMDE\Fundraising\Frontend\DonatingContext\UseCases\HandlePayPalPaymentNotification\HandlePayPalPaymentNotificationUseCase;
60
use WMDE\Fundraising\Frontend\DonatingContext\UseCases\ListComments\ListCommentsUseCase;
61
use WMDE\Fundraising\Frontend\DonatingContext\UseCases\ShowDonationConfirmation\ShowDonationConfirmationUseCase;
62
use WMDE\Fundraising\Frontend\ApplicationContext\Infrastructure\CachingPageRetriever;
63
use WMDE\Fundraising\Frontend\ApplicationContext\Infrastructure\Honorifics;
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\Messenger;
68
use WMDE\Fundraising\Frontend\ApplicationContext\Infrastructure\ModifyingPageRetriever;
69
use WMDE\Fundraising\Frontend\Infrastructure\PageRetrieverBasedStringList;
70
use WMDE\Fundraising\Frontend\Infrastructure\PaymentNotificationVerifier;
71
use WMDE\Fundraising\Frontend\Infrastructure\PayPalPaymentNotificationVerifier;
72
use WMDE\Fundraising\Frontend\Infrastructure\ProfilerDataCollector;
73
use WMDE\Fundraising\Frontend\Infrastructure\ProfilingDecoratorBuilder;
74
use WMDE\Fundraising\Frontend\Infrastructure\RandomTokenGenerator;
75
use WMDE\Fundraising\Frontend\Infrastructure\TemplateBasedMailer;
76
use WMDE\Fundraising\Frontend\Infrastructure\TokenGenerator;
77
use WMDE\Fundraising\Frontend\MembershipApplicationContext\Authorization\ApplicationAuthorizer;
78
use WMDE\Fundraising\Frontend\MembershipApplicationContext\Authorization\ApplicationTokenFetcher;
79
use WMDE\Fundraising\Frontend\MembershipApplicationContext\DataAccess\DoctrineApplicationAuthorizer;
80
use WMDE\Fundraising\Frontend\MembershipApplicationContext\DataAccess\DoctrineApplicationPiwikTracker;
81
use WMDE\Fundraising\Frontend\MembershipApplicationContext\DataAccess\DoctrineMembershipApplicationPrePersistSubscriber;
82
use WMDE\Fundraising\Frontend\MembershipApplicationContext\DataAccess\DoctrineApplicationRepository;
83
use WMDE\Fundraising\Frontend\MembershipApplicationContext\DataAccess\DoctrineApplicationTokenFetcher;
84
use WMDE\Fundraising\Frontend\MembershipApplicationContext\DataAccess\DoctrineApplicationTracker;
85
use WMDE\Fundraising\Frontend\MembershipApplicationContext\Domain\Model\EmailAddress;
86
use WMDE\Fundraising\Frontend\MembershipApplicationContext\Domain\Repositories\ApplicationRepository;
87
use WMDE\Fundraising\Frontend\MembershipApplicationContext\Infrastructure\LoggingApplicationRepository;
88
use WMDE\Fundraising\Frontend\MembershipApplicationContext\Tracking\ApplicationPiwikTracker;
89
use WMDE\Fundraising\Frontend\MembershipApplicationContext\Tracking\ApplicationTracker;
90
use WMDE\Fundraising\Frontend\MembershipApplicationContext\UseCases\ApplyForMembership\ApplyForMembershipUseCase;
91
use WMDE\Fundraising\Frontend\MembershipApplicationContext\UseCases\ApplyForMembership\MembershipApplicationValidator;
92
use WMDE\Fundraising\Frontend\MembershipApplicationContext\UseCases\CancelMembershipApplication\CancelMembershipApplicationUseCase;
93
use WMDE\Fundraising\Frontend\MembershipApplicationContext\UseCases\ShowMembershipApplicationConfirmation\ShowMembershipApplicationConfirmationUseCase;
94
use WMDE\Fundraising\Frontend\PaymentContext\DataAccess\McpCreditCardService;
95
use WMDE\Fundraising\Frontend\PaymentContext\DataAccess\UniqueTransferCodeGenerator;
96
use WMDE\Fundraising\Frontend\PaymentContext\Domain\BankDataConverter;
97
use WMDE\Fundraising\Frontend\PaymentContext\Domain\SimpleTransferCodeGenerator;
98
use WMDE\Fundraising\Frontend\PaymentContext\Domain\TransferCodeGenerator;
99
use WMDE\Fundraising\Frontend\PaymentContext\Infrastructure\CreditCardService;
100
use WMDE\Fundraising\Frontend\PaymentContext\UseCases\CheckIban\CheckIbanUseCase;
101
use WMDE\Fundraising\Frontend\PaymentContext\UseCases\GenerateIban\GenerateIbanUseCase;
102
use WMDE\Fundraising\Frontend\Presentation\AmountFormatter;
103
use WMDE\Fundraising\Frontend\Presentation\Content\PageContentModifier;
104
use WMDE\Fundraising\Frontend\Presentation\CreditCardUrlConfig;
105
use WMDE\Fundraising\Frontend\Presentation\CreditCardUrlGenerator;
106
use WMDE\Fundraising\Frontend\Presentation\DonationConfirmationPageSelector;
107
use WMDE\Fundraising\Frontend\Presentation\GreetingGenerator;
108
use WMDE\Fundraising\Frontend\Presentation\PayPalUrlConfig;
109
use WMDE\Fundraising\Frontend\Presentation\PayPalUrlGenerator;
110
use WMDE\Fundraising\Frontend\Presentation\Presenters\AddSubscriptionHtmlPresenter;
111
use WMDE\Fundraising\Frontend\Presentation\Presenters\AddSubscriptionJsonPresenter;
112
use WMDE\Fundraising\Frontend\Presentation\Presenters\CancelDonationHtmlPresenter;
113
use WMDE\Fundraising\Frontend\Presentation\Presenters\CancelMembershipApplicationHtmlPresenter;
114
use WMDE\Fundraising\Frontend\Presentation\Presenters\CommentListHtmlPresenter;
115
use WMDE\Fundraising\Frontend\Presentation\Presenters\CommentListJsonPresenter;
116
use WMDE\Fundraising\Frontend\Presentation\Presenters\CommentListRssPresenter;
117
use WMDE\Fundraising\Frontend\Presentation\Presenters\ConfirmSubscriptionHtmlPresenter;
118
use WMDE\Fundraising\Frontend\Presentation\Presenters\CreditCardNotificationPresenter;
119
use WMDE\Fundraising\Frontend\Presentation\Presenters\CreditCardPaymentHtmlPresenter;
120
use WMDE\Fundraising\Frontend\Presentation\Presenters\DisplayPagePresenter;
121
use WMDE\Fundraising\Frontend\Presentation\Presenters\DonationConfirmationHtmlPresenter;
122
use WMDE\Fundraising\Frontend\Presentation\Presenters\DonationFormPresenter;
123
use WMDE\Fundraising\Frontend\Presentation\Presenters\DonationFormViolationPresenter;
124
use WMDE\Fundraising\Frontend\Presentation\Presenters\GetInTouchHtmlPresenter;
125
use WMDE\Fundraising\Frontend\Presentation\Presenters\IbanPresenter;
126
use WMDE\Fundraising\Frontend\Presentation\Presenters\InternalErrorHtmlPresenter;
127
use WMDE\Fundraising\Frontend\Presentation\Presenters\MembershipApplicationConfirmationHtmlPresenter;
128
use WMDE\Fundraising\Frontend\Presentation\Presenters\MembershipFormViolationPresenter;
129
use WMDE\Fundraising\Frontend\Presentation\TwigTemplate;
130
use WMDE\Fundraising\Frontend\SubscriptionContext\DataAccess\DoctrineSubscriptionRepository;
131
use WMDE\Fundraising\Frontend\SubscriptionContext\Domain\Repositories\SubscriptionRepository;
132
use WMDE\Fundraising\Frontend\SubscriptionContext\Infrastructure\LoggingSubscriptionRepository;
133
use WMDE\Fundraising\Frontend\SubscriptionContext\UseCases\AddSubscription\AddSubscriptionUseCase;
134
use WMDE\Fundraising\Frontend\SubscriptionContext\UseCases\ConfirmSubscription\ConfirmSubscriptionUseCase;
135
use WMDE\Fundraising\Frontend\Validation\AllowedValuesValidator;
136
use WMDE\Fundraising\Frontend\Validation\AmountPolicyValidator;
137
use WMDE\Fundraising\Frontend\Validation\AmountValidator;
138
use WMDE\Fundraising\Frontend\Validation\BankDataValidator;
139
use WMDE\Fundraising\Frontend\Validation\EmailValidator;
140
use WMDE\Fundraising\Frontend\Validation\GetInTouchValidator;
141
use WMDE\Fundraising\Frontend\Validation\IbanValidator;
142
use WMDE\Fundraising\Frontend\Validation\MembershipFeeValidator;
143
use WMDE\Fundraising\Frontend\SubscriptionContext\Validation\SubscriptionDuplicateValidator;
144
use WMDE\Fundraising\Frontend\SubscriptionContext\Validation\SubscriptionValidator;
145
use WMDE\Fundraising\Frontend\DonatingContext\Validation\DonorValidator;
146
use WMDE\Fundraising\Frontend\DonatingContext\Validation\DonorNameValidator;
147
use WMDE\Fundraising\Frontend\DonatingContext\Validation\DonorAddressValidator;
148
use WMDE\Fundraising\Frontend\Validation\TemplateNameValidator;
149
use WMDE\Fundraising\Frontend\Validation\TextPolicyValidator;
150
use WMDE\Fundraising\Store\Factory as StoreFactory;
151
use WMDE\Fundraising\Store\Installer;
152
153
/**
154
 * @licence GNU GPL v2+
155
 */
156
class FunFunFactory {
157
158
	private $config;
159
160
	/**
161
	 * @var \Pimple
162
	 */
163
	private $pimple;
164
165
	private $addDoctrineSubscribers = true;
166
167
	/**
168
	 * @var Stopwatch|null
169
	 */
170
	private $profiler = null;
171
172 130
	public function __construct( array $config ) {
173 130
		$this->config = $config;
174 130
		$this->pimple = $this->newPimple();
175 130
	}
176
177 130
	private function newPimple(): \Pimple {
178 130
		$pimple = new \Pimple();
179
180
		$pimple['logger'] = $pimple->share( function() {
181 89
			return new NullLogger();
182 130
		} );
183
184
		$pimple['profiler_data_collector'] = $pimple->share( function() {
185
			return new ProfilerDataCollector();
186 130
		} );
187
188
		$pimple['dbal_connection'] = $pimple->share( function() {
189 130
			return DriverManager::getConnection( $this->config['db'] );
190 130
		} );
191
192
		$pimple['entity_manager'] = $pimple->share( function() {
193 76
			$entityManager = ( new StoreFactory( $this->getConnection() ) )->getEntityManager();
194 76
			if ( $this->addDoctrineSubscribers ) {
195 76
				$entityManager->getEventManager()->addEventSubscriber( $this->newDoctrineDonationPrePersistSubscriber() );
196 76
				$entityManager->getEventManager()->addEventSubscriber( $this->newDoctrineMembershipApplicationPrePersistSubscriber() );
197
			}
198
199 76
			return $entityManager;
200 130
		} );
201
202
		$pimple['subscription_repository'] = $pimple->share( function() {
203 8
			return new LoggingSubscriptionRepository(
204 8
				new DoctrineSubscriptionRepository( $this->getEntityManager() ),
205 8
				$this->getLogger()
206
			);
207 130
		} );
208
209
		$pimple['donation_repository'] = $pimple->share( function() {
210 34
			return new LoggingDonationRepository(
211 34
				new DoctrineDonationRepository( $this->getEntityManager() ),
212 34
				$this->getLogger()
213
			);
214 130
		} );
215
216
		$pimple['membership_application_repository'] = $pimple->share( function() {
217 10
			return new LoggingApplicationRepository(
218 10
				new DoctrineApplicationRepository( $this->getEntityManager() ),
219 10
				$this->getLogger()
220
			);
221 130
		} );
222
223
		$pimple['comment_repository'] = $pimple->share( function() {
224 12
			$finder = new LoggingCommentFinder(
225 12
				new DoctrineCommentFinder( $this->getEntityManager() ),
226 12
				$this->getLogger()
227
			);
228
229 12
			return $this->addProfilingDecorator( $finder, 'CommentFinder' );
230 130
		} );
231
232
		$pimple['mail_validator'] = $pimple->share( function() {
233 35
			return new EmailValidator( new InternetDomainNameValidator() );
234 130
		} );
235
236
		$pimple['subscription_validator'] = $pimple->share( function() {
237 6
			return new SubscriptionValidator(
238 6
				$this->getEmailValidator(),
239 6
				$this->newTextPolicyValidator( 'fields' ),
240 6
				$this->newSubscriptionDuplicateValidator(),
241 6
				$this->newHonorificValidator()
242
			);
243 130
		} );
244
245
		$pimple['template_name_validator'] = $pimple->share( function() {
246 2
			return new TemplateNameValidator( $this->getTwig() );
247 130
		} );
248
249
		$pimple['contact_validator'] = $pimple->share( function() {
250 3
			return new GetInTouchValidator( $this->getEmailValidator() );
251 130
		} );
252
253
		$pimple['greeting_generator'] = $pimple->share( function() {
254 40
			return new GreetingGenerator();
255 130
		} );
256
257
		$pimple['mw_api'] = $pimple->share( function() {
258 77
			return new MediawikiApi(
259 77
				$this->config['cms-wiki-api-url'],
260 77
				$this->getGuzzleClient()
261
			);
262 130
		} );
263
264
		$pimple['guzzle_client'] = $pimple->share( function() {
265 77
			$middlewareFactory = new MiddlewareFactory();
266 77
			$middlewareFactory->setLogger( $this->getLogger() );
267
268 77
			$handlerStack = HandlerStack::create( new CurlHandler() );
269 77
			$handlerStack->push( $middlewareFactory->retry() );
270
271 77
			$guzzle = new Client( [
272 77
				'cookies' => true,
273 77
				'handler' => $handlerStack,
274
				'headers' => [ 'User-Agent' => 'WMDE Fundraising Frontend' ],
275
			] );
276
277 77
			return $this->addProfilingDecorator( $guzzle, 'Guzzle Client' );
278 130
		} );
279
280
		$pimple['translator'] = $pimple->share( function() {
281 82
			$translationFactory = new TranslationFactory();
282
			$loaders = [
283 82
				'json' => $translationFactory->newJsonLoader()
284
			];
285 82
			$locale = $this->config['locale'];
286 82
			$translator = $translationFactory->create( $loaders, $locale );
287 82
			$translator->addResource(
288 82
				'json',
289 82
				__DIR__ . '/../../app/translations/messages.' . $locale . '.json',
290
				$locale
291
			);
292
293 82
			$translator->addResource(
294 82
				'json',
295 82
				__DIR__ . '/../../app/translations/paymentTypes.' . $locale . '.json',
296
				$locale,
297 82
				'paymentTypes'
298
			);
299
300 82
			$translator->addResource(
301 82
				'json',
302 82
				__DIR__ . '/../../app/translations/paymentIntervals.' . $locale . '.json',
303
				$locale,
304 82
				'paymentIntervals'
305
			);
306
307 82
			$translator->addResource(
308 82
				'json',
309 82
				__DIR__ . '/../../app/translations/donationStatus.' . $locale . '.json',
310
				$locale,
311 82
				'donationStatus'
312
			);
313
314 82
			$translator->addResource(
315 82
				'json',
316 82
				__DIR__ . '/../../app/translations/validations.' . $locale . '.json',
317
				$locale,
318 82
				'validations'
319
			);
320
321 82
			return $translator;
322 130
		} );
323
324
		// In the future, this could be locale-specific or filled from a DB table
325
		$pimple['honorifics'] = $pimple->share( function() {
326 64
			return new Honorifics( [
327 64
				'' => 'Kein Titel',
328
				'Dr.' => 'Dr.',
329
				'Prof.' => 'Prof.',
330
				'Prof. Dr.' => 'Prof. Dr.'
331
			] );
332 130
		} );
333
334
		$pimple['twig_factory'] = $pimple->share( function () {
335
			// TODO: like this we end up with two Twig instance, one created here and on in the framework
336 77
			return new TwigFactory( $this->config['twig'], $this->getCachePath() . '/twig' );
337 130
		} );
338
339
		$pimple['twig'] = $pimple->share( function() {
340 77
			$twigFactory = $this->getTwigFactory();
341 77
			$loaders = array_filter( [
342 77
				$twigFactory->newFileSystemLoader(),
343 77
				$twigFactory->newArrayLoader(), // This is just a fallback for testing
344 77
				$twigFactory->newWikiPageLoader( $this->newWikiPageRetriever() ),
345
			] );
346
			$extensions = [
347 77
				$twigFactory->newTranslationExtension( $this->getTranslator() ),
348 77
				new Twig_Extensions_Extension_Intl()
349
			];
350
351 77
			return $twigFactory->create( $loaders, $extensions );
352 130
		} );
353
354
		$pimple['messenger'] = $pimple->share( function() {
355 5
			return new Messenger(
356 5
				new Swift_MailTransport(),
357 5
				$this->getOperatorAddress(),
358 5
				$this->config['operator-displayname']
359
			);
360 130
		} );
361
362
		$pimple['confirmation-page-selector'] = $pimple->share( function() {
363 13
			return new DonationConfirmationPageSelector( $this->config['confirmation-pages'] );
364 130
		} );
365
366
		$pimple['paypal-payment-notification-verifier'] = $pimple->share( function() {
367
			return new LoggingPaymentNotificationVerifier(
368
				new PayPalPaymentNotificationVerifier(
369
					new Client(),
370
					$this->config['paypal']
371
				),
372
				$this->getLogger()
373
			);
374 130
		} );
375
376
		$pimple['credit-card-api-service'] = $pimple->share( function() {
377
			return new McpCreditCardService(
378
				new TNvpServiceDispatcher(
379
					'IMcpCreditcardService_v1_5',
380
					'https://sipg.micropayment.de/public/creditcard/v1.5/nvp/'
381
				),
382
				$this->config['creditcard']['access-key'],
383
				$this->config['creditcard']['testmode']
384
			);
385 130
		} );
386
387
		$pimple['token_generator'] = $pimple->share( function() {
388 60
			return new RandomTokenGenerator(
389 60
				$this->config['token-length'],
390 60
				new \DateInterval( $this->config['token-validity-timestamp'] )
391
			);
392 130
		} );
393
394
		$pimple['page_cache'] = $pimple->share( function() {
395 80
			return new VoidCache();
396 130
		} );
397
398 130
		return $pimple;
399
	}
400
401 130
	public function getConnection(): Connection {
402 130
		return $this->pimple['dbal_connection'];
403
	}
404
405 76
	public function getEntityManager(): EntityManager {
406 76
		return $this->pimple['entity_manager'];
407
	}
408
409 8
	private function newDonationEventLogger(): DonationEventLogger {
410 8
		return new BestEffortDonationEventLogger(
411 8
			new DoctrineDonationEventLogger( $this->getEntityManager() ),
412 8
			$this->getLogger()
413
		);
414
	}
415
416 130
	public function newInstaller(): Installer {
417 130
		return ( new StoreFactory( $this->getConnection() ) )->newInstaller();
418
	}
419
420 12
	public function newListCommentsUseCase(): ListCommentsUseCase {
421 12
		return new ListCommentsUseCase( $this->getCommentFinder() );
422
	}
423
424 6
	public function newCommentListJsonPresenter(): CommentListJsonPresenter {
425 6
		return new CommentListJsonPresenter();
426
	}
427
428 2
	public function newCommentListRssPresenter(): CommentListRssPresenter {
429 2
		return new CommentListRssPresenter( new TwigTemplate(
430 2
			$this->getTwig(),
431 2
			'CommentList.rss.twig'
432
		) );
433
	}
434
435 4
	public function newCommentListHtmlPresenter(): CommentListHtmlPresenter {
436 4
		return new CommentListHtmlPresenter( $this->getLayoutTemplate( 'CommentList.html.twig', [ 'piwikGoals' => [ 1 ] ] ) );
437
	}
438
439 12
	private function getCommentFinder(): CommentFinder {
440 12
		return $this->pimple['comment_repository'];
441
	}
442
443 9
	public function getSubscriptionRepository(): SubscriptionRepository {
444 9
		return $this->pimple['subscription_repository'];
445
	}
446
447 1
	public function setSubscriptionRepository( SubscriptionRepository $subscriptionRepository ) {
448 1
		$this->pimple['subscription_repository'] = $subscriptionRepository;
449 1
	}
450
451 6
	private function getSubscriptionValidator(): SubscriptionValidator {
452 6
		return $this->pimple['subscription_validator'];
453
	}
454
455 35
	public function getEmailValidator(): EmailValidator {
456 35
		return $this->pimple['mail_validator'];
457
	}
458
459 2
	private function getTemplateNameValidator(): TemplateNameValidator {
460 2
		return $this->pimple['template_name_validator'];
461
	}
462
463 2
	public function newDisplayPageUseCase(): DisplayPageUseCase {
464 2
		return new DisplayPageUseCase(
465 2
			$this->getTemplateNameValidator()
466
		);
467
	}
468
469 2
	public function newDisplayPagePresenter(): DisplayPagePresenter {
470 2
		return new DisplayPagePresenter( $this->getLayoutTemplate( 'DisplayPageLayout.twig' ) );
471
	}
472
473 1
	public function newAddSubscriptionHTMLPresenter(): AddSubscriptionHtmlPresenter {
474 1
		return new AddSubscriptionHtmlPresenter( $this->getIncludeTemplate( 'Subscription_Form.twig' ), $this->getTranslator() );
475
	}
476
477 3
	public function newConfirmSubscriptionHtmlPresenter(): ConfirmSubscriptionHtmlPresenter {
478 3
		return new ConfirmSubscriptionHtmlPresenter(
479 3
			$this->getLayoutTemplate( 'ConfirmSubscription.html.twig' ),
480 3
			$this->getTranslator()
481
		);
482
	}
483
484 2
	public function newAddSubscriptionJSONPresenter(): AddSubscriptionJsonPresenter {
485 2
		return new AddSubscriptionJsonPresenter( $this->getTranslator() );
486
	}
487
488 1
	public function newGetInTouchHTMLPresenter(): GetInTouchHtmlPresenter {
489 1
		return new GetInTouchHtmlPresenter( $this->getIncludeTemplate( 'Kontaktformular.twig' ), $this->getTranslator() );
490
	}
491
492 77
	public function getTwig(): Twig_Environment {
493 77
		return $this->pimple['twig'];
494
	}
495
496
	/**
497
	 * Get a template, with the content for the layout areas filled in.
498
	 *
499
	 * @param string $templateName
500
	 * @return TwigTemplate
501
	 */
502 23
	private function getLayoutTemplate( string $templateName, array $context = [] ): TwigTemplate {
503 23
		 return new TwigTemplate(
504 23
			$this->getTwig(),
505
			$templateName,
506 23
			array_merge( $this->getDefaultTwigVariables(), $context )
507
		);
508
	}
509
510
	/**
511
	 * Get a layouted template that includes another template
512
	 *
513
	 * @param string $templateName Template to include
514
	 * @return TwigTemplate
515
	 */
516 37
	private function getIncludeTemplate( string $templateName, array $context = [] ): TwigTemplate {
517 37
		return new TwigTemplate(
518 37
			$this->getTwig(),
519 37
			'IncludeInLayout.twig',
520
			array_merge(
521 37
				$this->getDefaultTwigVariables(),
522 37
				[ 'main_template' => $templateName ],
523
				$context
524
			)
525
		);
526
	}
527
528 59
	private function getDefaultTwigVariables() {
529
		return [
530 59
			'basepath' => $this->config['web-basepath'],
531 59
			'honorifics' => $this->getHonorifics()->getList(),
532 59
			'header_template' => $this->config['default-layout-templates']['header'],
533 59
			'footer_template' => $this->config['default-layout-templates']['footer'],
534 59
			'no_js_notice_template' => $this->config['default-layout-templates']['no-js-notice'],
535 59
			'piwik' => $this->config['piwik'],
536
		];
537
	}
538
539 13
	private function newReferrerGeneralizer() {
540 13
		return new ReferrerGeneralizer(
541 13
			$this->config['referrer-generalization']['default'],
542 13
			$this->config['referrer-generalization']['domain-map']
543
		);
544
	}
545
546 80
	private function getMediaWikiApi(): MediawikiApi {
547 80
		return $this->pimple['mw_api'];
548
	}
549
550 3
	public function setMediaWikiApi( MediawikiApi $api ) {
551 3
		$this->pimple['mw_api'] = $api;
552 3
	}
553
554 77
	private function getGuzzleClient(): ClientInterface {
555 77
		return $this->pimple['guzzle_client'];
556
	}
557
558 80
	private function newWikiPageRetriever(): PageRetriever {
559 80
		$PageRetriever = $this->newCachedPageRetriever();
560
561 80
		return $this->addProfilingDecorator( $PageRetriever, 'PageRetriever' );
562
	}
563
564 80
	private function newCachedPageRetriever(): PageRetriever {
565 80
		return new CachingPageRetriever(
566 80
			$this->newNonCachedApiPageRetriever(),
567 80
			$this->getPageCache()
568
		);
569
	}
570
571 80
	private function newNonCachedApiPageRetriever(): PageRetriever {
572 80
		return new ApiBasedPageRetriever(
573 80
			$this->getMediaWikiApi(),
574 80
			new ApiUser( $this->config['cms-wiki-user'], $this->config['cms-wiki-password'] ),
575 80
			$this->getLogger(),
576 80
			$this->config['cms-wiki-title-prefix']
577
		);
578
	}
579
580 89
	public function getLogger(): LoggerInterface {
581 89
		return $this->pimple['logger'];
582
	}
583
584 77
	private function getVarPath(): string {
585 77
		return __DIR__ . '/../../var';
586
	}
587
588 77
	public function getCachePath(): string {
589 77
		return $this->getVarPath() . '/cache';
590
	}
591
592
	public function getLoggingPath(): string {
593
		return $this->getVarPath() . '/log';
594
	}
595
596
	public function getTemplatePath(): string {
597
		return __DIR__ . '/../../app/templates';
598
	}
599
600 6
	public function newAddSubscriptionUseCase(): AddSubscriptionUseCase {
601 6
		return new AddSubscriptionUseCase(
602 6
			$this->getSubscriptionRepository(),
603 6
			$this->getSubscriptionValidator(),
604 6
			$this->newAddSubscriptionMailer()
605
		);
606
	}
607
608 3
	public function newConfirmSubscriptionUseCase(): ConfirmSubscriptionUseCase {
609 3
		return new ConfirmSubscriptionUseCase(
610 3
			$this->getSubscriptionRepository(),
611 3
			$this->newConfirmSubscriptionMailer()
612
		);
613
	}
614
615 6
	private function newAddSubscriptionMailer(): TemplateBasedMailer {
616 6
		return $this->newTemplateMailer(
617 6
			new TwigTemplate(
618 6
				$this->getTwig(),
619 6
				'Mail_Subscription_Request.twig',
620
				[
621 6
					'basepath' => $this->config['web-basepath'],
622 6
					'greeting_generator' => $this->getGreetingGenerator()
623
				]
624
			),
625 6
			'mail_subject_membership'
626
		);
627
	}
628
629 3
	private function newConfirmSubscriptionMailer(): TemplateBasedMailer {
630 3
		return $this->newTemplateMailer(
631 3
			new TwigTemplate(
632 3
					$this->getTwig(),
633 3
					'Mail_Subscription_Confirmation.twig',
634 3
					[ 'greeting_generator' => $this->getGreetingGenerator() ]
635
			),
636 3
			'mail_subject_membership'
637
		);
638
	}
639
640 43
	private function newTemplateMailer( TwigTemplate $template, string $messageKey ): TemplateBasedMailer {
641 43
		$mailer = new TemplateBasedMailer(
642 43
			$this->getMessenger(),
643
			$template,
644 43
			$this->getTranslator()->trans( $messageKey )
645
		);
646
647 43
		$mailer = new LoggingMailer( $mailer, $this->getLogger() );
648
649 43
		return $this->addProfilingDecorator( $mailer, 'Mailer' );
650
	}
651
652 40
	public function getGreetingGenerator() {
653 40
		return $this->pimple['greeting_generator'];
654
	}
655
656
	public function newCheckIbanUseCase(): CheckIbanUseCase {
657
		return new CheckIbanUseCase( $this->newBankDataConverter() );
658
	}
659
660
	public function newGenerateIbanUseCase(): GenerateIbanUseCase {
661
		return new GenerateIbanUseCase( $this->newBankDataConverter() );
662
	}
663
664
	public function newIbanPresenter(): IbanPresenter {
665
		return new IbanPresenter();
666
	}
667
668 21
	public function newBankDataConverter() {
669 21
		return new BankDataConverter( $this->config['bank-data-file'] );
670
	}
671
672
	public function setSubscriptionValidator( SubscriptionValidator $subscriptionValidator ) {
673
		$this->pimple['subscription_validator'] = $subscriptionValidator;
674
	}
675
676
	public function setPageTitlePrefix( string $prefix ) {
677
		$this->config['cms-wiki-title-prefix'] = $prefix;
678
	}
679
680 3
	public function newGetInTouchUseCase() {
681 3
		return new GetInTouchUseCase(
682 3
			$this->getContactValidator(),
683 3
			$this->getMessenger(),
684 3
			$this->newContactConfirmationMailer()
685
		);
686
	}
687
688 3
	private function newContactConfirmationMailer(): TemplateBasedMailer {
689 3
		return $this->newTemplateMailer(
690 3
			new TwigTemplate( $this->getTwig(), 'KontaktMailExtern.twig' ),
691 3
			'mail_subject_getintouch'
692
		);
693
	}
694
695 3
	private function getContactValidator(): GetInTouchValidator {
696 3
		return $this->pimple['contact_validator'];
697
	}
698
699 6
	private function newSubscriptionDuplicateValidator(): SubscriptionDuplicateValidator {
700 6
		return new SubscriptionDuplicateValidator(
701 6
				$this->getSubscriptionRepository(),
702 6
				$this->newSubscriptionDuplicateCutoffDate()
703
		);
704
	}
705
706 6
	private function newSubscriptionDuplicateCutoffDate(): \DateTime {
707 6
		$cutoffDateTime = new \DateTime();
708 6
		$cutoffDateTime->sub( new \DateInterval( $this->config['subscription-interval'] ) );
709 6
		return $cutoffDateTime;
710
	}
711
712 6
	private function newHonorificValidator(): AllowedValuesValidator {
713 6
		return new AllowedValuesValidator( $this->getHonorifics()->getKeys() );
714
	}
715
716 64
	private function getHonorifics(): Honorifics {
717 64
		return $this->pimple['honorifics'];
718
	}
719
720
	public function newPurgeCacheUseCase(): PurgeCacheUseCase {
721
		return new PurgeCacheUseCase(
722
			new AllOfTheCachePurger( $this->getTwig(), $this->getPageCache() ),
723
			$this->config['purging-secret']
724
		);
725
	}
726
727 21
	private function newBankDataValidator(): BankDataValidator {
728 21
		return new BankDataValidator( new IbanValidator( $this->newBankDataConverter() ) );
729
	}
730
731 43
	private function getMessenger(): Messenger {
732 43
		return $this->pimple['messenger'];
733
	}
734
735 41
	public function setMessenger( Messenger $messenger ) {
736 41
		$this->pimple['messenger'] = $messenger;
737 41
	}
738
739 40
	public function setNullMessenger() {
740 40
		$this->setMessenger( new Messenger(
741 40
			Swift_NullTransport::newInstance(),
742 40
			$this->getOperatorAddress()
743
		) );
744 40
	}
745
746 45
	public function getOperatorAddress() {
747 45
		return new EmailAddress( $this->config['operator-email'] );
748
	}
749
750 8
	public function newInternalErrorHTMLPresenter(): InternalErrorHtmlPresenter {
751 8
		return new InternalErrorHtmlPresenter( $this->getIncludeTemplate( 'ErrorPage.twig' ) );
752
	}
753
754 3
	public function newAccessDeniedHTMLPresenter(): InternalErrorHtmlPresenter {
755 3
		return new InternalErrorHtmlPresenter( $this->getLayoutTemplate( 'AccessDenied.twig' ) );
756
	}
757
758 84
	public function getTranslator(): TranslatorInterface {
759 84
		return $this->pimple['translator'];
760
	}
761
762 2
	public function setTranslator( TranslatorInterface $translator ) {
763 2
		$this->pimple['translator'] = $translator;
764 2
	}
765
766 77
	private function getTwigFactory(): TwigFactory {
767 77
		return $this->pimple['twig_factory'];
768
	}
769
770 22
	private function newTextPolicyValidator( string $policyName ): TextPolicyValidator {
771 22
		$contentProvider = $this->newWikiPageRetriever();
772 22
		$textPolicyConfig = $this->config['text-policies'][$policyName];
773
774 22
		return new TextPolicyValidator(
775 22
			new PageRetrieverBasedStringList( $contentProvider, $textPolicyConfig['badwords'] ?? '' ),
776 22
			new PageRetrieverBasedStringList( $contentProvider, $textPolicyConfig['whitewords'] ?? '' )
777
		);
778
	}
779
780 3
	private function newCommentPolicyValidator(): TextPolicyValidator {
781 3
		return $this->newTextPolicyValidator( 'comment' );
782
	}
783
784 5
	public function newCancelDonationUseCase( string $updateToken ): CancelDonationUseCase {
785 5
		return new CancelDonationUseCase(
786 5
			$this->getDonationRepository(),
787 5
			$this->newCancelDonationMailer(),
788 5
			$this->newDonationAuthorizer( $updateToken ),
789 5
			$this->newDonationEventLogger()
790
		);
791
	}
792
793 5
	private function newCancelDonationMailer(): TemplateBasedMailer {
794 5
		return $this->newTemplateMailer(
795 5
			new TwigTemplate(
796 5
				$this->getTwig(),
797 5
				'Mail_Donation_Cancellation_Confirmation.twig',
798 5
				[ 'greeting_generator' => $this->getGreetingGenerator() ]
799
			),
800 5
			'mail_subject_confirm_cancellation'
801
		);
802
	}
803
804 13
	public function newAddDonationUseCase(): AddDonationUseCase {
805 13
		return new AddDonationUseCase(
806 13
			$this->getDonationRepository(),
807 13
			$this->newDonationValidator(),
808 13
			$this->newDonationPolicyValidator(),
809 13
			$this->newReferrerGeneralizer(),
810 13
			$this->newDonationConfirmationMailer(),
811 13
			$this->newBankTransferCodeGenerator(),
812 13
			$this->newDonationTokenFetcher()
813
		);
814
	}
815
816 13
	private function newBankTransferCodeGenerator(): TransferCodeGenerator {
817 13
		return new UniqueTransferCodeGenerator(
818 13
			new SimpleTransferCodeGenerator(),
819 13
			$this->getEntityManager()
820
		);
821
	}
822
823 13
	private function newDonationValidator(): AddDonationValidator {
824 13
		return new AddDonationValidator(
825 13
			$this->newAmountValidator(),
826 13
			$this->newBankDataValidator(),
827 13
			$this->getEmailValidator()
828
		);
829
	}
830
831 2
	public function newPersonalInfoValidator(): DonorValidator {
832 2
		return new DonorValidator(
833 2
			new DonorNameValidator(),
834 2
			new DonorAddressValidator(),
835 2
			$this->getEmailValidator()
836
		);
837
	}
838
839 16
	private function newDonationConfirmationMailer(): DonationConfirmationMailer {
840 16
		return new DonationConfirmationMailer(
841 16
			$this->newTemplateMailer(
842 16
				new TwigTemplate(
843 16
					$this->getTwig(),
844 16
					'Mail_Donation_Confirmation.twig', // TODO: ongoing unification of different templates
845
					[
846 16
						'basepath' => $this->config['web-basepath'],
847 16
						'greeting_generator' => $this->getGreetingGenerator()
848
					]
849
				),
850 16
				'mail_subject_confirm_donation'
851
			)
852
		);
853
	}
854
855 1
	public function newPayPalUrlGenerator() {
856 1
		return new PayPalUrlGenerator( $this->getPayPalUrlConfig() );
857
	}
858
859 1
	private function getPayPalUrlConfig() {
860 1
		return PayPalUrlConfig::newFromConfig( $this->config['paypal'] );
861
	}
862
863 2
	private function newCreditCardUrlGenerator() {
864 2
		return new CreditCardUrlGenerator( $this->newCreditCardUrlConfig() );
865
	}
866
867 2
	private function newCreditCardUrlConfig() {
868 2
		return CreditCardUrlConfig::newFromConfig( $this->config['creditcard'] );
869
	}
870
871 34
	public function getDonationRepository(): DonationRepository {
872 34
		return $this->pimple['donation_repository'];
873
	}
874
875 15
	public function newAmountValidator(): AmountValidator {
876 15
		return new AmountValidator( 1 );
877
	}
878
879 11
	private function newAmountFormatter(): AmountFormatter {
880 11
		return new AmountFormatter( $this->config['locale'] );
881
	}
882
883 2
	public function newDecimalNumberFormatter(): NumberFormatter {
884 2
		return new NumberFormatter( $this->config['locale'], NumberFormatter::DECIMAL );
885
	}
886
887 3
	public function newAddCommentUseCase( string $updateToken ): AddCommentUseCase {
888 3
		return new AddCommentUseCase(
889 3
			$this->getDonationRepository(),
890 3
			$this->newDonationAuthorizer( $updateToken ),
891 3
			$this->newCommentPolicyValidator(),
892 3
			$this->newAddCommentValidator()
893
		);
894
	}
895
896 20
	private function newDonationAuthorizer( string $updateToken = null, string $accessToken = null ): DonationAuthorizer {
897 20
		return new DoctrineDonationAuthorizer(
898 20
			$this->getEntityManager(),
899
			$updateToken,
900
			$accessToken
901
		);
902
	}
903
904 76
	public function getTokenGenerator(): TokenGenerator {
905 76
		return $this->pimple['token_generator'];
906
	}
907
908 14
	public function newDonationConfirmationPresenter() {
909 14
		return new DonationConfirmationHtmlPresenter(
910 14
			$this->getIncludeTemplate( 'DonationConfirmation.twig', [ 'piwikGoals' => [ 3 ] ] )
911
		);
912
	}
913
914 2
	public function newCreditCardPaymentHtmlPresenter() {
915 2
		return new CreditCardPaymentHtmlPresenter(
916 2
			$this->getIncludeTemplate( 'CreditCardPaymentIframe.twig' ),
917 2
			$this->getTranslator(),
918 2
			$this->newCreditCardUrlGenerator()
919
		);
920
	}
921
922 5
	public function newCancelDonationHtmlPresenter() {
923 5
		return new CancelDonationHtmlPresenter(
924 5
			$this->getIncludeTemplate( 'Donation_Cancellation_Confirmation.twig' )
925
		);
926
	}
927
928 8
	public function newApplyForMembershipUseCase(): ApplyForMembershipUseCase {
929 8
		return new ApplyForMembershipUseCase(
930 8
			$this->getMembershipApplicationRepository(),
931 8
			$this->newMembershipApplicationTokenFetcher(),
932 8
			$this->newApplyForMembershipMailer(),
933 8
			$this->newMembershipApplicationValidator(),
934 8
			$this->newMembershipApplicationTracker(),
935 8
			$this->newMembershipApplicationPiwikTracker()
936
		);
937
	}
938
939 8
	private function newApplyForMembershipMailer(): TemplateBasedMailer {
940 8
		return $this->newTemplateMailer(
941 8
			new TwigTemplate(
942 8
				$this->getTwig(),
943 8
				'Mail_Membership_Application_Confirmation.twig',
944 8
				[ 'greeting_generator' => $this->getGreetingGenerator() ]
945
			),
946 8
			'mail_subject_confirm_membership_application'
947
		);
948
	}
949
950 8
	private function newMembershipApplicationValidator(): MembershipApplicationValidator {
951 8
		return new MembershipApplicationValidator(
952 8
			new MembershipFeeValidator(),
953 8
			$this->newBankDataValidator(),
954 8
			$this->getEmailValidator()
955
		);
956
	}
957
958 8
	private function newMembershipApplicationTracker(): ApplicationTracker {
959 8
		return new DoctrineApplicationTracker( $this->getEntityManager() );
960
	}
961
962 8
	private function newMembershipApplicationPiwikTracker(): ApplicationPiwikTracker {
963 8
		return new DoctrineApplicationPiwikTracker( $this->getEntityManager() );
964
	}
965
966 2
	public function newCancelMembershipApplicationUseCase( string $updateToken ): CancelMembershipApplicationUseCase {
967 2
		return new CancelMembershipApplicationUseCase(
968 2
			$this->newMembershipApplicationAuthorizer( $updateToken ),
969 2
			$this->getMembershipApplicationRepository(),
970 2
			$this->newCancelMembershipApplicationMailer()
971
		);
972
	}
973
974 2
	private function newMembershipApplicationAuthorizer(
975
		string $updateToken = null, string $accessToken = null ): ApplicationAuthorizer {
976
977 2
		return new DoctrineApplicationAuthorizer(
978 2
			$this->getEntityManager(),
979
			$updateToken,
980
			$accessToken
981
		);
982
	}
983
984 10
	public function getMembershipApplicationRepository(): ApplicationRepository {
985 10
		return $this->pimple['membership_application_repository'];
986
	}
987
988 2
	private function newCancelMembershipApplicationMailer(): TemplateBasedMailer {
989 2
		return $this->newTemplateMailer(
990 2
			new TwigTemplate(
991 2
				$this->getTwig(),
992 2
				'Mail_Membership_Application_Cancellation_Confirmation.twig',
993 2
				[ 'greeting_generator' => $this->getGreetingGenerator() ]
994
			),
995 2
			'mail_subject_confirm_membership_application_cancellation'
996
		);
997
	}
998
999
	public function newMembershipApplicationConfirmationUseCase( string $accessToken ) {
1000
		return new ShowMembershipApplicationConfirmationUseCase(
1001
			$this->newMembershipApplicationAuthorizer( null, $accessToken ), $this->getMembershipApplicationRepository(),
1002
			$this->newMembershipApplicationTokenFetcher()
1003
		);
1004
	}
1005
1006 9
	public function newShowDonationConfirmationUseCase( string $accessToken ): ShowDonationConfirmationUseCase {
1007 9
		return new ShowDonationConfirmationUseCase(
1008 9
			$this->newDonationAuthorizer( null, $accessToken ),
1009 9
			$this->getDonationRepository()
1010
		);
1011
	}
1012
1013 7
	public function setDonationConfirmationPageSelector( DonationConfirmationPageSelector $selector ) {
1014 7
		$this->pimple['confirmation-page-selector'] = $selector;
1015 7
	}
1016
1017 17
	public function getDonationConfirmationPageSelector() {
1018 17
		return $this->pimple['confirmation-page-selector'];
1019
	}
1020
1021 2
	public function newDonationFormViolationPresenter() {
1022 2
		$template = $this->getLayoutTemplate( 'DisplayPageLayout.twig' );
1023
		// TODO make this dependent on the 'form' value from the HTTP POST request
1024
		// (we need different form pages for A/B testing)
1025 2
		$template->context['main_template'] = 'DonationForm.twig';
0 ignored issues
show
Bug introduced by
The property context does not seem to exist in WMDE\Fundraising\Fronten...esentation\TwigTemplate.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1026 2
		return new DonationFormViolationPresenter( $template, $this->newAmountFormatter() );
1027
	}
1028
1029 9
	public function newDonationFormPresenter() {
1030 9
		$template = $this->getLayoutTemplate( 'DisplayPageLayout.twig' );
1031
		// TODO make this dependent on the 'form' value from the HTTP POST request
1032
		// (we need different form pages for A/B testing)
1033 9
		$template->context['main_template'] = 'DonationForm.twig';
0 ignored issues
show
Bug introduced by
The property context does not seem to exist in WMDE\Fundraising\Fronten...esentation\TwigTemplate.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1034 9
		return new DonationFormPresenter( $template, $this->newAmountFormatter() );
1035
	}
1036
1037 1
	public function newHandlePayPalPaymentNotificationUseCase( string $updateToken ) {
1038 1
		return new HandlePayPalPaymentNotificationUseCase(
1039 1
			$this->getDonationRepository(),
1040 1
			$this->newDonationAuthorizer( $updateToken ),
1041 1
			$this->newDonationConfirmationMailer(),
1042 1
			$this->getLogger(),
1043 1
			$this->newDonationEventLogger()
1044
		);
1045
	}
1046
1047 2
	public function getPayPalPaymentNotificationVerifier(): PaymentNotificationVerifier {
1048 2
		return $this->pimple['paypal-payment-notification-verifier'];
1049
	}
1050
1051 2
	public function setPayPalPaymentNotificationVerifier( PaymentNotificationVerifier $verifier ) {
1052 2
		$this->pimple['paypal-payment-notification-verifier'] = $verifier;
1053 2
	}
1054
1055 2
	public function newCreditCardNotificationUseCase( string $updateToken ) {
1056 2
		return new CreditCardNotificationUseCase(
1057 2
			$this->getDonationRepository(),
1058 2
			$this->newDonationAuthorizer( $updateToken ),
1059 2
			$this->getCreditCardService(),
1060 2
			$this->newDonationConfirmationMailer(),
1061 2
			$this->getLogger(),
1062 2
			$this->newDonationEventLogger()
1063
		);
1064
	}
1065
1066 2
	public function newCancelMembershipApplicationHtmlPresenter() {
1067 2
		return new CancelMembershipApplicationHtmlPresenter(
1068 2
			$this->getIncludeTemplate( 'Membership_Application_Cancellation_Confirmation.twig' )
1069
		);
1070
	}
1071
1072
	public function newMembershipApplicationConfirmationHtmlPresenter() {
1073
		return new MembershipApplicationConfirmationHtmlPresenter(
1074
			$this->getIncludeTemplate( 'MembershipApplicationConfirmation.twig' )
1075
		);
1076
	}
1077
1078 2
	public function newMembershipFormViolationPresenter() {
1079 2
		return new MembershipFormViolationPresenter(
1080 2
			$this->getIncludeTemplate( 'MembershipApplication.twig' )
1081
		);
1082
	}
1083
1084 2
	public function setCreditCardService( CreditCardService $ccService ) {
1085 2
		$this->pimple['credit-card-api-service'] = $ccService;
1086 2
	}
1087
1088 2
	public function getCreditCardService(): CreditCardService {
1089 2
		return $this->pimple['credit-card-api-service'];
1090
	}
1091
1092 2
	public function newCreditCardNotificationPresenter(): CreditCardNotificationPresenter {
1093 2
		return new CreditCardNotificationPresenter(
1094 2
			new TwigTemplate(
1095 2
				$this->getTwig(),
1096 2
				'CreditCardPaymentNotification.twig',
1097 2
				[ 'returnUrl' => $this->config['creditcard']['return-url'] ]
1098
			)
1099
		);
1100
	}
1101
1102 76
	private function newDoctrineDonationPrePersistSubscriber(): DoctrineDonationPrePersistSubscriber {
1103 76
		$tokenGenerator = $this->getTokenGenerator();
1104 76
		return new DoctrineDonationPrePersistSubscriber(
1105
			$tokenGenerator,
1106
			$tokenGenerator
1107
		);
1108
	}
1109
1110 76
	private function newDoctrineMembershipApplicationPrePersistSubscriber(): DoctrineMembershipApplicationPrePersistSubscriber {
1111 76
		$tokenGenerator = $this->getTokenGenerator();
1112 76
		return new DoctrineMembershipApplicationPrePersistSubscriber(
1113
			$tokenGenerator,
1114
			$tokenGenerator
1115
		);
1116
	}
1117
1118 16
	public function setTokenGenerator( TokenGenerator $tokenGenerator ) {
1119 16
		$this->pimple['token_generator'] = $tokenGenerator;
1120 16
	}
1121
1122
	public function disableDoctrineSubscribers() {
1123
		$this->addDoctrineSubscribers = false;
1124
	}
1125
1126 13
	private function newDonationTokenFetcher(): DonationTokenFetcher {
1127 13
		return new DoctrineDonationTokenFetcher(
1128 13
			$this->getEntityManager()
1129
		);
1130
	}
1131
1132 8
	private function newMembershipApplicationTokenFetcher(): ApplicationTokenFetcher {
1133 8
		return new DoctrineApplicationTokenFetcher(
1134 8
			$this->getEntityManager()
1135
		);
1136
	}
1137
1138 13
	private function newDonationPolicyValidator(): AddDonationPolicyValidator {
1139 13
		return new AddDonationPolicyValidator(
1140 13
			$this->newDonationAmountPolicyValidator(),
1141 13
			$this->newTextPolicyValidator( 'fields' )
1142
		);
1143
	}
1144
1145 13
	private function newDonationAmountPolicyValidator(): AmountPolicyValidator {
1146
		// in the future, this might come from the configuration
1147 13
		return new AmountPolicyValidator( 1000, 200, 300 );
1148
	}
1149
1150 2
	public function getDonationTimeframeLimit() {
1151 2
		return $this->config['donation-timeframe-limit'];
1152
	}
1153
1154 2
	public function newSystemMessageResponse( string $message ) {
1155 2
		$test = $this->getIncludeTemplate( 'System_Message.twig' );
1156 2
		return $test->render( [ 'message' => $message ] );
1157
	}
1158
1159 2
	public function getMembershipApplicationTimeframeLimit() {
1160 2
		return $this->config['membership-application-timeframe-limit'];
1161
	}
1162
1163 3
	private function newAddCommentValidator(): AddCommentValidator {
1164 3
		return new AddCommentValidator();
1165
	}
1166
1167 80
	private function getPageCache(): Cache {
1168 80
		return $this->pimple['page_cache'];
1169
	}
1170
1171
	public function enablePageCache() {
1172
		$this->pimple['page_cache'] = $this->pimple->share( function() {
1173
			return new FilesystemCache( $this->getCachePath() . '/pages' );
1174
		} );
1175
	}
1176
1177 86
	private function addProfilingDecorator( $objectToDecorate, string $profilingLabel ) {
1178 86
		if ( $this->profiler === null ) {
1179 86
			return $objectToDecorate;
1180
		}
1181
1182
		$builder = new ProfilingDecoratorBuilder( $this->profiler, $this->getProfilerDataCollector() );
1183
1184
		return $builder->decorate( $objectToDecorate, $profilingLabel );
1185
	}
1186
1187
	public function setProfiler( Stopwatch $profiler ) {
1188
		$this->profiler = $profiler;
1189
	}
1190
1191
	public function setLogger( LoggerInterface $logger ) {
1192
		$this->pimple['logger'] = $logger;
1193
	}
1194
1195
	public function getProfilerDataCollector(): ProfilerDataCollector {
1196
		return $this->pimple['profiler_data_collector'];
1197
	}
1198
1199
}
1200