Skip to content

Commit c149267

Browse files
committed
Fix when service is not an object
1 parent c2431d0 commit c149267

File tree

4 files changed

+55
-24
lines changed

4 files changed

+55
-24
lines changed

Bridge/ContainerIntrospectionBundle/Resources/views/DataCollector/container.html.twig

+20-7
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,16 @@
130130
<i class="text-small font-normal">No dependencies</i>
131131
{% endif %}
132132

133-
<a
134-
href="#"
135-
class="sf-toggle text-small font-normal link-inverse"
136-
data-toggle-selector="#container-introspection-fileName-{{ loop.index0 }}"
137-
data-toggle-alt-content="Hide file name"
138-
>View file name</a>
133+
{% if serviceInfos.fileName is not null %}
134+
<a
135+
href="#"
136+
class="sf-toggle text-small font-normal link-inverse"
137+
data-toggle-selector="#container-introspection-fileName-{{ loop.index0 }}"
138+
data-toggle-alt-content="Hide file name"
139+
>View file name</a>
140+
{% else %}
141+
<i class="text-small font-normal">No file name</i>
142+
{% endif %}
139143

140144
<div id="container-introspection-dependencies-{{ loop.index0 }}" class="sf-toggle-content hidden highlight">
141145
<ul>
@@ -152,7 +156,16 @@
152156
{{ serviceInfos.fileName }}
153157
</div>
154158
</td>
155-
<td>{{ serviceInfos.fqcn }}</td>
159+
<td>
160+
{% if serviceInfos.fqcn is not null %}
161+
{{ serviceInfos.fqcn }}
162+
{% elseif serviceInfos.value is not null %}
163+
<i>Not an object: </i>
164+
{{ serviceInfos.value|raw }}
165+
{% else %}
166+
<i>Unknown value</i>
167+
{% endif %}
168+
</td>
156169
<td>
157170
{% if serviceInfos.ocramiusLazy %}
158171
<span class="label status-warning">Ocramius Lazy</span>

ContainerIntrospectionService.php

+30-16
Original file line numberDiff line numberDiff line change
@@ -57,26 +57,40 @@ public function getInstantiatedServices(): array
5757
$return = [];
5858
foreach ($services as $id) {
5959
$service = $this->container->get($id);
60-
$ocramiusLazy = $service instanceof VirtualProxyInterface;
61-
$className = ($ocramiusLazy) ? get_parent_class($service) : get_class($service);
62-
63-
$reflection = new \ReflectionClass($className);
64-
$constructor = $reflection->getConstructor();
65-
$dependencies = [];
66-
if ($constructor instanceof \ReflectionMethod) {
67-
foreach ($constructor->getParameters() as $parameter) {
68-
$dependencies[] = [
69-
'type' => $parameter->getType() instanceof \ReflectionNamedType
70-
? $parameter->getType()->getName()
71-
: null,
72-
'name' => $parameter->getName()
73-
];
60+
61+
if (is_object($service)) {
62+
$ocramiusLazy = $service instanceof VirtualProxyInterface;
63+
$className = ($ocramiusLazy) ? get_parent_class($service) : get_class($service);
64+
65+
$reflection = new \ReflectionClass($className);
66+
$constructor = $reflection->getConstructor();
67+
$dependencies = [];
68+
if ($constructor instanceof \ReflectionMethod) {
69+
foreach ($constructor->getParameters() as $parameter) {
70+
$dependencies[] = [
71+
'type' => $parameter->getType() instanceof \ReflectionNamedType
72+
? $parameter->getType()->getName()
73+
: null,
74+
'name' => $parameter->getName()
75+
];
76+
}
7477
}
78+
79+
$value = null;
80+
$fqcn = $reflection->getName();
81+
$fileName = $reflection->getFileName();
82+
} else {
83+
$value = var_export($service, true);
84+
$fqcn = null;
85+
$fileName = null;
86+
$dependencies = [];
87+
$ocramiusLazy = false;
7588
}
7689

7790
$return[$id] = [
78-
'fqcn' => $reflection->getName(),
79-
'fileName' => $reflection->getFileName(),
91+
'value' => $value,
92+
'fqcn' => $fqcn,
93+
'fileName' => $fileName,
8094
'dependencies' => $dependencies,
8195
'ocramiusLazy' => $ocramiusLazy
8296
];

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![version](https://img.shields.io/badge/version-1.0.0-green.svg)](https://github.com/steevanb/symfony-container-introspection/tree/1.0.0)
1+
[![version](https://img.shields.io/badge/version-1.0.1-green.svg)](https://github.com/steevanb/symfony-container-introspection/tree/1.0.1)
22
[![php](https://img.shields.io/badge/php-^7.1-blue.svg)](https://php.net)
33
[![symfony](https://img.shields.io/badge/symfony/dependency--injection-^3.4||^4.0-blue.svg)](https://symfony.com)
44
![Lines](https://img.shields.io/badge/code%20lines-734-green.svg)

changelog.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### [1.0.1](../../../compare/1.0.0...1.0.1) - 2018-06-06
2+
3+
- Fix when service is not an object
4+
15
### 1.0.0 - 2018-06-06
26

37
- Get registered services: `ContainerIntrospectionService::getRegisteredServices()`

0 commit comments

Comments
 (0)