From 337bad9112ad2ced13b0890d69e809657164d2f6 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Thu, 20 Apr 2023 18:58:37 +0200 Subject: [PATCH] cosmetic nullsafe fix --- src/Alias.php | 20 ++++++++++++++++++++ src/Backend.php | 6 ++++++ src/Manage.php | 20 ++++++++++++++------ 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/Alias.php b/src/Alias.php index 63c3fca..38c9d3d 100644 --- a/src/Alias.php +++ b/src/Alias.php @@ -40,6 +40,11 @@ class Alias return $this->aliases; } + // nullsafe PHP < 8.0 + if (is_null(dcCore::app()->blog)) { + return []; + } + $sql = new SelectStatement(); $rs = $sql->from(dcCore::app()->prefix . My::ALIAS_TABLE_NAME) ->columns([ @@ -97,6 +102,11 @@ class Alias */ public function createAlias(string $url, string $destination, int $position): void { + // nullsafe PHP < 8.0 + if (is_null(dcCore::app()->blog)) { + return; + } + $url = trim($url); $destination = trim($destination); @@ -122,6 +132,11 @@ class Alias */ public function deleteAlias(string $url): void { + // nullsafe PHP < 8.0 + if (is_null(dcCore::app()->blog)) { + return; + } + $sql = new DeleteStatement(); $sql->from(dcCore::app()->prefix . My::ALIAS_TABLE_NAME) ->where('blog_id = ' . $sql->quote((string) dcCore::app()->blog->id)) @@ -134,6 +149,11 @@ class Alias */ public function deleteAliases(): void { + // nullsafe PHP < 8.0 + if (is_null(dcCore::app()->blog)) { + return; + } + $sql = new DeleteStatement(); $sql->from(dcCore::app()->prefix . My::ALIAS_TABLE_NAME) ->where('blog_id = ' . $sql->quote((string) dcCore::app()->blog->id)) diff --git a/src/Backend.php b/src/Backend.php index 6636081..3182444 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -27,6 +27,7 @@ class Backend extends dcNsProcess public static function init(): bool { static::$init = defined('DC_CONTEXT_ADMIN') + && !is_null(dcCore::app()->auth) && !is_null(dcCore::app()->blog) //nullsafe PHP < 8.0 && dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([ dcCore::app()->auth::PERMISSION_ADMIN, ]), dcCore::app()->blog->id); @@ -40,6 +41,11 @@ class Backend extends dcNsProcess return false; } + // nullsafe PHP < 8.0 + if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) { + return false; + } + dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem( My::name(), dcCore::app()->adminurl->get('admin.plugin.' . My::id()), diff --git a/src/Manage.php b/src/Manage.php index 4dccc80..e321379 100644 --- a/src/Manage.php +++ b/src/Manage.php @@ -40,12 +40,10 @@ class Manage extends dcNsProcess public static function init(): bool { static::$init = defined('DC_CONTEXT_ADMIN') - && dcCore::app()->auth->check( - dcCore::app()->auth->makePermissions([ - dcCore::app()->auth::PERMISSION_ADMIN, - ]), - dcCore::app()->blog->id - ); + && !is_null(dcCore::app()->auth) && !is_null(dcCore::app()->blog) //nullsafe PHP < 8.0 + && dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([ + dcCore::app()->auth::PERMISSION_ADMIN, + ]), dcCore::app()->blog->id); return static::$init; } @@ -56,6 +54,11 @@ class Manage extends dcNsProcess return false; } + // nullsafe PHP < 8.0 + if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) { + return false; + } + if (empty($_POST) || empty($_POST['a']) && empty($_POST['alias_url'])) { return true; } @@ -94,6 +97,11 @@ class Manage extends dcNsProcess return; } + // nullsafe PHP < 8.0 + if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) { + return; + } + $alias = new Alias(); $aliases = $alias->getAliases();