|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace Doyo\Bridge\CodeCoverage\Compiler; |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
use Doyo\Bridge\CodeCoverage\Listener\LocalListener; |
|
8
|
|
|
use Doyo\Bridge\CodeCoverage\Session\LocalSession; |
|
9
|
|
|
use Doyo\Bridge\CodeCoverage\Session\RemoteSession; |
|
10
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
|
11
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
12
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
13
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
14
|
|
|
|
|
15
|
|
|
class SessionPass implements CompilerPassInterface |
|
16
|
|
|
{ |
|
17
|
35 |
|
public function process(ContainerBuilder $container) |
|
18
|
|
|
{ |
|
19
|
35 |
|
$sessions = $container->getParameterBag()->get('sessions'); |
|
20
|
|
|
|
|
21
|
35 |
|
foreach($sessions as $name => $config){ |
|
22
|
|
|
$driver = $config['driver']; |
|
23
|
|
|
if('local' === $driver){ |
|
24
|
|
|
$this->createLocalSession($container, $name, $config); |
|
25
|
|
|
} |
|
26
|
|
|
} |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
private function createLocalSession(ContainerBuilder $container, string $name, array $config) |
|
|
|
|
|
|
30
|
|
|
{ |
|
31
|
|
|
$id = 'sessions.'.$name; |
|
32
|
|
|
$sessionId = $id.'.session'; |
|
33
|
|
|
$listenerId = $id.'.listener'; |
|
34
|
|
|
|
|
35
|
|
|
$session = new Definition(LocalSession::class); |
|
36
|
|
|
$session->addArgument($name); |
|
37
|
|
|
$session->addTag('coverage.session'); |
|
38
|
|
|
$session->addMethodCall('init',[$container->getParameter('config')]); |
|
39
|
|
|
$container->setDefinition($sessionId, $session); |
|
40
|
|
|
|
|
41
|
|
|
$listener = new Definition(LocalListener::class); |
|
42
|
|
|
$listener->addArgument(new Reference($sessionId)); |
|
43
|
|
|
$container->setDefinition($listenerId, $listener); |
|
44
|
|
|
|
|
45
|
|
|
$dispatcher = $container->findDefinition('coverage'); |
|
46
|
|
|
$dispatcher->addMethodCall('addSubscriber',[new Reference($listenerId)]); |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.