Skip to content

Commit 7ac0db1

Browse files
authored
Merge pull request #162 from iMattPro/updates
Prevent fatal php errors if phpBB is v4
2 parents 0bdd523 + 1a007ab commit 7ac0db1

File tree

6 files changed

+52
-38
lines changed

6 files changed

+52
-38
lines changed

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"type": "phpbb-extension",
44
"description": "The official phpBB skeleton extension generator.",
55
"homepage": "https://www.phpbb.com/customise/db/official_tool/ext_skeleton/",
6-
"version": "1.1.16",
6+
"version": "1.2.0-dev",
77
"license": "GPL-2.0-only",
88
"authors": [
99
{
@@ -19,7 +19,7 @@
1919
}
2020
],
2121
"require": {
22-
"php": ">=5.6",
22+
"php": ">=7.1",
2323
"composer/installers": "~1.0",
2424
"ext-zip": "*"
2525
},
@@ -29,7 +29,7 @@
2929
"extra": {
3030
"display-name": "phpBB Skeleton Extension",
3131
"soft-require": {
32-
"phpbb/phpbb": ">=3.2.3,<4.0.0@dev"
32+
"phpbb/phpbb": ">=3.3.0,<4.0.0@dev"
3333
},
3434
"version-check": {
3535
"host": "www.phpbb.com",

ext.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515

1616
class ext extends \phpbb\extension\base
1717
{
18-
const DEFAULT_PHP = '7.1.3';
19-
const DEFAULT_PHPBB_MIN = '3.3.0';
20-
const DEFAULT_PHPBB_MAX = '4.0.0@dev';
18+
public const DEFAULT_SKELETON_PHP = '7.1.3';
19+
public const DEFAULT_SKELETON_PHPBB_MIN = '3.3.0';
20+
public const DEFAULT_SKELETON_PHPBB_MAX = '4.0.0@dev';
2121

22-
const REQUIRE_PHPBB_MIN = '3.2.3';
23-
const REQUIRE_PHPBB_MAX = '4.0.0-dev';
24-
const REQUIRE_PHP = 50600;
22+
public const MIN_PHPBB_ALLOWED = '3.3.0';
23+
public const MAX_PHPBB_ALLOWED = '4.0.0-dev';
24+
public const MIN_PHP_ALLOWED = 70100;
2525

2626
/**
2727
* @var array An array of installation error messages
@@ -51,11 +51,11 @@ public function is_enableable()
5151
*/
5252
protected function phpbb_requirement($phpBB_version = PHPBB_VERSION)
5353
{
54-
if (phpbb_version_compare($phpBB_version, self::REQUIRE_PHPBB_MIN, '<'))
54+
if (phpbb_version_compare($phpBB_version, self::MIN_PHPBB_ALLOWED, '<'))
5555
{
5656
$this->errors[] = 'PHPBB_VERSION_MIN_ERROR';
5757
}
58-
else if (phpbb_version_compare($phpBB_version, self::REQUIRE_PHPBB_MAX, '>='))
58+
else if (phpbb_version_compare($phpBB_version, self::MAX_PHPBB_ALLOWED, '>='))
5959
{
6060
$this->errors[] = 'PHPBB_VERSION_MAX_ERROR';
6161
}
@@ -69,7 +69,7 @@ protected function phpbb_requirement($phpBB_version = PHPBB_VERSION)
6969
*/
7070
protected function php_requirement($php_version = PHP_VERSION_ID)
7171
{
72-
if ($php_version < self::REQUIRE_PHP)
72+
if ($php_version < self::MIN_PHP_ALLOWED)
7373
{
7474
$this->errors[] = 'PHP_VERSION_ERROR';
7575
}

helper/packager.php

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use phpbb\config\config;
1717
use phpbb\di\service_collection;
1818
use phpbb\filesystem\filesystem;
19-
use phpbb\path_helper;
2019
use phpbb\skeleton\ext;
2120
use phpbb\skeleton\template\twig\extension\skeleton_version_compare;
2221
use phpbb\template\context;
@@ -75,9 +74,9 @@ public function get_composer_dialog_values()
7574
'extension_homepage' => null,
7675
],
7776
'requirements' => [
78-
'php_version' => '>=' . ext::DEFAULT_PHP,
79-
'phpbb_version_min' => '>=' . ext::DEFAULT_PHPBB_MIN,
80-
'phpbb_version_max' => '<' . ext::DEFAULT_PHPBB_MAX,
77+
'php_version' => '>=' . ext::DEFAULT_SKELETON_PHP,
78+
'phpbb_version_min' => '>=' . ext::DEFAULT_SKELETON_PHPBB_MIN,
79+
'phpbb_version_max' => '<' . ext::DEFAULT_SKELETON_PHPBB_MAX,
8180
],
8281
];
8382
}
@@ -199,20 +198,35 @@ protected function get_template_engine()
199198
'assets_version' => null,
200199
]);
201200

202-
/** @var path_helper $path_helper */
203-
$path_helper = $this->phpbb_container->get('path_helper');
204-
/** @var filesystem $filesystem */
205-
$filesystem = $this->phpbb_container->get('filesystem');
206-
$environment = new environment(
207-
$config,
208-
$filesystem,
209-
$path_helper,
210-
$this->phpbb_container->getParameter('core.cache_dir'),
211-
$this->phpbb_container->get('ext.manager'),
212-
new loader(
213-
new filesystem()
214-
)
215-
);
201+
$container = $this->phpbb_container;
202+
$path_helper = $container->get('path_helper');
203+
$filesystem = $container->get('filesystem');
204+
$cache_dir = $container->getParameter('core.cache_dir');
205+
$ext_manager = $container->get('ext.manager');
206+
207+
$is_phpbb_4 = defined('PHPBB_VERSION') &&
208+
phpbb_version_compare(PHPBB_VERSION, '4.0.0-dev', '>=');
209+
210+
$args = $is_phpbb_4
211+
? [
212+
$container->get('assets.bag'),
213+
$config,
214+
$filesystem,
215+
$path_helper,
216+
$cache_dir,
217+
$ext_manager,
218+
new loader()
219+
]
220+
: [
221+
$config,
222+
$filesystem,
223+
$path_helper,
224+
$cache_dir,
225+
$ext_manager,
226+
new loader(new filesystem())
227+
];
228+
229+
$environment = new environment(...$args);
216230

217231
// Custom filter for use by packager to decode greater/less than symbols
218232
$filter = new \Twig\TwigFilter('skeleton_decode', function ($string) {
@@ -225,8 +239,8 @@ protected function get_template_engine()
225239
$config,
226240
new context(),
227241
$environment,
228-
$this->phpbb_container->getParameter('core.cache_dir'),
229-
$this->phpbb_container->get('user'),
242+
$cache_dir,
243+
$container->get('user'),
230244
[
231245
new skeleton_version_compare()
232246
]

language/en/common.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@
7070

7171
'SKELETON_QUESTION_PHP_VERSION' => 'Please enter the PHP requirement of the extension',
7272
'SKELETON_QUESTION_PHP_VERSION_UI' => 'PHP requirement of the extension',
73-
'SKELETON_QUESTION_PHP_VERSION_EXPLAIN' => 'default: &gt;=' . \phpbb\skeleton\ext::DEFAULT_PHP,
73+
'SKELETON_QUESTION_PHP_VERSION_EXPLAIN' => 'default: &gt;=' . \phpbb\skeleton\ext::DEFAULT_SKELETON_PHP,
7474
'SKELETON_QUESTION_PHPBB_VERSION_MIN' => 'Please enter the minimum phpBB requirement of the extension',
7575
'SKELETON_QUESTION_PHPBB_VERSION_MIN_UI' => 'Minimum phpBB requirement of the extension',
76-
'SKELETON_QUESTION_PHPBB_VERSION_MIN_EXPLAIN' => 'default: &gt;=' . \phpbb\skeleton\ext::DEFAULT_PHPBB_MIN,
76+
'SKELETON_QUESTION_PHPBB_VERSION_MIN_EXPLAIN' => 'default: &gt;=' . \phpbb\skeleton\ext::DEFAULT_SKELETON_PHPBB_MIN,
7777
'SKELETON_QUESTION_PHPBB_VERSION_MAX' => 'Please enter the maximum phpBB requirement of the extension',
7878
'SKELETON_QUESTION_PHPBB_VERSION_MAX_UI' => 'Maximum phpBB requirement of the extension',
79-
'SKELETON_QUESTION_PHPBB_VERSION_MAX_EXPLAIN' => 'default: &lt;' . \phpbb\skeleton\ext::DEFAULT_PHPBB_MAX,
79+
'SKELETON_QUESTION_PHPBB_VERSION_MAX_EXPLAIN' => 'default: &lt;' . \phpbb\skeleton\ext::DEFAULT_SKELETON_PHPBB_MAX,
8080

8181
'SKELETON_QUESTION_COMPONENT_PHPLISTENER' => 'Create sample PHP event listeners',
8282
'SKELETON_QUESTION_COMPONENT_PHPLISTENER_UI' => 'PHP event listeners',

tests/controller/main_test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public function test_handle($status_code, $page_content)
146146
['vendor_name', '', true, \phpbb\request\request_interface::REQUEST, 'foo'],
147147
['author_name', [''], true, \phpbb\request\request_interface::REQUEST, ['bar']],
148148
['extension_version', '1.0.0-dev', true, \phpbb\request\request_interface::REQUEST, '1.0.0-dev'],
149-
['php_version', '>=' . ext::DEFAULT_PHP, false, \phpbb\request\request_interface::REQUEST, '>=' . ext::DEFAULT_PHP],
149+
['php_version', '>=' . ext::DEFAULT_SKELETON_PHP, false, \phpbb\request\request_interface::REQUEST, '>=' . ext::DEFAULT_SKELETON_PHP],
150150
['component_phplistener', false, false, \phpbb\request\request_interface::REQUEST, true],
151151
]);
152152

@@ -229,7 +229,7 @@ public function test_handle($status_code, $page_content)
229229
'NAME' => 'php_version',
230230
'DESC' => 'SKELETON_QUESTION_PHP_VERSION_UI',
231231
'DESC_EXPLAIN' => 'SKELETON_QUESTION_PHP_VERSION_EXPLAIN',
232-
'VALUE' => '>=' . ext::DEFAULT_PHP,
232+
'VALUE' => '>=' . ext::DEFAULT_SKELETON_PHP,
233233
]],
234234
['requirement', [
235235
'NAME' => 'phpbb_version_min',

tests/helper/packager_test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ public function test_get_template_engine_returns_twig_instance()
217217
$user
218218
);
219219

220-
$this->container->expects($this->exactly(2))
220+
$this->container->expects($this->once())
221221
->method('getParameter')
222222
->with('core.cache_dir')
223223
->willReturn(false);

0 commit comments

Comments
 (0)