11
11
use Michelf \MarkdownExtra ;
12
12
use PHPDraft \Model \StructureElement ;
13
13
14
- class EnumStructureElement implements StructureElement
14
+ class EnumStructureElement extends ObjectStructureElement implements StructureElement
15
15
{
16
16
/**
17
- * Object description
17
+ * Parse an array object
18
18
*
19
- * @var string
20
- */
21
- public $ description ;
22
- /**
23
- * Type of element
24
- *
25
- * @var string
26
- */
27
- public $ element = NULL ;
28
- /**
29
- * Object value
19
+ * @param \stdClass $object APIb Item to parse
20
+ * @param array $dependencies List of dependencies build
30
21
*
31
- * @var mixed
22
+ * @return $this
32
23
*/
33
- public $ value = NULL ;
34
- /**
35
- * /**
36
- * List of object dependencies
37
- *
38
- * @var string[]
39
- */
40
- public $ deps ;
41
-
42
- /**
43
- * Parse a JSON object to a structure
44
- *
45
- * @param \stdClass $object An object to parse
46
- * @param array $dependencies Dependencies of this object
47
- *
48
- * @return EnumStructureElement self reference
49
- */
50
- function parse ($ object , &$ dependencies )
24
+ public function parse ($ object , &$ dependencies )
51
25
{
52
- $ this ->element = (isset ($ object ->element )) ? $ object ->element : NULL ;
53
- $ this ->description = (isset ($ object ->meta ->description )) ? htmlentities ($ object ->meta ->description ) : NULL ;
54
- if (isset ($ object ->content ) && is_array ($ object ->content ))
26
+ $ this ->element = (isset ($ object ->element )) ? $ object ->element : 'array ' ;
27
+
28
+ $ this ->parse_common ($ object , $ dependencies );
29
+
30
+ if (!isset ($ object ->content ->value ->content ))
31
+ {
32
+ $ this ->value = [];
33
+ return $ this ;
34
+ }
35
+
36
+ foreach ($ object ->content ->value ->content as $ sub_item )
55
37
{
56
- $ deps = [];
57
- foreach ($ object ->content as $ value ) {
58
- $ element = new EnumStructureElement ();
59
- $ this ->value [] = $ element ->parse ($ value , $ deps );
38
+ if (!in_array ($ sub_item ->element , self ::DEFAULTS ))
39
+ {
40
+ $ dependencies [] = $ sub_item ->element ;
60
41
}
61
42
62
- $ this ->element = $ this ->element . '( ' . $ deps [0 ] . ') ' ;
63
- } else {
64
- $ this ->value = (isset ($ object ->content )) ? $ object ->content : NULL ;
43
+ $ this ->value [$ sub_item ->content ] = (isset ($ sub_item ->element )) ? $ sub_item ->element : '' ;
65
44
}
66
45
67
- $ this ->description_as_html ();
68
-
69
- $ dependencies [] = $ this ->element ;
46
+ $ this ->deps = $ dependencies ;
70
47
71
48
return $ this ;
72
49
}
73
50
74
51
/**
75
- * Parse the description to HTML
76
- *
77
- * @return void
78
- */
79
- public function description_as_html ()
80
- {
81
- $ this ->description = MarkdownExtra::defaultTransform ($ this ->description );
82
- }
83
-
84
- /**
85
- * Print a string representation
52
+ * Provide HTML representation
86
53
*
87
54
* @return string
88
55
*/
89
56
function __toString ()
90
57
{
91
- if (is_array ($ this ->value ))
92
- {
93
- $ return = '<ul class="list-group"> ' ;
94
- foreach ($ this ->value as $ item ) {
95
- $ return .= '<li class="list-group-item"> ' . $ item ->simple_string () . '</li> ' ;
96
- }
97
-
98
- $ return .= '</ul> ' ;
58
+ $ return = '<ul class="list-group"> ' ;
99
59
100
- return $ return ;
60
+ if (!is_array ($ this ->value ))
61
+ {
62
+ return '<span class="example-value pull-right">//list of options</span> ' ;
101
63
}
102
64
103
- $ type = (!in_array ($ this ->element , self ::DEFAULTS )) ?
104
- '<a class="code" href="#object- ' . str_replace (' ' , '- ' ,
105
- strtolower ($ this ->element )) . '"> ' . $ this ->element . '</a> ' : '<code> ' . $ this ->element . '</code> ' ;
106
- $ return = '<tr> ' .
107
- '<td><span> ' . $ this ->value . '</span></td> ' .
108
- '<td> ' . $ type . '</td> ' .
109
- '<td> ' . $ this ->description . '</td> ' .
110
- '</tr> ' ;
111
-
112
- return $ return ;
113
- }
114
-
115
- function simple_string ()
116
- {
117
- $ return = '<span> ' . $ this ->value . "</span> " ;
65
+ foreach ($ this ->value as $ key =>$ item ) {
66
+ $ type = (in_array ($ item , self ::DEFAULTS )) ? $ key : '<a href="#object- ' . str_replace (' ' , '- ' ,
67
+ strtolower ($ item )) . '"> ' . $ key . '</a> ' ;
118
68
119
- if (!empty ($ this ->description )) {
120
- $ return .= ' - ' . $ this ->description ;
69
+ $ return .= '<li class="list-group-item"> ' . $ type . '</li> ' ;
121
70
}
122
71
72
+ $ return .= '</ul> ' ;
123
73
124
74
return $ return ;
125
75
}
126
-
127
- function strval ()
128
- {
129
- if (is_array ($ this ->value )) {
130
- $ key = rand (0 , count ($ this ->value ));
131
- if (is_subclass_of ($ this ->value [$ key ], StructureElement::class)) {
132
- return $ this ->value [$ key ]->strval ();
133
- }
134
-
135
- return $ this ->value [$ key ];
136
- }
137
-
138
- return $ this ->value ;
139
- }
140
76
}
0 commit comments