11<?php
22/**
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<sean@seanmolenaar.eu>
77 */
88
99namespace PHPDraft \Model \Elements ;
1010
1111use PHPDraft \Model \StructureElement ;
1212
13- class ArrayStructureElement extends DataStructureElement implements StructureElement
13+ /**
14+ * Class ArrayStructureElement
15+ */
16+ class ArrayStructureElement extends ObjectStructureElement implements StructureElement
1417{
1518
1619 /**
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
1824 *
19- * @var
25+ * @return $this
2026 */
21- public $ type_of ;
22-
23- public function parse ($ item , &$ dependencies )
27+ public function parse ($ object , &$ dependencies )
2428 {
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 ;
4844 }
45+
46+ $ this ->value [] = (isset ($ sub_item ->element )) ? $ sub_item ->element : '' ;
4947 }
5048
49+ $ this ->deps = $ dependencies ;
50+
5151 return $ this ;
5252 }
5353
54+ /**
55+ * Provide HTML representation
56+ *
57+ * @return string
58+ */
5459 function __toString ()
5560 {
56- if (!is_array ($ this ->type )) {
57- return '' ;
58- }
5961 $ 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> ' ;
6462
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> ' ;
6771
68- $ return .= '<li class="list-group-item"> ' . $ type . $ value . '</li> ' ;
72+ $ return .= '<li class="list-group-item"> ' . $ type . '</li> ' ;
6973 }
74+
7075 $ return .= '</ul> ' ;
7176
7277 return $ return ;
7378 }
7479
75-
7680}
0 commit comments