1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace DoctrineORMModule\Service; |
6
|
|
|
|
7
|
|
|
use Doctrine\DBAL\Logging\DebugStack; |
8
|
|
|
use Doctrine\DBAL\Logging\LoggerChain; |
9
|
|
|
use DoctrineORMModule\Collector\SQLLoggerCollector; |
10
|
|
|
use DoctrineORMModule\Options\SQLLoggerCollectorOptions; |
11
|
|
|
use Interop\Container\ContainerInterface; |
12
|
|
|
use Laminas\ServiceManager\FactoryInterface; |
13
|
|
|
use Laminas\ServiceManager\ServiceLocatorInterface; |
14
|
|
|
use RuntimeException; |
15
|
|
|
use function sprintf; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* DBAL Configuration ServiceManager factory |
19
|
|
|
*/ |
20
|
|
|
class SQLLoggerCollectorFactory implements FactoryInterface |
|
|
|
|
21
|
|
|
{ |
22
|
|
|
/** @var string */ |
23
|
|
|
protected $name; |
24
|
|
|
|
25
|
5 |
|
public function __construct(string $name) |
26
|
|
|
{ |
27
|
5 |
|
$this->name = $name; |
28
|
5 |
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* {@inheritDoc} |
32
|
|
|
*/ |
33
|
5 |
|
public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null) |
34
|
|
|
{ |
35
|
5 |
|
$options = $this->getOptions($container); |
36
|
|
|
|
37
|
|
|
// @todo always ask the serviceLocator instead? (add a factory?) |
38
|
5 |
|
if ($options->getSqlLogger()) { |
39
|
2 |
|
$debugStackLogger = $container->get($options->getSqlLogger()); |
40
|
|
|
} else { |
41
|
3 |
|
$debugStackLogger = new DebugStack(); |
42
|
|
|
} |
43
|
|
|
|
44
|
5 |
|
$configuration = $container->get($options->getConfiguration()); |
45
|
|
|
|
46
|
5 |
|
if ($configuration->getSQLLogger() !== null) { |
47
|
1 |
|
$logger = new LoggerChain(); |
48
|
1 |
|
$logger->addLogger($debugStackLogger); |
|
|
|
|
49
|
1 |
|
$logger->addLogger($configuration->getSQLLogger()); |
|
|
|
|
50
|
1 |
|
$configuration->setSQLLogger($logger); |
51
|
|
|
} else { |
52
|
4 |
|
$configuration->setSQLLogger($debugStackLogger); |
53
|
|
|
} |
54
|
|
|
|
55
|
5 |
|
return new SQLLoggerCollector($debugStackLogger, 'doctrine.sql_logger_collector.' . $options->getName()); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* {@inheritDoc} |
60
|
|
|
*/ |
61
|
5 |
|
public function createService(ServiceLocatorInterface $container) |
62
|
|
|
{ |
63
|
5 |
|
return $this($container, SQLLoggerCollector::class); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return mixed |
68
|
|
|
* |
69
|
|
|
* @throws RuntimeException |
70
|
|
|
*/ |
71
|
5 |
|
protected function getOptions(ContainerInterface $serviceLocator) |
72
|
|
|
{ |
73
|
5 |
|
$options = $serviceLocator->get('config'); |
74
|
5 |
|
$options = $options['doctrine']; |
75
|
5 |
|
$options = $options['sql_logger_collector'][$this->name] ?? null; |
76
|
|
|
|
77
|
5 |
|
if ($options === null) { |
78
|
|
|
throw new RuntimeException( |
79
|
|
|
sprintf( |
80
|
|
|
'Configuration with name "%s" could not be found in "doctrine.sql_logger_collector".', |
81
|
|
|
$this->name |
82
|
|
|
) |
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
|
86
|
5 |
|
$optionsClass = $this->getOptionsClass(); |
87
|
|
|
|
88
|
5 |
|
return new $optionsClass($options); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* {@inheritDoc} |
93
|
|
|
*/ |
94
|
5 |
|
protected function getOptionsClass() |
95
|
|
|
{ |
96
|
5 |
|
return SQLLoggerCollectorOptions::class; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
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.