Skip to content

Commit a269b00

Browse files
authored
Merge pull request #76 from iMattPro/improvements
Add better PHP requirement checks
2 parents 36a41c2 + 885b5bc commit a269b00

5 files changed

Lines changed: 70 additions & 27 deletions

File tree

.github/workflows/tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,14 +357,14 @@ jobs:
357357
db: "mcr.microsoft.com/mssql/server:2017-latest"
358358
db_alias: 'MSSQL 2017'
359359
- php: '7.3'
360-
db: "mcr.microsoft.com/mssql/server:2019-latest"
360+
db: "mcr.microsoft.com/mssql/server:2019-CU27-ubuntu-20.04"
361361
db_alias: 'MSSQL 2019'
362362

363363
name: PHP ${{ matrix.php }} - ${{ matrix.db_alias != '' && matrix.db_alias || matrix.db }}
364364

365365
services:
366366
mssql:
367-
image: ${{ matrix.db != 'mcr.microsoft.com/mssql/server:2017-latest' && matrix.db != 'mcr.microsoft.com/mssql/server:2019-latest' && 'mcr.microsoft.com/mssql/server:2017-latest' || matrix.db }}
367+
image: ${{ matrix.db != 'mcr.microsoft.com/mssql/server:2017-latest' && matrix.db != 'mcr.microsoft.com/mssql/server:2019-CU27-ubuntu-20.04' && 'mcr.microsoft.com/mssql/server:2017-latest' || matrix.db }}
368368
env:
369369
SA_PASSWORD: "Pssw0rd_12"
370370
ACCEPT_EULA: "y"
@@ -404,7 +404,7 @@ jobs:
404404
env:
405405
MATRIX_DB: ${{ matrix.db }}
406406
run: |
407-
if [ $MATRIX_DB == 'mcr.microsoft.com/mssql/server:2017-latest' ] || [ $MATRIX_DB == 'mcr.microsoft.com/mssql/server:2019-latest' ]
407+
if [ $MATRIX_DB == 'mcr.microsoft.com/mssql/server:2017-latest' ] || [ $MATRIX_DB == 'mcr.microsoft.com/mssql/server:2019-CU27-ubuntu-20.04' ]
408408
then
409409
db='mssql'
410410
else

composer.json

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,33 @@
2424
],
2525
"require": {
2626
"php": ">=7.3",
27+
"ext-curl": "*",
28+
"ext-json": "*",
29+
"ext-mbstring": "*",
30+
"ext-openssl": "*",
2731
"composer/installers": "~1.0",
2832
"minishlink/web-push": "^7.0"
2933
},
3034
"require-dev": {
3135
"phing/phing": "~2.4"
3236
},
33-
"config": {
34-
"allow-plugins": {
35-
"composer/installers": true
36-
}
37-
},
38-
"extra": {
37+
"suggest": {
38+
"ext-gmp": "Optional but better for performance"
39+
},
40+
"config": {
41+
"allow-plugins": {
42+
"composer/installers": true
43+
}
44+
},
45+
"extra": {
3946
"display-name": "phpBB Browser Push Notifications",
4047
"soft-require": {
4148
"phpbb/phpbb": ">=3.3.12,<4.0.0@dev"
42-
},
43-
"version-check": {
44-
"host": "imattpro.github.io",
45-
"directory": "/version",
46-
"filename": "webpushnotifications.json"
49+
},
50+
"version-check": {
51+
"host": "imattpro.github.io",
52+
"directory": "/version",
53+
"filename": "webpushnotifications.json"
4754
}
4855
}
4956
}

ext.php

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,35 @@
1515
*/
1616
class ext extends \phpbb\extension\base
1717
{
18+
/**
19+
* Require phpBB 3.3.12 due to new template and core events.
20+
*/
21+
public const PHPBB_MIN_VERSION = '3.3.12';
22+
23+
/**
24+
* Should not be installed in phpBB 4 because it already has push notifications.
25+
*/
26+
public const PHPBB_MAX_VERSION = '4.0.0-dev';
27+
28+
/**
29+
* Require PHP 7.3 due to 3rd party libraries included.
30+
*/
31+
public const PHP_MIN_VERSION = '7.3';
32+
1833
/**
1934
* @var array An array of installation error messages
2035
*/
2136
protected $errors = [];
2237

2338
/**
2439
* {@inheritdoc}
25-
*
26-
* Requires phpBB 3.3.12 due to new template and core events.
27-
* Should not be installed in phpBB 4.0.0-a1 because it already has push notifications.
28-
* Requires PHP 7.3 due to 3rd party libraries included.
2940
*/
3041
public function is_enableable()
3142
{
32-
return $this->check_phpbb_version()->check_php_version()->result();
43+
return $this->check_phpbb_version()
44+
->check_php_version()
45+
->check_php_requirements()
46+
->result();
3347
}
3448

3549
/**
@@ -39,12 +53,12 @@ public function is_enableable()
3953
*/
4054
protected function check_phpbb_version()
4155
{
42-
if (phpbb_version_compare(PHPBB_VERSION, '3.3.12', '<'))
56+
if (phpbb_version_compare(PHPBB_VERSION, self::PHPBB_MIN_VERSION, '<'))
4357
{
4458
$this->errors[] = 'PHPBB_VERSION_MIN_ERROR';
4559
}
4660

47-
if (phpbb_version_compare(PHPBB_VERSION, '4.0.0-dev', '>='))
61+
if (phpbb_version_compare(PHPBB_VERSION, self::PHPBB_MAX_VERSION, '>='))
4862
{
4963
$this->errors[] = 'PHPBB_VERSION_MAX_ERROR';
5064
}
@@ -67,6 +81,24 @@ protected function check_php_version()
6781
return $this;
6882
}
6983

84+
/**
85+
* Check the installed PHP extensions meet this extension's requirements.
86+
*
87+
* @return \phpbb\webpushnotifications\ext
88+
*/
89+
protected function check_php_requirements()
90+
{
91+
foreach (['curl', 'mbstring', 'openssl'] as $extension)
92+
{
93+
if (!extension_loaded($extension))
94+
{
95+
$this->errors[] = ['PHP_EXT_MISSING', $extension];
96+
}
97+
}
98+
99+
return $this;
100+
}
101+
70102
/**
71103
* Return the is_enableable result. Either true, or the best enable failed
72104
* response for the current phpBB environment: array of error messages
@@ -85,7 +117,9 @@ protected function result()
85117
{
86118
$language = $this->container->get('language');
87119
$language->add_lang('install', 'phpbb/webpushnotifications');
88-
return array_map([$language, 'lang'], $this->errors);
120+
return array_map(static function($error) use ($language) {
121+
return call_user_func_array([$language, 'lang'], (array) $error);
122+
}, $this->errors);
89123
}
90124

91125
return false;

language/en/install.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
//
3939

4040
$lang = array_merge($lang, [
41-
'PHPBB_VERSION_MAX_ERROR' => 'This extension can not be installed on your board. You are using phpBB 4, which already contains the features in this extension.',
42-
'PHPBB_VERSION_MIN_ERROR' => 'This extension is not compatible with your board. You must be using phpBB 3.3.12 or newer.',
43-
'PHP_VERSION_ERROR' => 'This extension is not compatible with your server. Your server must be running PHP 7.3 or newer.',
41+
'PHPBB_VERSION_MAX_ERROR' => 'This extension can not be installed on this board. This is a phpBB 4 board, which already contains the features in this extension.',
42+
'PHPBB_VERSION_MIN_ERROR' => 'phpBB ' . \phpbb\webpushnotifications\ext::PHPBB_MIN_VERSION . ' or newer is required.',
43+
'PHP_VERSION_ERROR' => 'PHP ' . \phpbb\webpushnotifications\ext::PHP_MIN_VERSION . ' or newer is required.',
44+
'PHP_EXT_MISSING' => 'The “%s” extension for PHP must be installed on this server.',
4445
]);

language/ru/install.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
$lang = array_merge($lang, [
4141
'PHPBB_VERSION_MAX_ERROR' => 'Данное расширение несовместимо с установленной версией конференции. Вы используете версию phpBB 4, которая уже содержит соответствующие функции.',
42-
'PHPBB_VERSION_MIN_ERROR' => 'Данное расширение несовместимо с установленной версией конференции. Необходима версия phpBB 3.3.12 или выше.',
43-
'PHP_VERSION_ERROR' => 'Данное расширение несовместимо с установленной на сервере версией PHP. Необходима версия PHP 7.3 или выше.',
42+
'PHPBB_VERSION_MIN_ERROR' => 'Данное расширение несовместимо с установленной версией конференции. Необходима версия phpBB ' . \phpbb\webpushnotifications\ext::PHPBB_MIN_VERSION . ' или выше.',
43+
'PHP_VERSION_ERROR' => 'Данное расширение несовместимо с установленной на сервере версией PHP. Необходима версия PHP ' . \phpbb\webpushnotifications\ext::PHP_MIN_VERSION . ' или выше.',
44+
'PHP_EXT_MISSING' => 'На этом сервере должно быть установлено расширение «%s» для PHP.',
4445
]);

0 commit comments

Comments
 (0)