@@ -24,25 +24,33 @@ trait IsElement
2424
2525 public function getAttributes (): array
2626 {
27- return $ this ->attributes ;
27+ if ($ this instanceof WrapsElement) {
28+ $ wrappingAttributes = $ this ->getWrappingElement ()->getAttributes ();
29+ } else {
30+ $ wrappingAttributes = [];
31+ }
32+
33+ return [...$ this ->attributes , ...$ wrappingAttributes ];
2834 }
2935
3036 public function hasAttribute (string $ name ): bool
3137 {
3238 $ name = ltrim ($ name , ': ' );
3339
34- return array_key_exists (": {$ name }" , $ this ->attributes ) || array_key_exists ($ name , $ this ->attributes );
40+ $ attributes = $ this ->getAttributes ();
41+
42+ return array_key_exists (": {$ name }" , $ attributes ) || array_key_exists ($ name , $ attributes );
3543 }
3644
3745 public function getAttribute (string $ name ): ?string
3846 {
39- $ name = ltrim ( $ name , ' : ' );
47+ $ attributes = $ this -> getAttributes ( );
4048
41- if ($ this instanceof WrapsElement) {
42- $ value = $ this ->getWrappingElement ()->getAttribute ($ name );
43- }
49+ $ originalName = $ name ;
4450
45- return $ value ?? $ this ->attributes [": {$ name }" ] ?? $ this ->attributes [$ name ] ?? null ;
51+ $ name = ltrim ($ name , ': ' );
52+
53+ return $ attributes [$ originalName ] ?? $ this ->attributes [": {$ name }" ] ?? $ this ->attributes [$ name ] ?? null ;
4654 }
4755
4856 public function setAttribute (string $ name , string $ value ): self
@@ -51,8 +59,6 @@ public function setAttribute(string $name, string $value): self
5159 $ this ->getWrappingElement ()->setAttribute ($ name , $ value );
5260 }
5361
54- $ this ->unsetAttribute ($ name );
55-
5662 $ this ->attributes [$ name ] = $ value ;
5763
5864 return $ this ;
@@ -69,9 +75,11 @@ public function consumeAttribute(string $name): ?string
6975
7076 public function unsetAttribute (string $ name ): self
7177 {
72- $ name = ltrim ($ name , ': ' );
78+ if ($ this instanceof WrapsElement) {
79+ $ this ->getWrappingElement ()->unsetAttribute ($ name );
80+ }
7381
74- unset($ this ->attributes [$ name ], $ this -> attributes [ " : { $ name }" ] );
82+ unset($ this ->attributes [$ name ]);
7583
7684 return $ this ;
7785 }
0 commit comments