Skip to content

Commit

Permalink
fix PHP 7.4 (2)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixhahnweilheim committed Feb 14, 2024
1 parent ef88cf7 commit b3235f6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 8 additions & 1 deletion models/ColorSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,14 @@ protected function additonalColorSaving(string $color, ?string $value): void

protected function getColorFallBack(string $color): string
{
$value = (new \ReflectionClass($this))->getProperty($color)->getDefaultValue();
// compatiblity with PHP 7.4 will be removed in next version
if (version_compare(phpversion(), '8.0.0', '<')) {
$value = (new \ReflectionProperty($this))->getDeclaringClass()->getDefaultProperties()[$color] ?? null;
} else {
// min PHP 8.0
$value = (new \ReflectionClass($this))->getProperty($color)->getDefaultValue();
}

if (empty($value)) {
$theme_var = str_replace('_', '-', $color);
$value = ThemeHelper::getThemeByName(self::BASE_THEME)->variable(static::PREFIX . $theme_var);
Expand Down
9 changes: 8 additions & 1 deletion models/DarkColorSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,14 @@ public function attributeHints(): array

protected function getColorFallBack(string $color): string
{
$value = (new \ReflectionClass($this))->getProperty($color)->getDefaultValue();
// compatiblity with PHP 7.4 will be removed in next version
if (version_compare(phpversion(), '8.0.0', '<')) {
$value = (new \ReflectionProperty($this))->getDeclaringClass()->getDefaultProperties()[$color] ?? null;
} else {
// min PHP 8.0
$value = (new \ReflectionClass($this))->getProperty($color)->getDefaultValue();
}

if (empty($value)) {// only main colors can be empty!
if (!isset($lightColors)) {
$lightColors = (new ColorSettings())->getColors();
Expand Down

0 comments on commit b3235f6

Please sign in to comment.