1
1
<?php
2
2
/**
3
- * Created by PhpStorm.
4
- * User: smillernl
5
- * Date: 2-9-16
6
- * Time: 15:21
3
+ * This file contains the ArrayStructureElement.php
4
+ *
5
+ * @package PHPDraft\Model\Elements
6
+ * @author Sean Molenaar<[email protected] >
7
7
*/
8
8
9
9
namespace PHPDraft \Model \Elements ;
10
10
11
11
use PHPDraft \Model \StructureElement ;
12
12
13
- class ArrayStructureElement extends DataStructureElement implements StructureElement
13
+ /**
14
+ * Class ArrayStructureElement
15
+ */
16
+ class ArrayStructureElement extends ObjectStructureElement implements StructureElement
14
17
{
15
18
16
19
/**
17
- * Type of objects in the array
20
+ * Parse an array object
21
+ *
22
+ * @param \stdClass $object APIb Item to parse
23
+ * @param array $dependencies List of dependencies build
18
24
*
19
- * @var
25
+ * @return $this
20
26
*/
21
- public $ type_of ;
22
-
23
- public function parse ($ item , &$ dependencies )
27
+ public function parse ($ object , &$ dependencies )
24
28
{
25
- $ this ->element = (isset ($ item ->element )) ? $ item ->element : 'array ' ;
26
- $ this ->value = (isset ($ item ->content )) ? $ item ->content : null ;
27
-
28
- if (isset ($ item ->content )) {
29
- foreach ($ item ->content as $ key => $ sub_item ) {
30
- $ this ->type [$ key ] = $ sub_item ->element ;
31
- switch ($ sub_item ->element ) {
32
- case 'array ' :
33
- $ value = new ArrayStructureElement ();
34
- $ this ->value [$ key ] = $ value ->parse ($ sub_item , $ dependencies );
35
- break ;
36
- case 'object ' :
37
- $ value = new DataStructureElement ();
38
- $ this ->value [$ key ] = $ value ->parse ($ sub_item , $ dependencies );
39
- break ;
40
- case 'enum ' :
41
- $ value = new EnumStructureElement ();
42
- $ this ->value [$ key ] = $ value ->parse ($ sub_item , $ dependencies );
43
- break ;
44
- default :
45
- $ this ->value [$ key ] = (isset ($ sub_item ->content )) ? $ sub_item ->content : null ;
46
- break ;
47
- }
29
+ $ this ->element = (isset ($ object ->element )) ? $ object ->element : 'array ' ;
30
+
31
+ $ this ->parse_common ($ object , $ dependencies );
32
+
33
+ if (!isset ($ object ->content ->value ->content ))
34
+ {
35
+ $ this ->value = [];
36
+ return $ this ;
37
+ }
38
+
39
+ foreach ($ object ->content ->value ->content as $ sub_item )
40
+ {
41
+ if (!in_array ($ sub_item ->element , self ::DEFAULTS ))
42
+ {
43
+ $ dependencies [] = $ sub_item ->element ;
48
44
}
45
+
46
+ $ this ->value [] = (isset ($ sub_item ->element )) ? $ sub_item ->element : '' ;
49
47
}
50
48
49
+ $ this ->deps = $ dependencies ;
50
+
51
51
return $ this ;
52
52
}
53
53
54
+ /**
55
+ * Provide HTML representation
56
+ *
57
+ * @return string
58
+ */
54
59
function __toString ()
55
60
{
56
- if (!is_array ($ this ->type )) {
57
- return '' ;
58
- }
59
61
$ return = '<ul class="list-group"> ' ;
60
- foreach ($ this ->type as $ key => $ item ) {
61
- $ type =
62
- (in_array ($ item , self ::DEFAULTS )) ? $ item : '<a href="#object- ' . str_replace (' ' , '- ' ,
63
- strtolower ($ item )) . '"> ' . $ item . '</a> ' ;
64
62
65
- $ value =
66
- (isset ($ this ->value [$ key ])) ? ': <span class="example-value pull-right"> ' . json_encode ($ this ->value [$ key ]) . '</span> ' : null ;
63
+ if (!is_array ($ this ->value ))
64
+ {
65
+ return '<span class="example-value pull-right">[ ]</span> ' ;
66
+ }
67
+
68
+ foreach ($ this ->value as $ item ) {
69
+ $ type = (in_array ($ this ->value , self ::DEFAULTS )) ? $ item : '<a href="#object- ' . str_replace (' ' , '- ' ,
70
+ strtolower ($ item )) . '"> ' . $ item . '</a> ' ;
67
71
68
- $ return .= '<li class="list-group-item"> ' . $ type . $ value . '</li> ' ;
72
+ $ return .= '<li class="list-group-item"> ' . $ type . '</li> ' ;
69
73
}
74
+
70
75
$ return .= '</ul> ' ;
71
76
72
77
return $ return ;
73
78
}
74
79
75
-
76
80
}
0 commit comments