summaryrefslogtreecommitdiff
path: root/vendor/symfony/cache/DependencyInjection/CacheCollectorPass.php
diff options
context:
space:
mode:
authorpolo <ordipolo@gmx.fr>2024-08-13 23:45:21 +0200
committerpolo <ordipolo@gmx.fr>2024-08-13 23:45:21 +0200
commitbf6655a534a6775d30cafa67bd801276bda1d98d (patch)
treec6381e3f6c81c33eab72508f410b165ba05f7e9c /vendor/symfony/cache/DependencyInjection/CacheCollectorPass.php
parent94d67a4b51f8e62e7d518cce26a526ae1ec48278 (diff)
downloadAppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.zip
VERSION 0.2 doctrine ORM et entités
Diffstat (limited to 'vendor/symfony/cache/DependencyInjection/CacheCollectorPass.php')
-rw-r--r--vendor/symfony/cache/DependencyInjection/CacheCollectorPass.php75
1 files changed, 75 insertions, 0 deletions
diff --git a/vendor/symfony/cache/DependencyInjection/CacheCollectorPass.php b/vendor/symfony/cache/DependencyInjection/CacheCollectorPass.php
new file mode 100644
index 0000000..ed95740
--- /dev/null
+++ b/vendor/symfony/cache/DependencyInjection/CacheCollectorPass.php
@@ -0,0 +1,75 @@
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\Cache\DependencyInjection;
13
14use Symfony\Component\Cache\Adapter\TagAwareAdapterInterface;
15use Symfony\Component\Cache\Adapter\TraceableAdapter;
16use Symfony\Component\Cache\Adapter\TraceableTagAwareAdapter;
17use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
18use Symfony\Component\DependencyInjection\ContainerBuilder;
19use Symfony\Component\DependencyInjection\Definition;
20use Symfony\Component\DependencyInjection\Reference;
21
22/**
23 * Inject a data collector to all the cache services to be able to get detailed statistics.
24 *
25 * @author Tobias Nyholm <tobias.nyholm@gmail.com>
26 */
27class CacheCollectorPass implements CompilerPassInterface
28{
29 public function process(ContainerBuilder $container): void
30 {
31 if (!$container->hasDefinition('data_collector.cache')) {
32 return;
33 }
34
35 foreach ($container->findTaggedServiceIds('cache.pool') as $id => $attributes) {
36 $poolName = $attributes[0]['name'] ?? $id;
37
38 $this->addToCollector($id, $poolName, $container);
39 }
40 }
41
42 private function addToCollector(string $id, string $name, ContainerBuilder $container): void
43 {
44 $definition = $container->getDefinition($id);
45 if ($definition->isAbstract()) {
46 return;
47 }
48
49 $collectorDefinition = $container->getDefinition('data_collector.cache');
50 $recorder = new Definition(is_subclass_of($definition->getClass(), TagAwareAdapterInterface::class) ? TraceableTagAwareAdapter::class : TraceableAdapter::class);
51 $recorder->setTags($definition->getTags());
52 if (!$definition->isPublic() || !$definition->isPrivate()) {
53 $recorder->setPublic($definition->isPublic());
54 }
55 $recorder->setArguments([new Reference($innerId = $id.'.recorder_inner')]);
56
57 foreach ($definition->getMethodCalls() as [$method, $args]) {
58 if ('setCallbackWrapper' !== $method || !$args[0] instanceof Definition || !($args[0]->getArguments()[2] ?? null) instanceof Definition) {
59 continue;
60 }
61 if ([new Reference($id), 'setCallbackWrapper'] == $args[0]->getArguments()[2]->getFactory()) {
62 $args[0]->getArguments()[2]->setFactory([new Reference($innerId), 'setCallbackWrapper']);
63 }
64 }
65
66 $definition->setTags([]);
67 $definition->setPublic(false);
68
69 $container->setDefinition($innerId, $definition);
70 $container->setDefinition($id, $recorder);
71
72 // Tell the collector to add the new instance
73 $collectorDefinition->addMethodCall('addInstance', [$name, new Reference($id)]);
74 }
75}