7
7
class Elementv1 extends Element
8
8
{
9
9
/** @var string[] */
10
- protected array $ sources = [];
10
+ protected array $ id = [];
11
11
protected string $ type ;
12
12
13
13
/** @var bool Include element with HTML tags */
14
14
protected bool $ tag ;
15
15
16
-
17
- public function __construct (string $ pageid , string $ fullmatch , string $ type , string $ options )
16
+ public function __construct (string $ pageid , string $ type )
18
17
{
18
+ $ this ->id = [$ pageid ]; // default source is current page
19
19
$ this ->tag = Config::htmltag ();
20
20
$ this ->urllinker = Config::urllinker ();
21
- $ this ->fullmatch = $ fullmatch ;
22
- $ type = strtolower ($ type );
21
+ $ type = strtolower ($ type );
23
22
if (in_array ($ type , Pagev1::HTML_ELEMENTS )) {
24
23
$ this ->type = $ type ;
25
24
} else {
26
- throw new DomainException ("$ type is not a valid Page HTML Element Type " );
27
- }
28
- $ this ->options = $ options ;
29
- $ this ->analyse ($ pageid );
30
- }
31
-
32
- protected function analyse (string $ pageid ): void
33
- {
34
- if (!empty ($ this ->options )) {
35
- $ this ->options = str_replace ('* ' , $ pageid , $ this ->options );
36
- parse_str ($ this ->options , $ datas );
37
- if (isset ($ datas ['id ' ])) {
38
- $ this ->sources = explode (' ' , $ datas ['id ' ]);
39
- } else {
40
- $ this ->sources = [$ pageid ];
41
- }
42
- $ this ->hydrate ($ datas );
43
- } else {
44
- $ this ->sources = [$ pageid ];
25
+ throw new DomainException ("invalid element type inclusion: $ type " );
45
26
}
46
27
}
47
28
@@ -51,9 +32,9 @@ protected function analyse(string $pageid): void
51
32
/**
52
33
* @return string[]
53
34
*/
54
- public function sources (): array
35
+ public function id (): array
55
36
{
56
- return $ this ->sources ;
37
+ return $ this ->id ;
57
38
}
58
39
59
40
public function type (): string
@@ -66,6 +47,20 @@ public function tag(): bool
66
47
return $ this ->tag ;
67
48
}
68
49
50
+ // ______________________________________________ S E T ________________________________________________________
51
+
52
+ /**
53
+ * @param string[]|string $sources if provided as string, multiple IDs may be space separated
54
+ */
55
+ public function setid ($ sources ): void
56
+ {
57
+ if (is_string ($ sources )) {
58
+ $ this ->id = explode (' ' , $ sources );
59
+ } elseif (is_array ($ sources )) {
60
+ $ this ->id = $ sources ;
61
+ }
62
+ }
63
+
69
64
public function settag (bool $ tag ): void
70
65
{
71
66
$ this ->tag = $ tag ;
0 commit comments