From 902b2f74a6caca9ddc441c03c238ce65d314d25d Mon Sep 17 00:00:00 2001 From: Josh Bruce <15252830+joshbruce@users.noreply.github.com> Date: Sat, 10 Dec 2022 22:59:42 -0500 Subject: [PATCH] BC: XML Builder deprecated interfaces and implementations --- composer.json | 2 +- composer.lock | 14 +++++++------- src/Components/Copyright.php | 8 ++------ src/Components/Favicons.php | 8 ++------ src/Document.php | 12 ++++-------- tests/DocumentBaselineTest.php | 17 +++++++---------- tests/ElementBaselineTest.php | 7 +++---- tests/ElementExtensionBaselineTest.php | 5 ++--- 8 files changed, 28 insertions(+), 45 deletions(-) diff --git a/composer.json b/composer.json index 9de95b6..18e394e 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ ], "require": { "php": "^8.1", - "8fold/php-xml-builder": "^1.0" + "8fold/php-xml-builder": "^2.0" }, "require-dev": { "phpstan/phpstan": "^1.2", diff --git a/composer.lock b/composer.lock index 25f7820..bf788ea 100644 --- a/composer.lock +++ b/composer.lock @@ -4,20 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c947d8e6a9d83a5901fde433b192b1d2", + "content-hash": "dc6343ad7a810126408d6ead837d1274", "packages": [ { "name": "8fold/php-xml-builder", - "version": "1.4.0", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/8fold/php-xml-builder.git", - "reference": "69800b791a2b331f603a1680a33f8a082a44309f" + "reference": "a1feffe8d91e3ed3bf532c9b2ba13c5a8c2abfcb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/8fold/php-xml-builder/zipball/69800b791a2b331f603a1680a33f8a082a44309f", - "reference": "69800b791a2b331f603a1680a33f8a082a44309f", + "url": "https://api.github.com/repos/8fold/php-xml-builder/zipball/a1feffe8d91e3ed3bf532c9b2ba13c5a8c2abfcb", + "reference": "a1feffe8d91e3ed3bf532c9b2ba13c5a8c2abfcb", "shasum": "" }, "require": { @@ -47,7 +47,7 @@ "description": "A library for building XML document and element strings.", "support": { "issues": "https://github.com/8fold/php-xml-builder/issues", - "source": "https://github.com/8fold/php-xml-builder/tree/1.4.0" + "source": "https://github.com/8fold/php-xml-builder/tree/2.0.0" }, "funding": [ { @@ -59,7 +59,7 @@ "type": "github" } ], - "time": "2022-12-05T00:11:28+00:00" + "time": "2022-12-11T03:40:44+00:00" } ], "packages-dev": [ diff --git a/src/Components/Copyright.php b/src/Components/Copyright.php index 55f38a1..985c8ac 100644 --- a/src/Components/Copyright.php +++ b/src/Components/Copyright.php @@ -3,16 +3,12 @@ namespace Eightfold\HTMLBuilder\Components; -use Eightfold\XMLBuilder\Contracts\Buildable; - -use Eightfold\XMLBuilder\Implementations\Buildable as BuildableImp; +use Stringable; use Eightfold\HTMLBuilder\Element; -class Copyright implements Buildable +class Copyright implements Stringable { - use BuildableImp; - private bool $useCopyrightSymbol = true; private bool $spellOutCopyright = false; diff --git a/src/Components/Favicons.php b/src/Components/Favicons.php index b303da1..1ddefd6 100644 --- a/src/Components/Favicons.php +++ b/src/Components/Favicons.php @@ -3,12 +3,10 @@ namespace Eightfold\HTMLBuilder\Components; -use Eightfold\XMLBuilder\Contracts\Buildable; +use Stringable; use Eightfold\XMLBuilder\Concatenate; -use Eightfold\XMLBuilder\Implementations\Buildable as BuildableImp; - use Eightfold\HTMLBuilder\Element; use Eightfold\HTMLBuilder\Components\FaviconMetroColors; @@ -17,10 +15,8 @@ * We use https://realfavicongenerator.net to generate favicon-related assets. * We presume the names of these assets will not be changed. */ -class Favicons implements Buildable +class Favicons implements Stringable { - use BuildableImp; - private string $appName = ''; private bool $metroUsesWhite; diff --git a/src/Document.php b/src/Document.php index 7402b4d..c62201d 100644 --- a/src/Document.php +++ b/src/Document.php @@ -5,15 +5,10 @@ use Stringable; -use Eightfold\XMLBuilder\Contracts\Buildable; -use Eightfold\XMLBuilder\Implementations\Buildable as BuildableImp; - use Eightfold\HTMLBuilder\Element; -class Document implements Buildable +class Document implements Stringable { - use BuildableImp; - /** * @var array */ @@ -54,14 +49,15 @@ public function body(string|Stringable ...$content): Document public function __toString(): string { $doctype = '' . "\n"; - return $doctype . Element::html( + $html = (string) Element::html( Element::head( Element::title($this->title()), Element::meta()->omitEndTag()->props($this->charset()), ...$this->headContent() ), Element::body(...$this->bodyContent()) - )->props($this->lang())->build(); + )->props($this->lang()); + return $doctype . $html; } private function title(): string diff --git a/tests/DocumentBaselineTest.php b/tests/DocumentBaselineTest.php index b158544..ccb0d7e 100644 --- a/tests/DocumentBaselineTest.php +++ b/tests/DocumentBaselineTest.php @@ -21,8 +21,7 @@ public function is_stringable(): void // phpcs:ignore title

paragraph content

html; - $result = (string) Document::create('title', 'fr', 'ascii') - ->head( + $result = (string) Document::create('title', 'fr', 'ascii')->head( Element::link() ->omitEndTag()->props('rel stylesheet', 'href style.css'), Element::script()->props('src script.js') @@ -43,14 +42,13 @@ public function can_have_body(): void // phpcs:ignore title

paragraph content

html; - $result = Document::create('title', 'fr', 'ascii') - ->head( + $result = (string) Document::create('title', 'fr', 'ascii')->head( Element::link() ->omitEndTag()->props('rel stylesheet', 'href style.css'), Element::script()->props('src script.js') )->body( Element::p('paragraph content') - )->build(); + ); $this->assertSame($expected, $result); } @@ -65,12 +63,11 @@ public function can_have_head(): void // phpcs:ignore title html; - $result = Document::create('title', 'fr', 'ascii') - ->head( + $result = (string) Document::create('title', 'fr', 'ascii')->head( Element::link() ->omitEndTag()->props('rel stylesheet', 'href style.css'), Element::script()->props('src script.js') - )->build(); + ); $this->assertSame($expected, $result); } @@ -85,7 +82,7 @@ public function can_change_lang_and_char_set(): void // phpcs:ignore title html; - $result = Document::create('title', 'fr', 'ascii')->build(); + $result = (string) Document::create('title', 'fr', 'ascii'); $this->assertSame($expected, $result); } @@ -100,7 +97,7 @@ public function has_baseline(): void // phpcs:ignore title html; - $result = Document::create('title')->build(); + $result = (string) Document::create('title'); $this->assertSame($expected, $result); } diff --git a/tests/ElementBaselineTest.php b/tests/ElementBaselineTest.php index 31c7455..57964b0 100644 --- a/tests/ElementBaselineTest.php +++ b/tests/ElementBaselineTest.php @@ -32,14 +32,13 @@ public function has_ordered_properties(): void // phpcs:ignore link html; - $result = Element::a('link') - ->props( + $result = (string) Element::a('link')->props( 'required required', 'href https://8fold.pro', 'class some-style', 'id unique', 'data-testing test' - )->build(); + ); $this->assertSame($expected, $result); } @@ -53,7 +52,7 @@ public function has_correct_selfclosing_string(): void // phpcs:ignore html; - $result = Element::tag()->omitEndTag()->build(); + $result = (string) Element::tag()->omitEndTag(); $this->assertSame($expected, $result); } diff --git a/tests/ElementExtensionBaselineTest.php b/tests/ElementExtensionBaselineTest.php index d95b283..ebb084b 100644 --- a/tests/ElementExtensionBaselineTest.php +++ b/tests/ElementExtensionBaselineTest.php @@ -18,14 +18,13 @@ public function has_ordered_properties(): void // phpcs:ignore link html; - $result = ElementExtension::a('link') - ->props( + $result = (string) ElementExtension::a('link')->props( 'required required', 'href https://8fold.pro', 'class some-style', 'id unique', 'data-testing test' - )->build(); + ); $this->assertSame($exptected, $result); }