1 | <?php |
||
37 | class SQLLoggerCollectorFactory implements FactoryInterface |
||
38 | { |
||
39 | /** |
||
40 | * @var string |
||
41 | */ |
||
42 | protected $name; |
||
43 | |||
44 | /** |
||
45 | * @param string $name |
||
46 | */ |
||
47 | 5 | public function __construct($name) |
|
48 | { |
||
49 | 5 | $this->name = $name; |
|
50 | 5 | } |
|
51 | |||
52 | /** |
||
53 | * {@inheritDoc} |
||
54 | */ |
||
55 | 5 | public function __invoke(ContainerInterface $container, $requestedName, array $options = null) |
|
56 | { |
||
57 | 5 | $options = $this->getOptions($container); |
|
58 | |||
59 | // @todo always ask the serviceLocator instead? (add a factory?) |
||
60 | 5 | if ($options->getSqlLogger()) { |
|
|
|||
61 | 2 | $debugStackLogger = $container->get($options->getSqlLogger()); |
|
62 | 2 | } else { |
|
63 | 3 | $debugStackLogger = new DebugStack(); |
|
64 | } |
||
65 | |||
66 | /** @var $configuration Configuration */ |
||
67 | 5 | $configuration = $container->get($options->getConfiguration()); |
|
68 | |||
69 | 5 | if (null !== $configuration->getSQLLogger()) { |
|
70 | 1 | $logger = new LoggerChain(); |
|
71 | 1 | $logger->addLogger($debugStackLogger); |
|
72 | 1 | $logger->addLogger($configuration->getSQLLogger()); |
|
73 | 1 | $configuration->setSQLLogger($logger); |
|
74 | 1 | } else { |
|
75 | 4 | $configuration->setSQLLogger($debugStackLogger); |
|
76 | } |
||
77 | |||
78 | 5 | return new SQLLoggerCollector($debugStackLogger, 'doctrine.sql_logger_collector.' . $options->getName()); |
|
79 | } |
||
80 | |||
81 | /** |
||
82 | * @param ContainerInterface $serviceLocator |
||
83 | * @return SQLLoggerCollectorOptions |
||
84 | * @throws \RuntimeException |
||
85 | */ |
||
86 | 5 | protected function getOptions(ContainerInterface $serviceLocator) |
|
87 | { |
||
88 | 5 | $options = $serviceLocator->get('Config'); |
|
89 | 5 | $options = $options['doctrine']; |
|
90 | 5 | $options = isset($options['sql_logger_collector'][$this->name]) |
|
91 | 5 | ? $options['sql_logger_collector'][$this->name] |
|
92 | 5 | : null; |
|
93 | |||
94 | 5 | if (null === $options) { |
|
95 | throw new \RuntimeException( |
||
96 | sprintf( |
||
97 | 'Configuration with name "%s" could not be found in "doctrine.sql_logger_collector".', |
||
98 | $this->name |
||
99 | ) |
||
100 | ); |
||
101 | } |
||
102 | |||
103 | 5 | $optionsClass = $this->getOptionsClass(); |
|
104 | |||
105 | 5 | return new $optionsClass($options); |
|
106 | } |
||
107 | |||
108 | /** |
||
109 | * {@inheritDoc} |
||
110 | */ |
||
111 | 5 | protected function getOptionsClass() |
|
115 | } |
||
116 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: