Skip to content

Commit 387baf6

Browse files
Fixing DataCollectors, removing serialization of FamilyRegistry and AttributeTypeRegistry and using arrays of scalar data instead.
1 parent 5ac49b6 commit 387baf6

File tree

4 files changed

+143
-31
lines changed

4 files changed

+143
-31
lines changed

Model/FamilyInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ interface FamilyInterface
2626
*/
2727
public function getCode();
2828

29+
/**
30+
* @return string
31+
*/
32+
public function getLabel();
33+
2934
/**
3035
* @return string
3136
*/

Profiler/DataLoaderCollector.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
<?php declare(strict_types=1);
1+
<?php
2+
/*
3+
* This file is part of the Sidus/EAVModelBundle package.
4+
*
5+
* Copyright (c) 2015-2019 Vincent Chalnot
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
210

311
namespace Sidus\EAVModelBundle\Profiler;
412

@@ -9,7 +17,9 @@
917
use Symfony\Component\VarDumper\Cloner\Data;
1018

1119
/**
12-
* @method reset()
20+
* Collect EAV Data loaded by the EAVDataLoader
21+
*
22+
* @author Vincent Chalnot <[email protected]>
1323
*/
1424
class DataLoaderCollector extends DataCollector
1525
{
@@ -53,6 +63,17 @@ public function collect(Request $request, Response $response, \Exception $except
5363
}
5464
}
5565

66+
/**
67+
* {@inheritdoc}
68+
*/
69+
public function reset()
70+
{
71+
$this->data = [
72+
'nodes' => [],
73+
'count' => null,
74+
];
75+
}
76+
5677
/**
5778
* @return int
5879
*/

Profiler/ModelConfigurationDataCollector.php

Lines changed: 103 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010

1111
namespace Sidus\EAVModelBundle\Profiler;
1212

13+
use Sidus\EAVModelBundle\Model\AttributeInterface;
14+
use Sidus\EAVModelBundle\Model\AttributeTypeInterface;
15+
use Sidus\EAVModelBundle\Model\FamilyInterface;
1316
use Sidus\EAVModelBundle\Registry\AttributeTypeRegistry;
1417
use Sidus\EAVModelBundle\Registry\FamilyRegistry;
1518
use Symfony\Component\HttpFoundation\Request;
1619
use Symfony\Component\HttpFoundation\Response;
1720
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
18-
use Symfony\Component\VarDumper\Cloner\Data;
1921

2022
/**
2123
* Display model configuration in the debug toolbar
@@ -24,16 +26,26 @@
2426
*/
2527
class ModelConfigurationDataCollector extends DataCollector
2628
{
29+
/** @var array[] */
30+
protected $data = [
31+
'families' => [],
32+
'attributeTypes' => [],
33+
];
34+
35+
/** @var FamilyRegistry */
36+
protected $familyRegistry;
37+
38+
/** @var AttributeTypeRegistry */
39+
protected $attributeTypeRegistry;
40+
2741
/**
2842
* @param FamilyRegistry $familyRegistry
2943
* @param AttributeTypeRegistry $attributeTypeRegistry
3044
*/
3145
public function __construct(FamilyRegistry $familyRegistry, AttributeTypeRegistry $attributeTypeRegistry)
3246
{
33-
$this->data = [
34-
'familyRegistry' => $familyRegistry,
35-
'attributeTypeRegistry' => $attributeTypeRegistry,
36-
];
47+
$this->familyRegistry = $familyRegistry;
48+
$this->attributeTypeRegistry = $attributeTypeRegistry;
3749
}
3850

3951
/**
@@ -45,29 +57,39 @@ public function __construct(FamilyRegistry $familyRegistry, AttributeTypeRegistr
4557
*/
4658
public function collect(Request $request, Response $response, \Exception $exception = null)
4759
{
60+
foreach ($this->familyRegistry->getFamilies() as $family) {
61+
$this->data['families'][$family->getCode()] = $this->parseFamily($family);
62+
}
63+
foreach ($this->attributeTypeRegistry->getTypes() as $attributeType) {
64+
$this->data['attributeTypes'][$attributeType->getCode()] = $this->parseAttributeType($attributeType);
65+
}
4866
}
4967

5068
/**
5169
* {@inheritdoc}
5270
*/
5371
public function reset()
5472
{
73+
$this->data = [
74+
'families' => [],
75+
'attributeTypes' => [],
76+
];
5577
}
5678

5779
/**
58-
* @return FamilyRegistry
80+
* @return array[]
5981
*/
60-
public function getFamilyRegistry()
82+
public function getFamilies()
6183
{
62-
return $this->data['familyRegistry'];
84+
return $this->data['families'];
6385
}
6486

6587
/**
66-
* @return AttributeTypeRegistry
88+
* @return array[]
6789
*/
68-
public function getAttributeTypeRegistry()
90+
public function getAttributeTypes()
6991
{
70-
return $this->data['attributeTypeRegistry'];
92+
return $this->data['attributeTypes'];
7193
}
7294

7395
/**
@@ -81,12 +103,78 @@ public function getName()
81103
}
82104

83105
/**
84-
* @param array $data
106+
* @param FamilyInterface|null $family
85107
*
86-
* @return Data|array
108+
* @return array|null
87109
*/
88-
public function wrapData(array $data)
110+
protected function parseFamily(FamilyInterface $family = null)
89111
{
90-
return $this->cloneVar($data);
112+
if (null === $family) {
113+
return null;
114+
}
115+
116+
return [
117+
'code' => $family->getCode(),
118+
'label' => $family->getLabel(),
119+
'instantiable' => $family->isInstantiable(),
120+
'singleton' => $family->isSingleton(),
121+
'parent' => $family->getParent() ? [
122+
'code' => $family->getParent()->getCode(),
123+
'label' => $family->getParent()->getLabel(),
124+
] : null,
125+
'dataClass' => $family->getDataClass(),
126+
'valueClass' => $family->getValueClass(),
127+
'attributeAsIdentifier' => $this->parseAttribute($family->getAttributeAsIdentifier()),
128+
'attributeAsLabel' => $this->parseAttribute($family->getAttributeAsLabel()),
129+
'attributes' => array_map([$this, 'parseAttribute'], $family->getAttributes()),
130+
'data_class' => $family->getDataClass(),
131+
];
132+
}
133+
134+
/**
135+
* @param AttributeInterface|null $attribute
136+
*
137+
* @return array|null
138+
*/
139+
protected function parseAttribute(AttributeInterface $attribute = null)
140+
{
141+
if (null === $attribute) {
142+
return null;
143+
}
144+
145+
return [
146+
'code' => $attribute->getCode(),
147+
'label' => $attribute->getLabel(),
148+
'group' => $attribute->getGroup(),
149+
'type' => $this->parseAttributeType($attribute->getType()),
150+
'required' => $attribute->isRequired(),
151+
'unique' => $attribute->isUnique(),
152+
'multiple' => $attribute->isMultiple(),
153+
'collection' => $attribute->isCollection(),
154+
'contextMask' => $attribute->getContextMask(),
155+
'validationRules' => $this->cloneVar($attribute->getValidationRules()),
156+
'options' => $this->cloneVar($attribute->getOptions()),
157+
'formOptions' => $this->cloneVar($attribute->getFormOptions()),
158+
];
159+
}
160+
161+
/**
162+
* @param AttributeTypeInterface|null $attributeType
163+
*
164+
* @return array|null
165+
*/
166+
protected function parseAttributeType(AttributeTypeInterface $attributeType = null)
167+
{
168+
if (null === $attributeType) {
169+
return null;
170+
}
171+
172+
return [
173+
'code' => $attributeType->getCode(),
174+
'relation' => $attributeType->isRelation(),
175+
'embedded' => $attributeType->isEmbedded(),
176+
'databaseType' => $attributeType->getDatabaseType(),
177+
'formType' => $attributeType->getFormType(),
178+
];
91179
}
92180
}

Resources/views/Profiler/sidus_eav_model.html.twig

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
{% set text %}
1111
<div class="sf-toolbar-info-piece">
1212
<b>Attribute types</b>
13-
<span class="sf-toolbar-status">{{ collector.attributeTypeRegistry.types|length }}</span>
13+
<span class="sf-toolbar-status">{{ collector.attributeTypes|length }}</span>
1414
</div>
1515
<div class="sf-toolbar-info-piece">
1616
<b>Families</b>
17-
<span class="sf-toolbar-status">{{ collector.familyRegistry.familyCodes|length }}</span>
17+
<span class="sf-toolbar-status">{{ collector.families|length }}</span>
1818
</div>
1919
{% endset %}
2020

@@ -61,7 +61,7 @@
6161
<div class="tab">
6262
<h3 class="tab-title">
6363
Families
64-
<span class="badge">{{ collector.familyRegistry.familyCodes|length }}</span>
64+
<span class="badge">{{ collector.families|length }}</span>
6565
</h3>
6666
<div class="tab-content">
6767
<table>
@@ -75,17 +75,17 @@
7575
</tr>
7676
</thead>
7777
<tbody>
78-
{% for family in collector.familyRegistry.families %}
78+
{% for family in collector.families %}
7979
{# @var family \Sidus\EAVModelBundle\Model\FamilyInterface #}
8080
<tr class="{{ not family.instantiable ? 'text-muted' }}">
8181
<td class="font-normal text-bold">
8282
<span class="colored text-bold">{{ family.code }}</span>
83-
<span class="text-muted newline">{{ family }}</span>
83+
<span class="text-muted newline">{{ family.label }}</span>
8484
</td>
8585
<td class="font-normal text-small" nowrap="">
8686
{% if family.parent %}
8787
<span class="colored text-bold">{{ family.parent.code }}</span>
88-
<span class="text-muted newline">{{ family.parent }}</span>
88+
<span class="text-muted newline">{{ family.parent.label }}</span>
8989
{% endif %}
9090
</td>
9191
<td class="font-normal text-small" nowrap="">
@@ -147,7 +147,7 @@
147147
<tr>
148148
<td class="font-normal text-bold">
149149
<span class="colored text-bold">{{ attribute.code }}</span>
150-
<span class="text-muted newline">{{ attribute }}</span>
150+
<span class="text-muted newline">{{ attribute.label }}</span>
151151
</td>
152152
<td class="font-normal text-small" nowrap="">
153153
{{ attribute.group }}
@@ -176,18 +176,16 @@
176176
<dd>{{ attribute.contextMask|join(', ') }}</dd>
177177
<dt>Validation Rules:</dt>
178178
<dd>
179-
{% for validationRule in attribute.validationRules %}
180-
{{ profiler_dump(collector.wrapData(validationRule), maxDepth=1) }}
181-
{% endfor %}
179+
{{ profiler_dump(attribute.validationRules, maxDepth=2) }}
182180
</dd>
183181
</dl>
184182
</td>
185183
<td class="font-normal text-small">
186184
<dl class="sidus-properties">
187185
<dt>Options:</dt>
188-
<dd>{{ profiler_dump(collector.wrapData(attribute.options), maxDepth=1) }}</dd>
186+
<dd>{{ profiler_dump(attribute.options, maxDepth=1) }}</dd>
189187
<dt>Form options:</dt>
190-
<dd>{{ profiler_dump(collector.wrapData(attribute.formOptions), maxDepth=1) }}</dd>
188+
<dd>{{ profiler_dump(attribute.formOptions, maxDepth=1) }}</dd>
191189
</dl>
192190
</td>
193191
</tr>
@@ -206,7 +204,7 @@
206204
<div class="tab">
207205
<h3 class="tab-title">
208206
Attribute Types
209-
<span class="badge">{{ collector.attributeTypeRegistry.types|length }}</span>
207+
<span class="badge">{{ collector.attributeTypes|length }}</span>
210208
</h3>
211209
<div class="tab-content">
212210
<table>
@@ -219,7 +217,7 @@
219217
</tr>
220218
</thead>
221219
<tbody>
222-
{% for attributeType in collector.attributeTypeRegistry.types %}
220+
{% for attributeType in collector.attributeTypes %}
223221
<tr>
224222
<td>{{ attributeType.code }}</td>
225223
<td>{{ attributeType.databaseType }}</td>

0 commit comments

Comments
 (0)