File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,11 @@ class Document implements Stringable
1919 */
2020 private array $ body = [];
2121
22+ /**
23+ * @var array<string>
24+ */
25+ private array $ bodyProps = [];
26+
2227 public static function create (
2328 string |Stringable $ title ,
2429 string $ lang = 'en ' ,
@@ -46,6 +51,12 @@ public function body(string|Stringable ...$content): Document
4651 return $ this ;
4752 }
4853
54+ public function bodyProps (string ...$ props ): Document
55+ {
56+ $ this ->bodyProps = $ props ;
57+ return $ this ;
58+ }
59+
4960 public function __toString (): string
5061 {
5162 $ pageTitle = $ this ->title ();
@@ -63,7 +74,7 @@ public function __toString(): string
6374 Element::meta ()->omitEndTag ()->props ($ this ->charset ()),
6475 ...$ this ->headContent ()
6576 ),
66- Element::body (...$ this ->bodyContent ())
77+ Element::body (...$ this ->bodyContent ())-> props (... $ this -> bodyProps )
6778 )->props ($ this ->lang ());
6879 return $ doctype . $ html ;
6980 }
Original file line number Diff line number Diff line change 1313
1414class DocumentBaselineTest extends TestCase
1515{
16+ /**
17+ * @test
18+ */
19+ public function can_add_properties_to_body_element (): void // phpcs:ignore
20+ {
21+ $ expected = <<<html
22+ <!doctype html>
23+ <html lang="en"><head><title>Second | First</title><meta charset="utf-8"></head><body id="hello" class="world" style="color: #000;"></body></html>
24+ html ;
25+
26+ $ result = (string ) Document::create (
27+ PageTitle::create (['Second ' , 'First ' ])
28+ )->bodyProps ('style color: #000; ' , 'class world ' , 'id hello ' );
29+
30+ $ this ->assertSame (
31+ $ expected ,
32+ $ result
33+ );
34+ }
35+
1636 /**
1737 * @test
1838 */
You can’t perform that action at this time.
0 commit comments