Skip to content

Commit 84c8d7e

Browse files
committed
Make hard-coded versions from lang files dynamic
1 parent 6b94db9 commit 84c8d7e

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

ext.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ protected function phpbb_requirement($phpBB_version = PHPBB_VERSION)
5353
{
5454
if (phpbb_version_compare($phpBB_version, self::MIN_PHPBB_ALLOWED, '<'))
5555
{
56-
$this->errors[] = 'PHPBB_VERSION_MIN_ERROR';
56+
$this->errors[] = ['PHPBB_VERSION_MIN_ERROR', self::MIN_PHPBB_ALLOWED];
5757
}
5858
else if (phpbb_version_compare($phpBB_version, self::MAX_PHPBB_ALLOWED, '>='))
5959
{
60-
$this->errors[] = 'PHPBB_VERSION_MAX_ERROR';
60+
$this->errors[] = ['PHPBB_VERSION_MAX_ERROR', self::MAX_PHPBB_ALLOWED];
6161
}
6262
}
6363

@@ -71,7 +71,7 @@ protected function php_requirement($php_version = PHP_VERSION_ID)
7171
{
7272
if ($php_version < self::MIN_PHP_ALLOWED)
7373
{
74-
$this->errors[] = 'PHP_VERSION_ERROR';
74+
$this->errors[] = ['PHP_VERSION_ERROR', sprintf('%d.%d.%d', self::MIN_PHP_ALLOWED / 10000, (self::MIN_PHP_ALLOWED / 100) % 100, self::MIN_PHP_ALLOWED % 100)];
7575
}
7676
}
7777

@@ -101,7 +101,9 @@ protected function enable_failed()
101101
{
102102
$language = $this->container->get('language');
103103
$language->add_lang('common', 'phpbb/skeleton');
104-
return array_map([$language, 'lang'], $this->errors);
104+
return array_map(static function($error) use ($language) {
105+
return is_array($error) ? call_user_func_array([$language, 'lang'], $error) : $language->lang($error);
106+
}, $this->errors);
105107
}
106108

107109
return false;

language/en/common.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@
163163
'SKELETON_INVALID_PHPBB_MAX_VERSION'=> 'The maximum phpBB version requirement is invalid.',
164164

165165
'NO_ZIPARCHIVE_ERROR' => 'The ZipArchive class is required, but was not found in your PHP configuration.',
166-
'PHP_VERSION_ERROR' => 'PHP 5.6 or newer is required to use this extension.',
167-
'PHPBB_VERSION_MIN_ERROR' => 'phpBB 3.2.3 or newer is required to use this extension.',
168-
'PHPBB_VERSION_MAX_ERROR' => 'phpBB 4 is not supported with this version of the extension. Please check for a newer version of this extension.'
166+
'PHP_VERSION_ERROR' => 'PHP %1$s or newer is required to install this version of the Skeleton Extension.',
167+
'PHPBB_VERSION_MIN_ERROR' => 'phpBB %1$s or newer is required to install this version of the Skeleton Extension.',
168+
'PHPBB_VERSION_MAX_ERROR' => 'phpBB %1$s and above is not supported by this version of the Skeleton Extension. Please check for a newer version of this extension.'
169169
]);

tests/ext_test.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ protected function getExtErrors($ext): array
138138
{
139139
$prop = (new \ReflectionClass($ext))->getProperty('errors');
140140
$prop->setAccessible(true);
141-
return $prop->getValue($ext);
141+
return array_map(static function ($e) {
142+
return is_array($e) ? $e[0] : $e;
143+
}, $prop->getValue($ext));
142144
}
143145

144146
protected function setExtErrors($ext, array $errors): void

0 commit comments

Comments
 (0)