|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Shopware\Core\Profiling; |
|
4
|
|
|
|
|
5
|
|
|
use Composer\InstalledVersions; |
|
6
|
|
|
use Shopware\Core\Framework\Bundle; |
|
7
|
|
|
use Shopware\Core\Kernel; |
|
8
|
|
|
use Symfony\Component\Config\FileLocator; |
|
9
|
|
|
use Symfony\Component\Config\Loader\DelegatingLoader; |
|
10
|
|
|
use Symfony\Component\Config\Loader\LoaderResolver; |
|
11
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
12
|
|
|
use Symfony\Component\DependencyInjection\Loader\GlobFileLoader; |
|
13
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
|
14
|
|
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
|
15
|
|
|
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @internal |
|
19
|
|
|
*/ |
|
20
|
|
|
class Profiling extends Bundle |
|
21
|
|
|
{ |
|
22
|
|
|
public function getTemplatePriority(): int |
|
23
|
|
|
{ |
|
24
|
|
|
return -2; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* {@inheritdoc} |
|
29
|
|
|
*/ |
|
30
|
|
|
public function build(ContainerBuilder $container): void |
|
31
|
|
|
{ |
|
32
|
|
|
/** @var string $environment */ |
|
33
|
|
|
$environment = $container->getParameter('kernel.environment'); |
|
34
|
|
|
|
|
35
|
|
|
parent::build($container); |
|
36
|
|
|
|
|
37
|
|
|
$this->buildConfig($container, $environment); |
|
38
|
|
|
|
|
39
|
|
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/DependencyInjection/')); |
|
40
|
|
|
$loader->load('services.xml'); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function boot(): void |
|
44
|
|
|
{ |
|
45
|
|
|
parent::boot(); |
|
46
|
|
|
// The profiler registers all profiler integrations in the constructor |
|
47
|
|
|
// Therefor we need to get the service once to initialize it |
|
48
|
|
|
$this->container->get(Profiler::class); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function configureRoutes(RoutingConfigurator $routes, string $environment): void |
|
52
|
|
|
{ |
|
53
|
|
|
if (!InstalledVersions::isInstalled('symfony/web-profiler-bundle')) { |
|
54
|
|
|
return; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
parent::configureRoutes($routes, $environment); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
private function buildConfig(ContainerBuilder $container, string $environment): void |
|
61
|
|
|
{ |
|
62
|
|
|
if (!InstalledVersions::isInstalled('symfony/web-profiler-bundle')) { |
|
63
|
|
|
return; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
$locator = new FileLocator('Resources/config'); |
|
67
|
|
|
|
|
68
|
|
|
$resolver = new LoaderResolver([ |
|
69
|
|
|
new YamlFileLoader($container, $locator), |
|
70
|
|
|
new GlobFileLoader($container, $locator), |
|
71
|
|
|
]); |
|
72
|
|
|
|
|
73
|
|
|
$configLoader = new DelegatingLoader($resolver); |
|
74
|
|
|
|
|
75
|
|
|
$confDir = $this->getPath() . '/Resources/config'; |
|
76
|
|
|
|
|
77
|
|
|
$configLoader->load($confDir . '/{packages}/*' . Kernel::CONFIG_EXTS, 'glob'); |
|
78
|
|
|
$configLoader->load($confDir . '/{packages}/' . $environment . '/*' . Kernel::CONFIG_EXTS, 'glob'); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|