mirror of
https://git.friendi.ca/friendica/friendica-addons.git
synced 2024-09-14 19:35:11 +00:00
b0ee9fdf2a
- Removing symfony/polyfill-apcu (v1.28.0) - Removing psr/simple-cache (1.0.1) - Updating psr/http-message (1.1 => 2.0) - Downgrading psr/container (2.0.2 => 1.1.2) - Updating slim/slim (4.12.0 => 4.13.0) - Installing symfony/polyfill-php80 (v1.29.0) - Installing symfony/var-exporter (v5.4.35) - Installing symfony/deprecation-contracts (v2.5.2) - Installing symfony/service-contracts (v2.5.2) - Installing symfony/polyfill-php73 (v1.29.0) - Installing symfony/cache-contracts (v2.5.2) - Updating symfony/cache (v3.4.47 => v4.4.48)
81 lines
2.9 KiB
PHP
81 lines
2.9 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of the Symfony package.
|
|
*
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Symfony\Component\Cache\DependencyInjection;
|
|
|
|
use Symfony\Component\Cache\Adapter\TagAwareAdapterInterface;
|
|
use Symfony\Component\Cache\Adapter\TraceableAdapter;
|
|
use Symfony\Component\Cache\Adapter\TraceableTagAwareAdapter;
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|
use Symfony\Component\DependencyInjection\Definition;
|
|
use Symfony\Component\DependencyInjection\Reference;
|
|
|
|
/**
|
|
* Inject a data collector to all the cache services to be able to get detailed statistics.
|
|
*
|
|
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
|
|
*/
|
|
class CacheCollectorPass implements CompilerPassInterface
|
|
{
|
|
private $dataCollectorCacheId;
|
|
private $cachePoolTag;
|
|
private $cachePoolRecorderInnerSuffix;
|
|
|
|
public function __construct(string $dataCollectorCacheId = 'data_collector.cache', string $cachePoolTag = 'cache.pool', string $cachePoolRecorderInnerSuffix = '.recorder_inner')
|
|
{
|
|
$this->dataCollectorCacheId = $dataCollectorCacheId;
|
|
$this->cachePoolTag = $cachePoolTag;
|
|
$this->cachePoolRecorderInnerSuffix = $cachePoolRecorderInnerSuffix;
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function process(ContainerBuilder $container)
|
|
{
|
|
if (!$container->hasDefinition($this->dataCollectorCacheId)) {
|
|
return;
|
|
}
|
|
|
|
foreach ($container->findTaggedServiceIds($this->cachePoolTag) as $id => $attributes) {
|
|
$poolName = $attributes[0]['name'] ?? $id;
|
|
|
|
$this->addToCollector($id, $poolName, $container);
|
|
}
|
|
}
|
|
|
|
private function addToCollector(string $id, string $name, ContainerBuilder $container)
|
|
{
|
|
$definition = $container->getDefinition($id);
|
|
if ($definition->isAbstract()) {
|
|
return;
|
|
}
|
|
|
|
$collectorDefinition = $container->getDefinition($this->dataCollectorCacheId);
|
|
$recorder = new Definition(is_subclass_of($definition->getClass(), TagAwareAdapterInterface::class) ? TraceableTagAwareAdapter::class : TraceableAdapter::class);
|
|
$recorder->setTags($definition->getTags());
|
|
if (!$definition->isPublic() || !$definition->isPrivate()) {
|
|
$recorder->setPublic($definition->isPublic());
|
|
}
|
|
$recorder->setArguments([new Reference($innerId = $id.$this->cachePoolRecorderInnerSuffix)]);
|
|
|
|
$definition->setTags([]);
|
|
$definition->setPublic(false);
|
|
|
|
$container->setDefinition($innerId, $definition);
|
|
$container->setDefinition($id, $recorder);
|
|
|
|
// Tell the collector to add the new instance
|
|
$collectorDefinition->addMethodCall('addInstance', [$name, new Reference($id)]);
|
|
$collectorDefinition->setPublic(false);
|
|
}
|
|
}
|