@@ -37,8 +37,6 @@ function html_build_attributes($attr, callable $callback = null)
37
37
if (is_object ($ val )) {
38
38
if ($ val instanceof Closure) {
39
39
$ val = $ val ();
40
- } elseif ($ val instanceof JsonSerializable) {
41
- $ val = json_encode ($ val , (JSON_UNESCAPED_SLASHES |JSON_UNESCAPED_UNICODE ));
42
40
} elseif (is_callable ([ $ val , 'toArray ' ])) {
43
41
$ val = $ val ->toArray ();
44
42
} elseif (is_callable ([ $ val , '__toString ' ])) {
@@ -51,9 +49,7 @@ function html_build_attributes($attr, callable $callback = null)
51
49
$ html [] = $ key ;
52
50
}
53
51
continue ;
54
- }
55
-
56
- if (is_array ($ val )) {
52
+ } elseif (is_array ($ val )) {
57
53
$ val = implode (' ' , array_reduce ($ val , function ($ tokens , $ token ) {
58
54
if (is_string ($ token )) {
59
55
$ token = trim ($ token );
@@ -71,6 +67,8 @@ function html_build_attributes($attr, callable $callback = null)
71
67
if (strlen ($ val ) === 0 ) {
72
68
continue ;
73
69
}
70
+ } elseif (!is_string ($ val ) && !is_numeric ($ val )) {
71
+ $ val = json_encode ($ val , (JSON_UNESCAPED_SLASHES |JSON_UNESCAPED_UNICODE ));
74
72
}
75
73
76
74
if (is_callable ($ callback )) {
@@ -81,10 +79,7 @@ function html_build_attributes($attr, callable $callback = null)
81
79
$ val = htmlspecialchars ($ val , ENT_QUOTES );
82
80
}
83
81
84
- if (is_string ($ val ) || is_numeric ($ val )) {
85
- $ html [] = sprintf ('%1$s="%2$s" ' , $ key , $ val );
86
- continue ;
87
- }
82
+ $ html [] = sprintf ('%1$s="%2$s" ' , $ key , $ val );
88
83
}
89
84
90
85
return implode (' ' , $ html );
0 commit comments