Skip to content

Commit 6a3ce13

Browse files
committed
Update README
Changed: - Improved description of `attr` parameter.
1 parent fe2fd70 commit 6a3ce13

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

README.md

+19-8
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,25 @@ Generate a string of HTML attributes from the associative array provided.
1919
If `attr` is a non-iterable object, then only accessible non-static properties
2020
will be incorporated into the result.
2121

22-
If a value of `attr` is an array, its values will be concatenated and
23-
delimited with a space.
22+
If an attribute name is an empty string, the attribute is ignored.
23+
The attribute name will be trimmed of leading/trailing whitespace.
2424

25-
If a value of `attr` is a boolean, the value's key will be rendered without
26-
a value.
27-
28-
If the value is Stringable, Arrayble, or a [`Closure`][class.closure],
29-
attempts will be made to parse as a string.
25+
If an attribute value is callable (either as a [`Closure`][class.closure] or
26+
invokable), it is called and the returned value continues processing.
27+
28+
If an attribute value is `null`, the attribute is ignored.
29+
30+
If an attribute value is an arrayable or a stringable object, it is converted
31+
to its primitive type.
32+
33+
If an attribute value is a boolean and `true`, the attribute will be rendered
34+
without a value, otherwise the attribute is ignored.
35+
36+
If an attribute value is an array, only numbers and strings are accepted.
37+
Strings of the array will be trimmed of leading/trailing whitespace.
38+
If the filtered array is empty, the attribute is ignored.
3039

31-
Values that cannot be converted into strings will be ignored.
40+
Any other value will be serialized using [`json_encode()`][function.json_encode].
3241

3342
- `callback` — Callback function for escaping the values for the HTML attributes.
3443

@@ -57,4 +66,6 @@ into your project path somewhere.
5766

5867
[class.closure]: https://php.net/class.closure
5968
[function.htmlspecialchars]: https://php.net/function.htmlspecialchars
69+
[function.json_encode]: https://php.net/function.json_encode
70+
[object.invoke]: https://php.net/oop5.magic#object.invoke
6071
[wp.esc_attr]: https://developer.wordpress.org/reference/functions/esc_attr/

0 commit comments

Comments
 (0)