|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
|
4
|
|
|
|
|
5
|
|
|
namespace WMDE\Fundraising\Frontend\Factories\EnvironmentSetup; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\ORM\Tools\Setup; |
|
8
|
|
|
use Monolog\Formatter\JsonFormatter; |
|
9
|
|
|
use Monolog\Handler\StreamHandler; |
|
10
|
|
|
use Monolog\Logger; |
|
11
|
|
|
use Psr\Log\LoggerInterface; |
|
12
|
|
|
use WMDE\Fundraising\Frontend\Factories\FunFunFactory; |
|
13
|
|
|
|
|
14
|
|
|
class ProductionEnvironmentSetup implements EnvironmentSetup { |
|
15
|
1 |
|
|
|
16
|
1 |
|
public function setEnvironmentDependentInstances( FunFunFactory $factory ) { |
|
17
|
|
|
$this->initializeLoggers( $factory ); |
|
18
|
1 |
|
|
|
19
|
1 |
|
$factory->enableCaching(); |
|
|
|
|
|
|
20
|
|
|
} |
|
21
|
1 |
|
|
|
22
|
1 |
|
private function initializeLoggers( FunFunFactory $factory ) { |
|
23
|
1 |
|
$this->setPaypalLogger( $factory ); |
|
24
|
1 |
|
$this->setSofortLogger( $factory ); |
|
25
|
1 |
|
$this->setCreditCardLogger( $factory ); |
|
26
|
|
|
$this->setDoctrineConfiguration( $factory ); |
|
27
|
1 |
|
} |
|
28
|
1 |
|
|
|
29
|
1 |
|
private function setPaypalLogger( FunFunFactory $factory ) { |
|
30
|
1 |
|
$factory->setPaypalLogger( $this->createStreamLoggerForPayment( 'paypal', $factory->getLoggingPath() ) ); |
|
31
|
|
|
} |
|
32
|
1 |
|
|
|
33
|
|
|
private function setSofortLogger( FunFunFactory $factory ) { |
|
34
|
1 |
|
$factory->setSofortLogger( $this->createStreamLoggerForPayment( 'sofort', $factory->getLoggingPath() ) ); |
|
35
|
1 |
|
} |
|
36
|
|
|
|
|
37
|
1 |
|
private function setDoctrineConfiguration( FunFunFactory $factory ) { |
|
38
|
1 |
|
// Setup will choose its own caching (APCu, Redis, Memcached, Array) based on the PHP environment and its extensions. |
|
39
|
|
|
// See https://phabricator.wikimedia.org/T249338 |
|
40
|
1 |
|
$factory->setDoctrineConfiguration( Setup::createConfiguration( false, $factory->getWritableApplicationDataPath() . '/doctrine_proxies' ) ); |
|
41
|
1 |
|
} |
|
42
|
|
|
|
|
43
|
1 |
|
private function setCreditCardLogger( FunFunFactory $factory ) { |
|
44
|
1 |
|
$factory->setCreditCardLogger( $this->createStreamLoggerForPayment( 'creditcard', $factory->getLoggingPath() ) ); |
|
45
|
|
|
} |
|
46
|
1 |
|
|
|
47
|
1 |
|
private function createStreamLoggerForPayment( string $paymentName, string $loggingPath ): LoggerInterface { |
|
48
|
|
|
$logger = new Logger( $paymentName ); |
|
49
|
1 |
|
$streamHandler = new StreamHandler( $loggingPath . '/' . $paymentName . '.log' ); |
|
50
|
1 |
|
$streamHandler->setFormatter( new JsonFormatter() ); |
|
51
|
1 |
|
$logger->pushHandler( $streamHandler ); |
|
52
|
|
|
return $logger; |
|
53
|
1 |
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|