Skip to content

Commit

Permalink
Fix TraceableFileLocator
Browse files Browse the repository at this point in the history
  • Loading branch information
jdreesen committed Jun 29, 2022
1 parent 19336e6 commit 45103cd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 23 deletions.
30 changes: 20 additions & 10 deletions Debug/TraceableFileLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,42 @@

namespace JMS\SerializerBundle\Debug;

use Metadata\Driver\FileLocator;
use Metadata\Driver\AdvancedFileLocatorInterface;

/**
* @internal
*/
final class TraceableFileLocator extends FileLocator
final class TraceableFileLocator implements AdvancedFileLocatorInterface
{
/**
* @var AdvancedFileLocatorInterface
*/
private $decorated;
private $files = [];

public function __construct(array $dirs)
public function __construct(AdvancedFileLocatorInterface $decorated)
{
parent::__construct($dirs);
$this->decorated = $decorated;
}

public function getAttemptedFiles()
public function getAttemptedFiles(): array
{
return $this->files;
}

protected function loadFileIfFound($prefix, $dir, \ReflectionClass $class, $extension)
public function findFileForClass(\ReflectionClass $class, string $extension): ?string
{
$pathData = parent::loadFileIfFound($prefix, $dir, $class, $extension);
$path = $this->decorated->findFileForClass($class, $extension);

if ($pathData[0] !== null) {
$this->files[$class->getName()][$pathData[0]] = $pathData[1];
if ($path !== null) {
$this->files[$class->getName()][] = $path;
}
return $pathData;

return $path;
}

public function findAllClasses(string $extension): array
{
return $this->decorated->findAllClasses($extension);
}
}
14 changes: 8 additions & 6 deletions Resources/config/debug.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<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.metadata.file_locator"/>
<argument type="service" id="jms_serializer.metadata.traceable_file_locator"/>
<argument type="service" id="jms_serializer.traceable_runs_listener"/>

<tag name="data_collector"
Expand Down Expand Up @@ -47,11 +47,13 @@
<argument type="service" id="jms_serializer.traceable_handler_registry.inner"/>
</service>

<service id="jms_serializer.metadata.traceable_file_locator" class="JMS\SerializerBundle\Debug\TraceableFileLocator" public="false">
<argument type="collection" /><!-- Namespace Prefixes mapping to Directories -->
</service>

<service id="jms_serializer.metadata.file_locator" alias="jms_serializer.metadata.traceable_file_locator">
<service
id="jms_serializer.metadata.traceable_file_locator"
class="JMS\SerializerBundle\Debug\TraceableFileLocator"
decorates="jms_serializer.metadata.file_locator"
decoration-priority="-128"
public="false">
<argument type="service" id="jms_serializer.metadata.traceable_file_locator.inner"/>
</service>

<service id="jms_serializer.event_dispatcher" alias="jms_serializer.traceable_event_dispatcher">
Expand Down
9 changes: 2 additions & 7 deletions Resources/views/Collector/metadata.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,12 @@
</table>
{%- endif -%}


<h3>Attempted files</h3>
{%- if collector.metadataFiles is empty -%}
<div class="empty">
<p>No metadata files attempted (if this list is empty, probably all the data are cached as expected)</p>
</div>
{%- else -%}


<table>
<thead>
<tr>
Expand All @@ -52,10 +49,8 @@
<tr>
<td>{{ class }}</td>
<td nowrap="nowrap">
{%- for file, found in files -%}
<span style="color: {{ found ? 'green': 'red' }}">
{{ file }} ({{ found ? 'found': 'not found' }})<br/>
</span>
{%- for file in files -%}
{{ file }}<br/>
{% endfor %}
</td>
</tr>
Expand Down

0 comments on commit 45103cd

Please sign in to comment.