diff --git a/composer.json b/composer.json index 2ffd82d..f9a6451 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "type": "phpbb-extension", "description": "The official phpBB skeleton extension generator.", "homepage": "https://www.phpbb.com/customise/db/official_tool/ext_skeleton/", - "version": "1.1.16", + "version": "1.2.0-dev", "license": "GPL-2.0-only", "authors": [ { @@ -19,7 +19,7 @@ } ], "require": { - "php": ">=5.6", + "php": ">=7.1", "composer/installers": "~1.0", "ext-zip": "*" }, @@ -29,7 +29,7 @@ "extra": { "display-name": "phpBB Skeleton Extension", "soft-require": { - "phpbb/phpbb": ">=3.2.3,<4.0.0@dev" + "phpbb/phpbb": ">=3.3.0,<4.0.0@dev" }, "version-check": { "host": "www.phpbb.com", diff --git a/ext.php b/ext.php index f085e0d..a2cdd1c 100644 --- a/ext.php +++ b/ext.php @@ -15,13 +15,13 @@ class ext extends \phpbb\extension\base { - const DEFAULT_PHP = '7.1.3'; - const DEFAULT_PHPBB_MIN = '3.3.0'; - const DEFAULT_PHPBB_MAX = '4.0.0@dev'; + public const DEFAULT_SKELETON_PHP = '7.1.3'; + public const DEFAULT_SKELETON_PHPBB_MIN = '3.3.0'; + public const DEFAULT_SKELETON_PHPBB_MAX = '4.0.0@dev'; - const REQUIRE_PHPBB_MIN = '3.2.3'; - const REQUIRE_PHPBB_MAX = '4.0.0-dev'; - const REQUIRE_PHP = 50600; + public const MIN_PHPBB_ALLOWED = '3.3.0'; + public const MAX_PHPBB_ALLOWED = '4.0.0-dev'; + public const MIN_PHP_ALLOWED = 70100; /** * @var array An array of installation error messages @@ -51,11 +51,11 @@ public function is_enableable() */ protected function phpbb_requirement($phpBB_version = PHPBB_VERSION) { - if (phpbb_version_compare($phpBB_version, self::REQUIRE_PHPBB_MIN, '<')) + if (phpbb_version_compare($phpBB_version, self::MIN_PHPBB_ALLOWED, '<')) { $this->errors[] = 'PHPBB_VERSION_MIN_ERROR'; } - else if (phpbb_version_compare($phpBB_version, self::REQUIRE_PHPBB_MAX, '>=')) + else if (phpbb_version_compare($phpBB_version, self::MAX_PHPBB_ALLOWED, '>=')) { $this->errors[] = 'PHPBB_VERSION_MAX_ERROR'; } @@ -69,7 +69,7 @@ protected function phpbb_requirement($phpBB_version = PHPBB_VERSION) */ protected function php_requirement($php_version = PHP_VERSION_ID) { - if ($php_version < self::REQUIRE_PHP) + if ($php_version < self::MIN_PHP_ALLOWED) { $this->errors[] = 'PHP_VERSION_ERROR'; } diff --git a/helper/packager.php b/helper/packager.php index aa29339..6186d6d 100644 --- a/helper/packager.php +++ b/helper/packager.php @@ -16,7 +16,6 @@ use phpbb\config\config; use phpbb\di\service_collection; use phpbb\filesystem\filesystem; -use phpbb\path_helper; use phpbb\skeleton\ext; use phpbb\skeleton\template\twig\extension\skeleton_version_compare; use phpbb\template\context; @@ -75,9 +74,9 @@ public function get_composer_dialog_values() 'extension_homepage' => null, ], 'requirements' => [ - 'php_version' => '>=' . ext::DEFAULT_PHP, - 'phpbb_version_min' => '>=' . ext::DEFAULT_PHPBB_MIN, - 'phpbb_version_max' => '<' . ext::DEFAULT_PHPBB_MAX, + 'php_version' => '>=' . ext::DEFAULT_SKELETON_PHP, + 'phpbb_version_min' => '>=' . ext::DEFAULT_SKELETON_PHPBB_MIN, + 'phpbb_version_max' => '<' . ext::DEFAULT_SKELETON_PHPBB_MAX, ], ]; } @@ -199,20 +198,35 @@ protected function get_template_engine() 'assets_version' => null, ]); - /** @var path_helper $path_helper */ - $path_helper = $this->phpbb_container->get('path_helper'); - /** @var filesystem $filesystem */ - $filesystem = $this->phpbb_container->get('filesystem'); - $environment = new environment( - $config, - $filesystem, - $path_helper, - $this->phpbb_container->getParameter('core.cache_dir'), - $this->phpbb_container->get('ext.manager'), - new loader( - new filesystem() - ) - ); + $container = $this->phpbb_container; + $path_helper = $container->get('path_helper'); + $filesystem = $container->get('filesystem'); + $cache_dir = $container->getParameter('core.cache_dir'); + $ext_manager = $container->get('ext.manager'); + + $is_phpbb_4 = defined('PHPBB_VERSION') && + phpbb_version_compare(PHPBB_VERSION, '4.0.0-dev', '>='); + + $args = $is_phpbb_4 + ? [ + $container->get('assets.bag'), + $config, + $filesystem, + $path_helper, + $cache_dir, + $ext_manager, + new loader() + ] + : [ + $config, + $filesystem, + $path_helper, + $cache_dir, + $ext_manager, + new loader(new filesystem()) + ]; + + $environment = new environment(...$args); // Custom filter for use by packager to decode greater/less than symbols $filter = new \Twig\TwigFilter('skeleton_decode', function ($string) { @@ -225,8 +239,8 @@ protected function get_template_engine() $config, new context(), $environment, - $this->phpbb_container->getParameter('core.cache_dir'), - $this->phpbb_container->get('user'), + $cache_dir, + $container->get('user'), [ new skeleton_version_compare() ] diff --git a/language/en/common.php b/language/en/common.php index 0f085d8..7b4665e 100644 --- a/language/en/common.php +++ b/language/en/common.php @@ -70,13 +70,13 @@ 'SKELETON_QUESTION_PHP_VERSION' => 'Please enter the PHP requirement of the extension', 'SKELETON_QUESTION_PHP_VERSION_UI' => 'PHP requirement of the extension', - 'SKELETON_QUESTION_PHP_VERSION_EXPLAIN' => 'default: >=' . \phpbb\skeleton\ext::DEFAULT_PHP, + 'SKELETON_QUESTION_PHP_VERSION_EXPLAIN' => 'default: >=' . \phpbb\skeleton\ext::DEFAULT_SKELETON_PHP, 'SKELETON_QUESTION_PHPBB_VERSION_MIN' => 'Please enter the minimum phpBB requirement of the extension', 'SKELETON_QUESTION_PHPBB_VERSION_MIN_UI' => 'Minimum phpBB requirement of the extension', - 'SKELETON_QUESTION_PHPBB_VERSION_MIN_EXPLAIN' => 'default: >=' . \phpbb\skeleton\ext::DEFAULT_PHPBB_MIN, + 'SKELETON_QUESTION_PHPBB_VERSION_MIN_EXPLAIN' => 'default: >=' . \phpbb\skeleton\ext::DEFAULT_SKELETON_PHPBB_MIN, 'SKELETON_QUESTION_PHPBB_VERSION_MAX' => 'Please enter the maximum phpBB requirement of the extension', 'SKELETON_QUESTION_PHPBB_VERSION_MAX_UI' => 'Maximum phpBB requirement of the extension', - 'SKELETON_QUESTION_PHPBB_VERSION_MAX_EXPLAIN' => 'default: <' . \phpbb\skeleton\ext::DEFAULT_PHPBB_MAX, + 'SKELETON_QUESTION_PHPBB_VERSION_MAX_EXPLAIN' => 'default: <' . \phpbb\skeleton\ext::DEFAULT_SKELETON_PHPBB_MAX, 'SKELETON_QUESTION_COMPONENT_PHPLISTENER' => 'Create sample PHP event listeners', 'SKELETON_QUESTION_COMPONENT_PHPLISTENER_UI' => 'PHP event listeners', diff --git a/tests/controller/main_test.php b/tests/controller/main_test.php index cb804f8..3a5ab30 100644 --- a/tests/controller/main_test.php +++ b/tests/controller/main_test.php @@ -146,7 +146,7 @@ public function test_handle($status_code, $page_content) ['vendor_name', '', true, \phpbb\request\request_interface::REQUEST, 'foo'], ['author_name', [''], true, \phpbb\request\request_interface::REQUEST, ['bar']], ['extension_version', '1.0.0-dev', true, \phpbb\request\request_interface::REQUEST, '1.0.0-dev'], - ['php_version', '>=' . ext::DEFAULT_PHP, false, \phpbb\request\request_interface::REQUEST, '>=' . ext::DEFAULT_PHP], + ['php_version', '>=' . ext::DEFAULT_SKELETON_PHP, false, \phpbb\request\request_interface::REQUEST, '>=' . ext::DEFAULT_SKELETON_PHP], ['component_phplistener', false, false, \phpbb\request\request_interface::REQUEST, true], ]); @@ -229,7 +229,7 @@ public function test_handle($status_code, $page_content) 'NAME' => 'php_version', 'DESC' => 'SKELETON_QUESTION_PHP_VERSION_UI', 'DESC_EXPLAIN' => 'SKELETON_QUESTION_PHP_VERSION_EXPLAIN', - 'VALUE' => '>=' . ext::DEFAULT_PHP, + 'VALUE' => '>=' . ext::DEFAULT_SKELETON_PHP, ]], ['requirement', [ 'NAME' => 'phpbb_version_min', diff --git a/tests/helper/packager_test.php b/tests/helper/packager_test.php index 7ffa987..e005a15 100644 --- a/tests/helper/packager_test.php +++ b/tests/helper/packager_test.php @@ -217,7 +217,7 @@ public function test_get_template_engine_returns_twig_instance() $user ); - $this->container->expects($this->exactly(2)) + $this->container->expects($this->once()) ->method('getParameter') ->with('core.cache_dir') ->willReturn(false);