1010
1111namespace Sidus \EAVModelBundle \Profiler ;
1212
13+ use Sidus \EAVModelBundle \Model \AttributeInterface ;
14+ use Sidus \EAVModelBundle \Model \AttributeTypeInterface ;
15+ use Sidus \EAVModelBundle \Model \FamilyInterface ;
1316use Sidus \EAVModelBundle \Registry \AttributeTypeRegistry ;
1417use Sidus \EAVModelBundle \Registry \FamilyRegistry ;
1518use Symfony \Component \HttpFoundation \Request ;
1619use Symfony \Component \HttpFoundation \Response ;
1720use Symfony \Component \HttpKernel \DataCollector \DataCollector ;
18- use Symfony \Component \VarDumper \Cloner \Data ;
1921
2022/**
2123 * Display model configuration in the debug toolbar
2426 */
2527class 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}
0 commit comments