Skip to content

Commit

Permalink
Merge pull request #900 from scyzoryck/fix-collecting-debug-info
Browse files Browse the repository at this point in the history
Stop collecting metadata from cache
  • Loading branch information
goetas authored Sep 12, 2022
2 parents 19336e6 + d08033a commit f91b701
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 71 deletions.
63 changes: 0 additions & 63 deletions Debug/TraceableDriver.php

This file was deleted.

53 changes: 53 additions & 0 deletions Debug/TraceableMetadataFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php declare(strict_types=1);

namespace JMS\SerializerBundle\Debug;

use Metadata\AdvancedMetadataFactoryInterface;
use Metadata\ClassMetadata;

/**
* @internal
*/
final class TraceableMetadataFactory implements AdvancedMetadataFactoryInterface
{
private $storage = [];

/**
* @var AdvancedMetadataFactoryInterface
*/
private $metadataFactory;

public function __construct(AdvancedMetadataFactoryInterface $metadataFactory)
{
$this->metadataFactory = $metadataFactory;
}

public function getLoadedMetadata(): array
{
return $this->storage;
}

public function getAllClassNames(): array
{
return $this->metadataFactory->getAllClassNames();
}

public function getMetadataForClass(string $className)
{
$metadata = $this->metadataFactory->getMetadataForClass($className);
if ($metadata instanceof ClassMetadata) {
$this->trackMetadata($metadata);
}

return $metadata;
}

protected function trackMetadata(ClassMetadata $metadata): void
{
$class = $metadata->name;
$this->storage[$class] = array_merge(
$this->storage[$class] ?? [], $metadata->fileResources
);
$this->storage[$class] = array_unique($this->storage[$class]);
}
}
10 changes: 5 additions & 5 deletions Resources/config/debug.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<argument type="collection" />
<argument type="service" id="jms_serializer.event_dispatcher"/>
<argument type="service" id="jms_serializer.traceable_handler_registry"/>
<argument type="service" id="jms_serializer.metadata.traceable_cache"/>
<argument type="service" id="jms_serializer.traceable_metadata_factory"/>
<argument type="service" id="jms_serializer.metadata.file_locator"/>
<argument type="service" id="jms_serializer.traceable_runs_listener"/>

Expand All @@ -29,13 +29,13 @@
</service>

<service
id="jms_serializer.metadata.traceable_cache"
class="JMS\SerializerBundle\Debug\TraceableDriver"
decorates="jms_serializer.metadata.cache"
id="jms_serializer.traceable_metadata_factory"
class="JMS\SerializerBundle\Debug\TraceableMetadataFactory"
decorates="jms_serializer.metadata_factory"
decoration-priority="-128"
public="false">

<argument type="service" id="jms_serializer.metadata.traceable_cache.inner"/>
<argument type="service" id="jms_serializer.traceable_metadata_factory.inner"/>
</service>

<service
Expand Down
28 changes: 25 additions & 3 deletions Tests/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace JMS\SerializerBundle\Tests\DependencyInjection;

use Doctrine\Common\Annotations\AnnotationReader;
use JMS\SerializerBundle\DependencyInjection\Configuration;
use JMS\SerializerBundle\JMSSerializerBundle;
use PHPUnit\Framework\TestCase;
Expand All @@ -16,7 +17,8 @@ class ConfigurationTest extends TestCase
private function getContainer(array $configs = [])
{
$container = new ContainerBuilder();


$container->set('annotation_reader', new AnnotationReader());
$container->setParameter('kernel.debug', true);
$container->setParameter('kernel.cache_dir', sys_get_temp_dir() . '/serializer');
$container->setParameter('kernel.bundles', ['JMSSerializerBundle' => 'JMS\SerializerBundle\JMSSerializerBundle']);
Expand All @@ -25,7 +27,7 @@ private function getContainer(array $configs = [])

$extension = $bundle->getContainerExtension();
$extension->load($configs, $container);

return $container;
}

Expand Down Expand Up @@ -113,7 +115,27 @@ public function testConfigComposed()
$this->assertArrayNotHasKey('JMSSerializerBundleNs1', $directories);
$this->assertEquals($ref->getPath() . '/Resources/config', $directories['JMSSerializerBundleNs2']);
}

public function testDebugWithoutCache()
{
$container = $this->getContainer([
[
'metadata' => [
'cache' => 'none',
'directories' => [
'foo' => [
'namespace_prefix' => 'JMSSerializerBundleNs1',
'path' => '@JMSSerializerBundle',
],
],
],
'profiler' => true,
],
]);
$container->compile();

$this->assertNotEmpty($container->get('jms_serializer'));
}

public function testContextDefaults()
{
$processor = new Processor();
Expand Down

0 comments on commit f91b701

Please sign in to comment.