Skip to content

Commit

Permalink
symfony/dependency-injection ^4.0 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
steevanb committed Oct 2, 2018
1 parent a92ca8a commit 68ff160
Show file tree
Hide file tree
Showing 7 changed files with 311 additions and 196 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,25 @@ public function getName(): string

public function collect(Request $request, Response $response, \Exception $exception = null): void
{
$this->introspection->introspect();

$this->data = [
'containerCachePath' => $this->introspection->getContainerCachePath(),
'containerCacheDir' => $this->introspection->getContainerCacheDir(),
'countContainerCacheFiles' => $this->introspection->countContainerCacheFiles(),
'countContainerCacheLines' => $this->introspection->countContainerCacheLines(),
'containerCacheSize' => $this->introspection->getContainerCacheSize(),

'registeredServices' => $this->introspection->getRegisteredServices(),
'countRegisteredServices' => $this->introspection->countRegisteredServices(),
'countServices' => $this->introspection->countServices(),

'instantiatedServices' => $this->introspection->getInstantiatedServices(),
'countInstanciatedServices' => $this->introspection->countInstantiatedServices(),

'publicServices' => $this->introspection->getPublicServices(),
'countPublicServices' => $this->introspection->countPublicServices(),

'privateServices' => $this->introspection->getPrivateServices(),
'countPrivateServices' => $this->introspection->countPrivateServices(),
'removedServices' => $this->introspection->getRemovedServices(),
'countRemovedServices' => $this->introspection->countRemovedServices(),

'parameters' => $this->introspection->getParameters(),
'countParameters' => $this->introspection->countParameters()
Expand Down Expand Up @@ -82,16 +83,6 @@ public function getContainerCacheSize(): int
return $this->data['containerCacheSize'];
}

public function getRegisteredServices(): array
{
return $this->data['registeredServices'];
}

public function countRegisteredServices(): int
{
return $this->data['countRegisteredServices'];
}

public function getInstantiatedServices(): array
{
return $this->data['instantiatedServices'];
Expand All @@ -112,14 +103,14 @@ public function countPublicServices(): int
return $this->data['countPublicServices'];
}

public function getPrivateServices(): array
public function getRemovedServices(): array
{
return $this->data['privateServices'];
return $this->data['removedServices'];
}

public function countPrivateServices(): int
public function countRemovedServices(): int
{
return $this->data['countPrivateServices'];
return $this->data['countRemovedServices'];
}

public function getParameters(): array
Expand All @@ -131,4 +122,21 @@ public function countParameters(): int
{
return $this->data['countParameters'];
}

public function countServices(): int
{
return $this->data['countServices'];
}

public function getInstantiatedInfos(string $id): ?array
{
$services = $this->getInstantiatedServices();

return array_key_exists($id, $services) ? $services[$id] : null;
}

public function dumpParameterValue($data): void
{
echo var_export($data, true);
}
}
Original file line number Diff line number Diff line change
@@ -1,35 +1,48 @@
{% extends '@WebProfiler/Profiler/layout.html.twig' %}

{% macro serviceInstantiation(infos) %}
{% if infos is null %}
Not instantiated
{% elseif infos.ocramiusLazy %}
<span class="label status-warning">Ocramius Lazy</span>
{% else %}
<span class="label status-success">Normal</span>
{% endif %}
{% endmacro %}

{% block toolbar %}
{% set icon %}
{{ include('@ContainerIntrospection/DataCollector/container.svg') }}
<span class="sf-toolbar-value">{{ collector.countInstantiatedServices()|localizednumber }} / {{ collector.countRegisteredServices()|localizednumber }}</span>
<span class="sf-toolbar-value">
{{ collector.countInstantiatedServices()|number_format(0, '.', ',') }}
/ {{ collector.countServices()|number_format(0, '.', ',') }}
</span>
{% endset %}

{% set text %}
<div class="sf-toolbar-info-piece">
<b>Instantiated services</b>
<span>{{ collector.countInstantiatedServices()|localizednumber }}</span>
<b>Instantiated</b>
<span>{{ collector.countInstantiatedServices()|number_format(0, '.', ',') }}</span>
</div>

<div class="sf-toolbar-info-piece">
<b>Registered services</b>
<span>{{ collector.countRegisteredServices()|localizednumber }}</span>
<b>Removed</b>
<span>{{ collector.countRemovedServices()|number_format(0, '.', ',') }}</span>
</div>

<div class="sf-toolbar-info-piece">
<b>Public services</b>
<span>{{ collector.countPublicServices()|localizednumber }}</span>
<b>Public</b>
<span>{{ collector.countPublicServices()|number_format(0, '.', ',') }}</span>
</div>

<div class="sf-toolbar-info-piece">
<b>Private services</b>
<span>{{ collector.countPrivateServices()|localizednumber }}</span>
<b>Total</b>
<span>{{ collector.countServices()|number_format(0, '.', ',') }}</span>
</div>

<div class="sf-toolbar-info-piece">
<b>Parameters</b>
<span>{{ collector.countParameters()|localizednumber }}</span>
<span>{{ collector.countParameters()|number_format(0, '.', ',') }}</span>
</div>
{% endset %}

Expand Down Expand Up @@ -59,20 +72,39 @@
color: #8959A8;
font-weight: bold;
}
.label.visibility-public {
background: #269cce;
color: #FFF;
}
.label.visibility-private {
background: #666666;
color: #FFF;
}
</style>
{% endblock %}

{% block panel %}
{% import _self as self %}

<h2>Statistics</h2>

<div class="metrics">
<div class="metric">
<span class="value" title="{{ collector.getContainerCachePath() }}">{{ collector.getContainerCacheDir() }}</span>
<span class="label">Cache dir</span>
<span class="label">Container</span>
</div>

<div class="metric">
<span class="value">{{ collector.countContainerCacheFiles() }}</span>
<span class="value" title="{{ collector.countServices()|number_format(0, '.', ',') }}">
{{ collector.countServices()|number_format(0, '.', ',') }}
</span>
<span class="label">Services</span>
</div>

<div class="metric">
<span class="value">{{ collector.countContainerCacheFiles()|number_format(0, '.', ',') }}</span>
<span class="label">Cache files</span>
</div>

Expand All @@ -92,29 +124,35 @@
<div class="sf-tabs">
<div class="tab">
<h3 class="tab-title">
Instantiated services
<span class="badge">{{ collector.countInstantiatedServices()|localizednumber }}</span>
Instantiated
<span class="badge">{{ collector.countInstantiatedServices()|number_format(0, '.', ',') }}</span>
</h3>

<p class="text-muted">
Note that only shared services are shown here,
Note that only shared (singleton) services are shown here,
we can't handle <a href="https://symfony.com/doc/current/service_container/shared.html" target="_blank">non shared service</a> creation.
</p>

<div class="tab-content">
<table class="table-striped">
<thead>
<tr>
<th>#</th>
<th>Service Id</th>
<th>Visibility</th>
<th>Service id</th>
<th>FQCN</th>
<th>Instantiation</th>
</tr>
</thead>
<tbody>
{% for serviceId, serviceInfos in collector.getInstantiatedServices() %}
<tr>
<td>{{ loop.index }}</td>
<td>
{% if serviceInfos.public %}
<span class="label visibility-public">Public</span>
{% else %}
<span class="label visibility-private">Private</span>
{% endif %}
</td>
<td>
{{ serviceId }}

Expand Down Expand Up @@ -166,13 +204,7 @@
<i>Unknown value</i>
{% endif %}
</td>
<td>
{% if serviceInfos.ocramiusLazy %}
<span class="label status-warning">Ocramius Lazy</span>
{% else %}
<span class="label status-success">Normal</span>
{% endif %}
</td>
<td>{{ self.serviceInstantiation(serviceInfos) }}</td>
</tr>
{% endfor %}
</tbody>
Expand All @@ -182,48 +214,24 @@

<div class="tab">
<h3 class="tab-title">
Registered services
<span class="badge">{{ collector.countRegisteredServices()|localizednumber }}</span>
Removed
<span class="badge">{{ collector.countRemovedServices()|number_format(0, '.', ',') }}</span>
</h3>

<div class="tab-content">
<table>
<thead>
<tr>
<th>#</th>
<th>Service ID</th>
</tr>
</thead>
<tbody>
{% for service in collector.getRegisteredServices() %}
<tr>
<td>{{ loop.index }}</td>
<td>{{ service }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>

<div class="tab">
<h3 class="tab-title">
Public services
<span class="badge">{{ collector.countPublicServices()|localizednumber }}</span>
</h3>
<p class="text-muted">
Some privates, all inlined and all tagged services are removed from Container.
</p>

<div class="tab-content">
<table>
<thead>
<tr>
<th>#</th>
<th>Service ID</th>
<th>Service id</th>
</tr>
</thead>
<tbody>
{% for service in collector.getPublicServices() %}
<tbody>
{% for service in collector.getRemovedServices() %}
<tr>
<td>{{ loop.index }}</td>
<td>{{ service }}</td>
</tr>
{% endfor %}
Expand All @@ -234,23 +242,23 @@

<div class="tab">
<h3 class="tab-title">
Private services
<span class="badge">{{ collector.countPrivateServices()|localizednumber }}</span>
Public
<span class="badge">{{ collector.countPublicServices()|number_format(0, '.', ',') }}</span>
</h3>

<div class="tab-content">
<table>
<thead>
<tr>
<th>#</th>
<th>Service ID</th>
<th>Service id</th>
<th>Instantiated</th>
</tr>
</thead>
<tbody>
{% for service in collector.getPrivateServices() %}
{% for service in collector.getPublicServices() %}
<tr>
<td>{{ loop.index }}</td>
<td>{{ service }}</td>
<td>{{ self.serviceInstantiation(collector.getInstantiatedInfos(service)) }}</td>
</tr>
{% endfor %}
</tbody>
Expand All @@ -261,22 +269,22 @@
<div class="tab">
<h3 class="tab-title">
Parameters
<span class="badge">{{ collector.countParameters()|localizednumber }}</span>
<span class="badge">{{ collector.countParameters()|number_format(0, '.', ',') }}</span>
</h3>

<div class="tab-content">
<table>
<thead>
<tr>
<th>#</th>
<th>Parameter name</th>
<th>Name</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<tbody>
{% for parameterName, parameterValue in collector.getParameters() %}
<tr>
<td>{{ loop.index }}</td>
<td>{{ parameterName }}</td>
<td>{{ collector.dumpParameterValue(parameterValue) }}</td>
</tr>
{% endfor %}
</tbody>
Expand Down
Loading

0 comments on commit 68ff160

Please sign in to comment.