AppKernel::getCacheDir()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
6
use Symfony\Component\Config\Loader\LoaderInterface;
7
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
use Symfony\Component\HttpFoundation\Response;
10
use Symfony\Component\HttpKernel\Kernel;
11
use Symfony\Component\Routing\RouteCollectionBuilder;
12
13
class AppKernel extends Kernel
14
{
15
    use MicroKernelTrait;
16
17
    /**
18
     * @var string
19
     */
20
    private static $cacheDir;
21
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function registerBundles()
26
    {
27
        $bundles = [
28
            new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
29
            new \Symfony\Bundle\TwigBundle\TwigBundle(),
30
            new \Http\HttplugBundle\HttplugBundle(),
31
        ];
32
33
        if (in_array($this->getEnvironment(), ['dev', 'test', 'psr18'])) {
34
            $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
35
        }
36
37
        return $bundles;
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
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...
44
    {
45
        $loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
46
        if ($this->isDebug()) {
47
            $loader->load(__DIR__.'/config/config_debug.yml');
48
        }
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    protected function configureRoutes(RouteCollectionBuilder $routes): void
55
    {
56
        $routes->import('@WebProfilerBundle/Resources/config/routing/wdt.xml', '/_wdt');
57
        $routes->import('@WebProfilerBundle/Resources/config/routing/profiler.xml', '/_profiler');
58
59
        if (Kernel::MAJOR_VERSION < 4 || (Kernel::MAJOR_VERSION === 4 && Kernel::MINOR_VERSION === 0)) {
60
            $routes->add('/', 'kernel:indexAction');
61
        } else {
62
            // If 4.1+
63
            $routes->add('/', 'kernel::indexAction');
64
        }
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70
    public function getCacheDir()
71
    {
72
        if (null === self::$cacheDir) {
73
            self::$cacheDir = uniqid('cache');
74
        }
75
76
        return sys_get_temp_dir().'/httplug-bundle/'.self::$cacheDir;
77
    }
78
79
    /**
80
     * {@inheritdoc}
81
     */
82
    public function getLogDir()
83
    {
84
        return sys_get_temp_dir().'/httplug-bundle/logs';
85
    }
86
87
    /**
88
     * {@inheritdoc}
89
     */
90
    protected function getContainerBaseClass()
91
    {
92
        return '\PSS\SymfonyMockerContainer\DependencyInjection\MockerContainer';
93
    }
94
95
    public function indexAction()
96
    {
97
        return new Response();
98
    }
99
100
    protected function build(ContainerBuilder $container): void
101
    {
102
        $container->addCompilerPass(new PublicServicesForFunctionalTestsPass());
103
    }
104
}
105
106
class PublicServicesForFunctionalTestsPass implements CompilerPassInterface
107
{
108
    public function process(ContainerBuilder $container): void
109
    {
110
        $services = [
111
            'httplug.strategy',
112
            'httplug.auto_discovery.auto_discovered_client',
113
            'httplug.auto_discovery.auto_discovered_async',
114
            'httplug.message_factory.default',
115
            'httplug.stream_factory.default',
116
            'httplug.uri_factory.default',
117
            'httplug.async_client.default',
118
            'httplug.client.default',
119
            'app.http.plugin.custom',
120
            'httplug.client.acme',
121
        ];
122
        foreach ($services as $service) {
123
            if ($container->hasDefinition($service)) {
124
                $container->getDefinition($service)->setPublic(true);
125
            }
126
        }
127
128
        $aliases = [
129
            'httplug.client',
130
        ];
131
        foreach ($aliases as $alias) {
132
            if ($container->hasAlias($alias)) {
133
                $container->getAlias($alias)->setPublic(true);
134
            }
135
        }
136
    }
137
}
138