Completed
Push — master ( b587fb...d05392 )
by David
20:34
created

PublicServicesForFunctionalTestsPass::process()   A

Complexity

Conditions 5
Paths 9

Size

Total Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 9.1288
c 0
b 0
f 0
cc 5
nc 9
nop 1
1
<?php
2
3
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
4
use Symfony\Component\Config\Loader\LoaderInterface;
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\HttpFoundation\Response;
8
use Symfony\Component\HttpKernel\Kernel;
9
use Symfony\Component\Routing\RouteCollectionBuilder;
10
11
class AppKernel extends Kernel
12
{
13
    use MicroKernelTrait;
14
15
    /**
16
     * @var string
17
     */
18
    private static $cacheDir;
19
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function registerBundles()
24
    {
25
        $bundles =  [
26
            new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
27
            new \Symfony\Bundle\TwigBundle\TwigBundle(),
28
            new \Http\HttplugBundle\HttplugBundle(),
29
        ];
30
31
        if (in_array($this->getEnvironment(), array('dev', 'test', 'psr18'))) {
32
            $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
33
        }
34
35
        return $bundles;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
0 ignored issues
show
Unused Code introduced by
The parameter $container is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
42
    {
43
        $loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
44
        if ($this->isDebug()) {
45
            $loader->load(__DIR__.'/config/config_debug.yml');
46
        }
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    protected function configureRoutes(RouteCollectionBuilder $routes)
53
    {
54
        $routes->import('@WebProfilerBundle/Resources/config/routing/wdt.xml', '/_wdt');
55
        $routes->import('@WebProfilerBundle/Resources/config/routing/profiler.xml', '/_profiler');
56
57
        if (Kernel::MAJOR_VERSION < 4 || (Kernel::MAJOR_VERSION === 4 && Kernel::MINOR_VERSION === 0)) {
58
            $routes->add('/', 'kernel:indexAction');
59
        } else {
60
            // If 4.1+
61
            $routes->add('/', 'kernel::indexAction');
62
        }
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68
    public function getCacheDir()
69
    {
70
        if (null === self::$cacheDir) {
71
            self::$cacheDir = uniqid('cache');
72
        }
73
        return sys_get_temp_dir().'/httplug-bundle/'.self::$cacheDir;
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79
    public function getLogDir()
80
    {
81
        return sys_get_temp_dir().'/httplug-bundle/logs';
82
    }
83
84
    /**
85
     * {@inheritdoc}
86
     */
87
    protected function getContainerBaseClass()
88
    {
89
        return '\PSS\SymfonyMockerContainer\DependencyInjection\MockerContainer';
90
    }
91
92
    public function indexAction()
93
    {
94
        return new Response();
95
    }
96
97
    protected function build(ContainerBuilder $container)
98
    {
99
        $container->addCompilerPass(new PublicServicesForFunctionalTestsPass());
100
    }
101
}
102
103
class PublicServicesForFunctionalTestsPass implements CompilerPassInterface
104
{
105
    public function process(ContainerBuilder $container)
106
    {
107
        $services = [
108
            'httplug.strategy',
109
            'httplug.auto_discovery.auto_discovered_client',
110
            'httplug.auto_discovery.auto_discovered_async',
111
            'httplug.message_factory.default',
112
            'httplug.stream_factory.default',
113
            'httplug.uri_factory.default',
114
            'httplug.async_client.default',
115
            'httplug.client.default',
116
            'app.http.plugin.custom',
117
            'httplug.client.acme',
118
        ];
119
        foreach ($services as $service) {
120
            if ($container->hasDefinition($service)) {
121
                $container->getDefinition($service)->setPublic(true);
122
            }
123
124
        }
125
126
        $aliases = [
127
            'httplug.client',
128
        ];
129
        foreach ($aliases as $alias) {
130
            if ($container->hasAlias($alias)) {
131
                $container->getAlias($alias)->setPublic(true);
132
            }
133
        }
134
    }
135
}
136