1010
1111use PHPDraft \Model \Elements \ArrayStructureElement ;
1212
13- class DataStructureElement
13+ class DataStructureElement implements StructureElement
1414{
15- /**
16- * Default datatypes
17- * @var array
18- */
19- const DEFAULTS = ['boolean ' , 'string ' , 'number ' , 'object ' , 'array ' ];
15+
2016 /**
2117 * Object key
2218 * @var string
@@ -68,17 +64,26 @@ public function parse($object, &$dependencies)
6864 return $ this ;
6965 }
7066 $ this ->element = $ object ->element ;
67+
7168 if (isset ($ object ->content ) && is_array ($ object ->content ))
7269 {
7370 foreach ($ object ->content as $ value )
7471 {
75- $ struct = new DataStructureElement ();
72+ if (in_array ($ this ->element , ['object ' , 'dataStructure ' ]))
73+ {
74+ $ struct = new DataStructureElement ();
75+ }
76+ else
77+ {
78+ $ struct = new EnumStructureElement ();
79+ }
7680 $ this ->value [] = $ struct ->parse ($ value , $ dependencies );
7781 }
7882
7983 return $ this ;
8084 }
8185
86+
8287 $ this ->key = $ object ->content ->key ->content ;
8388 $ this ->type = $ object ->content ->value ->element ;
8489 $ this ->description = isset ($ object ->meta ->description ) ? $ object ->meta ->description : NULL ;
@@ -90,13 +95,17 @@ public function parse($object, &$dependencies)
9095 $ dependencies [] = $ this ->type ;
9196 }
9297
93- if ($ this ->type === 'object ' || $ this ->type === 'array ' )
98+ if ($ this ->type === 'object ' || $ this ->type === 'array ' || $ this -> type === ' enum ' || ! in_array ( $ this -> type , self :: DEFAULTS ) )
9499 {
95100 $ value = isset ($ object ->content ->value ->content ) ? $ object ->content ->value : NULL ;
96101 if ($ this ->type === 'array ' )
97102 {
98103 $ this ->value = new ArrayStructureElement ();
99104 }
105+ elseif ($ this ->type === 'enum ' )
106+ {
107+ $ this ->value = new EnumStructureElement ();
108+ }
100109 else
101110 {
102111 $ this ->value = new DataStructureElement ();
@@ -128,7 +137,15 @@ function __toString()
128137 $ return = '<table class="table table-striped"> ' ;
129138 foreach ($ this ->value as $ object )
130139 {
131- if (is_string ($ object ) || get_class ($ object ) === self ::class || get_class ($ object ) === ArrayStructureElement::class)
140+ if (get_class ($ object ) === \stdClass::class)
141+ {
142+ return json_encode ($ object );
143+ }
144+ if (is_string ($ object )
145+ || get_class ($ object ) === self ::class
146+ || get_class ($ object ) === ArrayStructureElement::class
147+ || get_class ($ object ) === EnumStructureElement::class
148+ )
132149 {
133150 $ return .= $ object ;
134151 }
@@ -156,6 +173,10 @@ function __toString()
156173 {
157174 $ value = '<div class="array-struct"> ' . $ this ->value . '</div> ' ;
158175 }
176+ elseif (is_array ($ this ->value ) && (EnumStructureElement::class === get_class ($ this ->value [0 ])))
177+ {
178+ $ value = '<div class="enum-struct"> ' . $ this ->value . '</div> ' ;
179+ }
159180 else
160181 {
161182 $ value = '<span class="example-value pull-right"> ' . $ this ->value . '</span> ' ;
0 commit comments