Skip to content

Commit

Permalink
feat(MapperDataCollector): Add lazy badge for lazy results.
Browse files Browse the repository at this point in the history
  • Loading branch information
priyadi committed Feb 8, 2024
1 parent 0d46079 commit c0abcaa
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
class name.
* fix(`ProxyGenerator`): Borrow `__CG__` marker for compatibility with
third-party libraries.
* feat(`MapperDataCollector`): Add lazy badge for lazy results.

## 0.7.0

Expand Down
11 changes: 11 additions & 0 deletions src/Debug/TraceData.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Rekalogika\Mapper\Util\TypeUtil;
use Symfony\Component\PropertyInfo\Type;
use Symfony\Component\VarDumper\Cloner\Data;
use Symfony\Component\VarExporter\LazyObjectInterface;

final class TraceData
{
Expand Down Expand Up @@ -118,6 +119,16 @@ public function getResultType(): string
return $this->resultType ?? '__unknown__';
}

public function isLazyLoadingResult(): bool
{
$class = $this->getResultType();
if (!class_exists($class)) {
return false;
}

return is_a($class, LazyObjectInterface::class, true);
}

public function getTotalMappingsIncludingSubMappings(): int
{
$total = 1;
Expand Down
41 changes: 23 additions & 18 deletions templates/data_collector.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@
{% block toolbar %}
{% if collector.totalMappings > 0 %}
{% set icon %}
{{ source('@RekalogikaMapper/map.svg') }}
<span class="sf-toolbar-value">{{ collector.totalMappings }}</span>
{{ source('@RekalogikaMapper/map.svg') }}
<span class="sf-toolbar-value">{{ collector.totalMappings }}</span>
{% endset %}

{% set text %}
<div class="sf-toolbar-info-piece">
<b>Total mappings</b>
<span class="sf-toolbar-status">{{ collector.totalMappings }}</span>
</div>
<div class="sf-toolbar-info-piece">
<b>Total mappings</b>
<span class="sf-toolbar-status">{{ collector.totalMappings }}</span>
</div>

<div class="sf-toolbar-info-piece">
<b>Including submappings</b>
<span class="sf-toolbar-status">{{ collector.totalMappingsIncludingSubMappings }}</span>
</div>
<div class="sf-toolbar-info-piece">
<b>Including submappings</b>
<span class="sf-toolbar-status">{{ collector.totalMappingsIncludingSubMappings }}</span>
</div>

<div class="sf-toolbar-info-piece">
<b>Total time</b>
<span>
{{ '%.2f'|format(collector.totalTime * 1000) }}
<span class="unit">ms</span>
</span>
</div>
<div class="sf-toolbar-info-piece">
<b>Total time</b>
<span>
{{ '%.2f'|format(collector.totalTime * 1000) }}
<span class="unit">ms</span>
</span>
</div>
{% endset %}

{{ include('@WebProfiler/Profiler/toolbar_item.html.twig', { link: profiler_url }) }}
Expand Down Expand Up @@ -77,7 +77,12 @@
<td>{{ tracedata.sourceType|abbr_class }}</td>
<td>{{ tracedata.existingTargetType|abbr_class }}</td>
<td>{{ tracedata.targetType|raw }}</td>
<td>{{ tracedata.resultType|abbr_class }}</td>
<td>
{{ tracedata.resultType|abbr_class }}
{% if tracedata.lazyLoadingResult %}
<span class="badge badge-success">Lazy</span>
{% endif %}
</td>
<td>{{ tracedata.transformerClass|abbr_class }}</td>
<td>
<span class="nowrap">{{- '%.2f'|format(tracedata.time * 1000) -}}
Expand Down

0 comments on commit c0abcaa

Please sign in to comment.