Skip to content

Commit 243936f

Browse files
committed
Add better checks for required PHP extensions
Signed-off-by: Matt Friedman <maf675@gmail.com>
1 parent 36a41c2 commit 243936f

3 files changed

Lines changed: 47 additions & 16 deletions

File tree

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: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ class ext extends \phpbb\extension\base
2929
*/
3030
public function is_enableable()
3131
{
32-
return $this->check_phpbb_version()->check_php_version()->result();
32+
return $this->check_phpbb_version()
33+
->check_php_version()
34+
->check_php_requirements()
35+
->result();
3336
}
3437

3538
/**
@@ -67,6 +70,24 @@ protected function check_php_version()
6770
return $this;
6871
}
6972

73+
/**
74+
* Check the installed PHP extensions meet this extension's requirements.
75+
*
76+
* @return \phpbb\webpushnotifications\ext
77+
*/
78+
protected function check_php_requirements()
79+
{
80+
foreach (['curl', 'mbstring', 'openssl'] as $extension)
81+
{
82+
if (!extension_loaded($extension))
83+
{
84+
$this->errors[] = ['PHP_EXT_MISSING', $extension];
85+
}
86+
}
87+
88+
return $this;
89+
}
90+
7091
/**
7192
* Return the is_enableable result. Either true, or the best enable failed
7293
* response for the current phpBB environment: array of error messages
@@ -85,7 +106,9 @@ protected function result()
85106
{
86107
$language = $this->container->get('language');
87108
$language->add_lang('install', 'phpbb/webpushnotifications');
88-
return array_map([$language, 'lang'], $this->errors);
109+
return array_map(static function($error) use ($language) {
110+
return call_user_func_array([$language, 'lang'], (array) $error);
111+
}, $this->errors);
89112
}
90113

91114
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 3.3.12 or newer is required.',
43+
'PHP_VERSION_ERROR' => 'PHP 7.3 or newer is required.',
44+
'PHP_EXT_MISSING' => 'The “%s” extension for PHP must be installed on this server.',
4445
]);

0 commit comments

Comments
 (0)