Skip to content

Commit

Permalink
feat: support PHP 8.2
Browse files Browse the repository at this point in the history
  • Loading branch information
neilime committed Feb 17, 2023
1 parent e17661d commit 028a6bf
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 19 deletions.
1 change: 1 addition & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
include:
- php-versions: "8.0"
- php-versions: "8.1"
- php-versions: "8.2"
stable: true

runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 4 additions & 1 deletion src/Documentation/Test/Snapshots/Drivers/HtmlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
8 changes: 5 additions & 3 deletions src/TwbsHelper/Form/View/ElementHelperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions src/TwbsHelper/View/Helper/Navigation/Breadcrumbs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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');
Expand Down
19 changes: 11 additions & 8 deletions src/TwbsHelper/View/Helper/Navigation/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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])) {
Expand Down Expand Up @@ -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]);

Expand All @@ -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(
'/(<a.*aria-current=")(true)(".*)/imU',
Expand Down
2 changes: 1 addition & 1 deletion src/TwbsHelper/View/Helper/Navigation/Navbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ public function render($container = null, array $options = []): string
*/
public function renderNavbar($container = null, array $options = []): string
{
$this->parseContainer($container);
if (null === $container) {
$container = $this->getContainer();
}
$this->parseContainer($container);

$attributes = $this->prepareAttributes($options);
$id = $attributes['id'] ?? null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ public function testRenderStraightWithLinkLast()
'<nav aria-label="breadcrumb">' . PHP_EOL .
' <ol class="breadcrumb">' . PHP_EOL .
' <li class="breadcrumb-item"><a href="&#x2F;">Home</a></li>' . PHP_EOL .
' <li aria-current="page" class="active&#x20;breadcrumb-item">' .
'<a href="&#x2F;library">Library</a>' .
'</li>' . PHP_EOL .
' <li aria-current="page" class="active&#x20;breadcrumb-item">Library</li>' . PHP_EOL .
' </ol>' . PHP_EOL .
'</nav>',
$this->helper->renderStraight(new \Laminas\Navigation\Navigation([
Expand Down

0 comments on commit 028a6bf

Please sign in to comment.