Completed
Pull Request — master (#971)
by wiese
94:17 queued 29:21
created

SofortToggleServiceProvider::register()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 2
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\Fundraising\Frontend\Presentation;
6
7
use Pimple\Container;
8
use Pimple\ServiceProviderInterface;
9
use Silex\Api\BootableProviderInterface;
10
use Silex\Application;
11
use Symfony\Component\HttpFoundation\Request;
12
13
class SofortToggleServiceProvider implements ServiceProviderInterface, BootableProviderInterface {
14
15
	private const QUERY_PARAM_NAME = 'pmt';
16
17
	private $paymentTypesSettings;
18
19
	public function __construct( PaymentTypesSettings $paymentTypesSettings ) {
20
		$this->paymentTypesSettings = $paymentTypesSettings;
21
	}
22
23
	public function register( Container $app ): void {
24
	}
25
26
	public function boot( Application $app ): void {
27
		$app->before( function( Request $request ): void {
28
			if ( $request->query->get( self::QUERY_PARAM_NAME ) === '0' ) {
29
				$this->paymentTypesSettings->updateSetting( 'SUB', PaymentTypesSettings::PURPOSE_DONATION, false );
30
			}
31
		}, Application::EARLY_EVENT );
32
	}
33
}
34