From 028a6bf2005b5a885e75c2d7e959f8514b413d44 Mon Sep 17 00:00:00 2001 From: Emilien Escalle Date: Fri, 17 Feb 2023 18:10:16 +0100 Subject: [PATCH] feat: support PHP 8.2 --- .github/workflows/continuous-integration.yml | 1 + composer.json | 2 +- .../Test/Snapshots/Drivers/HtmlDriver.php | 5 ++++- .../Form/View/ElementHelperTrait.php | 8 +++++--- .../View/Helper/Navigation/Breadcrumbs.php | 4 ++-- .../View/Helper/Navigation/Menu.php | 19 +++++++++++-------- .../View/Helper/Navigation/Navbar.php | 2 +- .../Helper/Navigation/BreadcrumbsTest.php | 4 +--- 8 files changed, 26 insertions(+), 19 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 001d6d782..868697596 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -16,6 +16,7 @@ jobs: include: - php-versions: "8.0" - php-versions: "8.1" + - php-versions: "8.2" stable: true runs-on: ubuntu-latest diff --git a/composer.json b/composer.json index e29c3057f..2b3ca329e 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "twitter/bootstrap": "Twitter bootstrap assets" }, "require": { - "php": "~8.0.0 || ~8.1.0", + "php": "~8.0.0 || ~8.1.0 || ~8.2.0", "laminas/laminas-escaper": "^2.12", "laminas/laminas-form": "^3.4", "laminas/laminas-i18n": "^2.17", diff --git a/src/Documentation/Test/Snapshots/Drivers/HtmlDriver.php b/src/Documentation/Test/Snapshots/Drivers/HtmlDriver.php index 4535f6be8..93545d5b7 100644 --- a/src/Documentation/Test/Snapshots/Drivers/HtmlDriver.php +++ b/src/Documentation/Test/Snapshots/Drivers/HtmlDriver.php @@ -6,7 +6,10 @@ class HtmlDriver extends \Spatie\Snapshots\Drivers\HtmlDriver { public function serialize($data): string { - $serializedData = parent::serialize(mb_convert_encoding($data, 'HTML-ENTITIES', 'UTF-8')); + + $serializedData = str_replace("—", "—", $data); + $serializedData = parent::serialize($serializedData); + return preg_replace('~<(?:!DOCTYPE|/?(?:html|head|body))[^>]*>\s*~i', '', $serializedData); } diff --git a/src/TwbsHelper/Form/View/ElementHelperTrait.php b/src/TwbsHelper/Form/View/ElementHelperTrait.php index acebcdca4..464ed36f3 100644 --- a/src/TwbsHelper/Form/View/ElementHelperTrait.php +++ b/src/TwbsHelper/Form/View/ElementHelperTrait.php @@ -8,10 +8,12 @@ protected function prepareAttributes(array $attributes): array { $attributes = $this->getView()->plugin('htmlattributes')->__invoke($attributes)->getArrayCopy(); - if (!is_callable('parent::prepareAttributes')) { - return $attributes; + $callParentPrepareAttributes = parent::class . '::prepareAttributes'; + if (is_callable($callParentPrepareAttributes)) { + $attributes = call_user_func($callParentPrepareAttributes, $attributes); } - return call_user_func('parent::prepareAttributes', $attributes); + + return $attributes; } protected function setClassesToElement( diff --git a/src/TwbsHelper/View/Helper/Navigation/Breadcrumbs.php b/src/TwbsHelper/View/Helper/Navigation/Breadcrumbs.php index 2ba4752a1..e124bb906 100644 --- a/src/TwbsHelper/View/Helper/Navigation/Breadcrumbs.php +++ b/src/TwbsHelper/View/Helper/Navigation/Breadcrumbs.php @@ -17,10 +17,10 @@ class Breadcrumbs extends \Laminas\View\Helper\Navigation\Breadcrumbs */ public function renderStraight($container = null) { - $this->parseContainer($container); if (null === $container) { $container = $this->getContainer(); } + $this->parseContainer($container); // Find deepest active $activePage = $this->findActive($container); @@ -31,7 +31,7 @@ public function renderStraight($container = null) $activePage = $activePage['page']; // Put the deepest active page last in breadcrumbs - if ($this->getLinkLast()) { + if ($this->getLinkLast() && !$activePage->isActive()) { $html = $this->htmlify($activePage); } else { $escapeHtml = $this->getView()->plugin('escapeHtml'); diff --git a/src/TwbsHelper/View/Helper/Navigation/Menu.php b/src/TwbsHelper/View/Helper/Navigation/Menu.php index e8fcc7dd1..515e4d9ed 100644 --- a/src/TwbsHelper/View/Helper/Navigation/Menu.php +++ b/src/TwbsHelper/View/Helper/Navigation/Menu.php @@ -46,11 +46,12 @@ public function renderMenu($container = null, array $options = []) */ protected function prepareContainer(&$container = null) { - $this->parseContainer($container); if (null === $container) { $container = $this->getContainer(); } + $this->parseContainer($container); + // Create iterator $iterator = new \RecursiveIteratorIterator( $container, @@ -214,13 +215,13 @@ protected function getMenuItemsNavClasses(iterable $options, bool $isRoot): iter $classes = []; foreach ( [ - 'tabs' => 'nav-tabs', - 'pills' => 'nav-pills', - 'fill' => 'nav-fill', - 'justified' => 'nav-justified', - 'centered' => 'justify-content-center', - 'right_aligned' => 'justify-content-end', - 'vertical' => 'flex-column', + 'tabs' => 'nav-tabs', + 'pills' => 'nav-pills', + 'fill' => 'nav-fill', + 'justified' => 'nav-justified', + 'centered' => 'justify-content-center', + 'right_aligned' => 'justify-content-end', + 'vertical' => 'flex-column', ] as $option => $className ) { if (!empty($options[$option])) { @@ -291,6 +292,7 @@ protected function renderMenuItemsLink(string $content, array $options): string ); } + // Inject class attribute in link if ($itemClasses) { $attributes = $this->getView()->plugin('htmlattributes')->__invoke(['class' => $itemClasses]); @@ -303,6 +305,7 @@ protected function renderMenuItemsLink(string $content, array $options): string ); } + // Inject aria-current attribute in link if page is current if (!empty($options['page'])) { $content = preg_replace( '/(parseContainer($container); if (null === $container) { $container = $this->getContainer(); } + $this->parseContainer($container); $attributes = $this->prepareAttributes($options); $id = $attributes['id'] ?? null; diff --git a/tests/TestSuite/TwbsHelper/View/Helper/Navigation/BreadcrumbsTest.php b/tests/TestSuite/TwbsHelper/View/Helper/Navigation/BreadcrumbsTest.php index 4a1569656..0d4701648 100644 --- a/tests/TestSuite/TwbsHelper/View/Helper/Navigation/BreadcrumbsTest.php +++ b/tests/TestSuite/TwbsHelper/View/Helper/Navigation/BreadcrumbsTest.php @@ -26,9 +26,7 @@ public function testRenderStraightWithLinkLast() '', $this->helper->renderStraight(new \Laminas\Navigation\Navigation([