diff --git a/.github/workflows/php8.yml b/.github/workflows/php8.yml deleted file mode 100644 index cd55c28..0000000 --- a/.github/workflows/php8.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: PHP 8.0 - -on: - push: - branches: [main] - pull_request: - branches: [main] - -jobs: - build: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Setup PHP Action - uses: shivammathur/setup-php@2.15.0 - with: - php-version: '8.0' - - - name: Validate composer.json and composer.lock - run: composer validate - - - name: Install dependencies - run: composer install --prefer-dist --no-progress - - - name: Run style check - run: composer run style - - - name: Run static analyzer - run: composer run stan - - - name: Run tests - run: composer run test diff --git a/composer.json b/composer.json index 5ec7ecf..9de95b6 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ } ], "require": { - "php": "^8.0", + "php": "^8.1", "8fold/php-xml-builder": "^1.0" }, "require-dev": { diff --git a/composer.lock b/composer.lock index 150766d..25f7820 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "199aa517e28afc812147d2db276ef5b7", + "content-hash": "c947d8e6a9d83a5901fde433b192b1d2", "packages": [ { "name": "8fold/php-xml-builder", @@ -1915,7 +1915,7 @@ "prefer-stable": true, "prefer-lowest": false, "platform": { - "php": "^8.0" + "php": "^8.1" }, "platform-dev": [], "plugin-api-version": "2.3.0" diff --git a/src/Components/Copyright.php b/src/Components/Copyright.php index 7c13ca9..55f38a1 100644 --- a/src/Components/Copyright.php +++ b/src/Components/Copyright.php @@ -13,11 +13,11 @@ class Copyright implements Buildable { use BuildableImp; - private $useCopyrightSymbol = true; + private bool $useCopyrightSymbol = true; - private $spellOutCopyright = false; + private bool $spellOutCopyright = false; - private $scope = ''; + private string $scope = ''; public static function create( string $holder, diff --git a/src/Components/FaviconMetroColors.php b/src/Components/FaviconMetroColors.php new file mode 100644 index 0000000..9e7f9ef --- /dev/null +++ b/src/Components/FaviconMetroColors.php @@ -0,0 +1,17 @@ +path; + } + + private function themeColor(): string + { + return $this->themeColor; + } + + private function hasPath(): bool + { + return strlen($this->path()) > 0; + } + + private function appName(): string + { + return $this->appName; + } + + public function withAppName(string $name): self + { + $this->appName = $name; + return $this; + } + + private function hasAppName(): bool + { + return strlen($this->appName()) > 0; + } + + public function withMetro( + FaviconMetroColors $tileColor = FaviconMetroColors::DarkOrange, + bool $useWhite = false + ): self { + $this->metroTileColor = $tileColor; + + if ($useWhite !== false) { + $this->metroUsesWhite = $useWhite; + } + + return $this; + } + + private function hasMetro(): bool + { + if ($this->metroUsesWhite()) { + return true; + } + return false; + } + + private function metroUsesWhite(): bool + { + if (isset($this->metroUsesWhite) === false) { + return false; + } + return $this->metroUsesWhite; + } + + public function withSafariThemeColor(string $color): self + { + $this->safariThemeColor = $color; + return $this; + } + + private function safariThemeColor(): string + { + return $this->safariThemeColor; + } + + public function __toString(): string + { + $elements = [ + Element::link()->omitEndTag()->props( + 'rel apple-touch-icon', + 'sizes 180x180', + 'href ' . $this->path() . '/apple-touch-icon.png' + ), + Element::link()->omitEndTag()->props( + 'rel icon', + 'type image/png', + 'sizes 32x32', + 'href ' . $this->path() . '/favicon-32x32.png' + ), + Element::link()->omitEndTag()->props( + 'rel icon', + 'type image/png', + 'sizes 16x16', + 'href ' . $this->path() . '/favicon-16x16.png' + ), + Element::link()->omitEndTag()->props( + 'rel manifest', + 'href ' . $this->path() . '/site.webmanifest' + ), + Element::meta()->omitEndTag()->props( + 'name msapplication-TileColor', + 'content ' . $this->metroTileColor->value + ), + Element::meta()->omitEndTag()->props( + 'name theme-color', + 'content ' . $this->themeColor() + ), + Element::link()->omitEndTag()->props( + 'rel mask-icon', + 'href ' . $this->path() . '/safari-pinned-tab.svg', + 'color ' . $this->safariThemeColor() + ) + ]; + + if ($this->hasPath()) { + $elements[] = Element::link()->omitendTag()->props( + 'rel shortcut icon', + 'href ' . $this->path() . '/favicon.ico' + ); + + $elements[] = Element::meta()->omitEndTag()->props( + 'name msapplication-config', + 'content ' . $this->path() . '/browserconfig.xml' + ); + } + + if ($this->hasMetro() and $this->metroUsesWhite()) { + $elements[] = Element::meta()->omitEndTag()->props( + 'name msapplication-TileImage', + 'content ' . $this->path() . '/mstile-144x144.png' + ); + } + + if ($this->hasAppName()) { + $elements[] = Element::meta()->omitEndTag()->props( + 'name application-name', + 'content ' . $this->appName() + ); + + $elements[] = Element::meta()->omitEndTag()->props( + 'name apple-mobile-web-app-title', + 'content ' . $this->appName() + ); + } + return (string) Concatenate::create(...$elements); + } +} diff --git a/src/Document.php b/src/Document.php index 97c4751..7402b4d 100644 --- a/src/Document.php +++ b/src/Document.php @@ -1,17 +1,19 @@ */ @@ -32,8 +34,8 @@ public static function create( final private function __construct( private string $title, - private string $lang = 'en', - private string $charset = 'utf-8' + private string $lang, + private string $charset ) { } @@ -49,7 +51,7 @@ public function body(string|Stringable ...$content): Document return $this; } - public function build(): string + public function __toString(): string { $doctype = '' . "\n"; return $doctype . Element::html( @@ -62,11 +64,6 @@ public function build(): string )->props($this->lang())->build(); } - public function __toString(): string - { - return $this->build(); - } - private function title(): string { return $this->title; diff --git a/src/Element.php b/src/Element.php index 2a9cfce..0e8298c 100644 --- a/src/Element.php +++ b/src/Element.php @@ -1,5 +1,4 @@ assertSame( + $expected, + $result . "\n" + ); + } + + /** + * @test + */ + public function can_set_theme_color(): void + { + $expected = file_get_contents(__DIR__ . '/favicons-theme-color.xml'); + + $result = (string) Favicons::create( + themeColor: '#000000' + ); + + $this->assertSame( + $expected, + $result . "\n" + ); + } + + /** + * @test + */ + public function can_use_subfolder(): void + { + $expected = file_get_contents(__DIR__ . '/favicons-subfolder.xml'); + + $result = (string) Favicons::create('/subfolder'); + + $this->assertSame( + $expected, + $result . "\n" + ); + } + + /** + * @test + */ + public function can_use_custom_app_name(): void + { + $expected = file_get_contents(__DIR__ . '/favicons-app-name.xml'); + + $result = (string) Favicons::create()->withAppName('Override page title'); + + $this->assertSame( + $expected, + $result . "\n" + ); + } + + /** + * @test + */ + public function can_use_windows_metro_settings(): void + { + $expected = file_get_contents(__DIR__ . '/favicons-windows-metro.xml'); + + $result = (string) Favicons::create()->withMetro(useWhite: true); + + $this->assertSame( + $expected, + $result . "\n" + ); + + $expected = file_get_contents( + __DIR__ . '/favicons-windows-metro-tile-color.xml' + ); + + $result = (string) Favicons::create()->withMetro( + FaviconMetroColors::Teal + ); + + $this->assertSame( + $expected, + $result . "\n" + ); + } +} diff --git a/tests/Components/favicons-app-name.xml b/tests/Components/favicons-app-name.xml new file mode 100644 index 0000000..dc255e6 --- /dev/null +++ b/tests/Components/favicons-app-name.xml @@ -0,0 +1 @@ + diff --git a/tests/Components/favicons-default.xml b/tests/Components/favicons-default.xml new file mode 100644 index 0000000..5438971 --- /dev/null +++ b/tests/Components/favicons-default.xml @@ -0,0 +1 @@ + diff --git a/tests/Components/favicons-subfolder.xml b/tests/Components/favicons-subfolder.xml new file mode 100644 index 0000000..9e6ef2e --- /dev/null +++ b/tests/Components/favicons-subfolder.xml @@ -0,0 +1 @@ + diff --git a/tests/Components/favicons-theme-color.xml b/tests/Components/favicons-theme-color.xml new file mode 100644 index 0000000..2ed005c --- /dev/null +++ b/tests/Components/favicons-theme-color.xml @@ -0,0 +1 @@ + diff --git a/tests/Components/favicons-windows-metro-tile-color.xml b/tests/Components/favicons-windows-metro-tile-color.xml new file mode 100644 index 0000000..1b58af6 --- /dev/null +++ b/tests/Components/favicons-windows-metro-tile-color.xml @@ -0,0 +1 @@ + diff --git a/tests/Components/favicons-windows-metro.xml b/tests/Components/favicons-windows-metro.xml new file mode 100644 index 0000000..7b28d74 --- /dev/null +++ b/tests/Components/favicons-windows-metro.xml @@ -0,0 +1 @@ +