Skip to content

Commit 7584145

Browse files
committed
Merge branch 'master' into dev/4.0
2 parents 117dedf + 77eb509 commit 7584145

File tree

4 files changed

+97
-13
lines changed

4 files changed

+97
-13
lines changed

console/create.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,47 @@ protected function interact(InputInterface $input, OutputInterface $output): voi
120120
}
121121
$this->helper = $helper;
122122

123+
$this->display_banner();
124+
123125
$output->writeln($this->language->lang('SKELETON_CLI_COMPOSER_QUESTIONS'));
124126
$this->get_composer_data();
125127

126128
$output->writeln($this->language->lang('SKELETON_CLI_COMPONENT_QUESTIONS'));
127129
$this->get_component_data();
128130
}
129131

132+
/**
133+
* Display a colorful ASCII art title banner.
134+
*/
135+
protected function display_banner(): void
136+
{
137+
$title_lines = [
138+
[' _____ __ __ __ ', 'cyan'],
139+
[' / ___// /_____ / /__ / /_____ ____ ', 'cyan'],
140+
[' \__ \/ //_/ _ \/ / _ \/ __/ __ \/ __ \ ', 'blue'],
141+
[' ___/ / ,< / __/ / __/ /_/ /_/ / / / / ', 'blue'],
142+
[' /____/_/|_|\___/_/\___/\__/\____/_/ /_/ ', 'magenta'],
143+
[' ______ __ _ ', 'magenta'],
144+
[' / ____/ __/ /____ ____ _____(_)___ ____ ', 'red'],
145+
[' / __/ | |/_/ __/ _ \/ __ \/ ___/ / __ \/ __ \ ', 'red'],
146+
[' / /____> </ /_/ __/ / / (__ ) / /_/ / / / / ', 'yellow'],
147+
['/_____/_/|_|\__/\___/_/ /_/____/_/\____/_/ /_/ ', 'yellow'],
148+
];
149+
150+
$desc = $this->language->lang('SKELETON_CLI_BANNER_DESC');
151+
$line = str_repeat('', 50);
152+
153+
$this->output->writeln('');
154+
foreach ($title_lines as [$text, $color])
155+
{
156+
$this->output->writeln("<fg=$color;options=bold>$text</>");
157+
}
158+
$this->output->writeln('');
159+
$this->output->writeln("<fg=cyan> $desc </>");
160+
$this->output->writeln("<fg=white>$line</>");
161+
$this->output->writeln('');
162+
}
163+
130164
/**
131165
* Get composer data from the user
132166
*/

ext.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ class ext extends base
2222
public const DEFAULT_SKELETON_PHPBB_MAX = '4.0.0@dev';
2323

2424
public const MIN_PHPBB_ALLOWED = '4.0.0-dev';
25-
public const MIN_PHP_ALLOWED = 80100;
25+
public const MAX_PHPBB_ALLOWED = '5.0.0-dev';
26+
public const MIN_PHP_ALLOWED = '8.1.0';
27+
public const MIN_PHP_ID_ALLOWED = 80100;
2628

2729
/**
2830
* @var array An array of installation error messages
@@ -54,7 +56,11 @@ protected function phpbb_requirement(string $phpBB_version = PHPBB_VERSION): voi
5456
{
5557
if (phpbb_version_compare($phpBB_version, self::MIN_PHPBB_ALLOWED, '<'))
5658
{
57-
$this->errors[] = 'PHPBB_VERSION_ERROR';
59+
$this->errors[] = ['PHPBB_VERSION_MIN_ERROR', self::MIN_PHPBB_ALLOWED, $phpBB_version];
60+
}
61+
else if (phpbb_version_compare($phpBB_version, self::MAX_PHPBB_ALLOWED, '>='))
62+
{
63+
$this->errors[] = ['PHPBB_VERSION_MAX_ERROR', self::MAX_PHPBB_ALLOWED, $phpBB_version];
5864
}
5965
}
6066

@@ -66,9 +72,9 @@ protected function phpbb_requirement(string $phpBB_version = PHPBB_VERSION): voi
6672
*/
6773
protected function php_requirement(int $php_version = PHP_VERSION_ID): void
6874
{
69-
if ($php_version < self::MIN_PHP_ALLOWED)
75+
if ($php_version < self::MIN_PHP_ID_ALLOWED)
7076
{
71-
$this->errors[] = 'PHP_VERSION_ERROR';
77+
$this->errors[] = ['PHP_VERSION_MIN_ERROR', self::MIN_PHP_ALLOWED, PHP_VERSION];
7278
}
7379
}
7480

@@ -98,7 +104,9 @@ protected function enable_failed(): array|bool
98104
{
99105
$language = $this->container->get('language');
100106
$language->add_lang('common', 'phpbb/skeleton');
101-
return array_map([$language, 'lang'], $this->errors);
107+
return array_map(static function ($error) use ($language) {
108+
return is_array($error) ? call_user_func_array([$language, 'lang'], $error) : $language->lang($error);
109+
}, $this->errors);
102110
}
103111

104112
return false;

language/en/common.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
'PHPBB_CREATE_SKELETON_EXPLAIN' => 'Generate your extension’s foundation in seconds. No more setting up files by hand — Skeleton builds it all for you, with clean, fully documented templates based on phpBB’s best practices. Before you begin, be sure to review the 📖 [<a href="%1$s" target="_blank">Skeleton Extension Documentation</a>], 🛡️ [<a href="%2$s" target="_blank">Extension Validation Rules</a>], and 🛠️ [<a href="%3$s" target="_blank">Coding Guidelines</a>].',
3131
'PHPBB_SKELETON_EXT_HELP' => 'Learn More',
3232

33+
'SKELETON_CLI_BANNER_DESC' => 'The official phpBB skeleton extension generator',
34+
3335
'EXTENSION_CLI_SKELETON_SUCCESS' => "<info>Extension created successfully.\nCopy the extension from `store/tmp-ext/` into the `ext/` folder.</info>",
3436
'SKELETON_CLI_COMPOSER_QUESTIONS' => '<comment>Enter composer.json details (hit enter to leave an option empty)</comment>',
3537
'SKELETON_CLI_COMPONENT_QUESTIONS' => '<comment>Install optional components. Default: No; [y/n]</comment>',
@@ -162,7 +164,8 @@
162164
'SKELETON_INVALID_PHPBB_MIN_VERSION'=> 'The minimum phpBB version requirement is invalid.',
163165
'SKELETON_INVALID_PHPBB_MAX_VERSION'=> 'The maximum phpBB version requirement is invalid.',
164166

165-
'NO_ZIPARCHIVE_ERROR' => 'The ZipArchive class is required, but was not found in your PHP configuration.',
166-
'PHP_VERSION_ERROR' => 'PHP 8.1 or newer is required to use this extension.',
167-
'PHPBB_VERSION_ERROR' => 'phpBB 4.0.0-dev or newer is required to use this extension.',
167+
'NO_ZIPARCHIVE_ERROR' => 'The ZipArchive class is required, but was not found in your PHP configuration.',
168+
'PHP_VERSION_MIN_ERROR' => 'PHP %1$s or newer is required to install this version of the Skeleton Extension. You are using PHP %2$s.',
169+
'PHPBB_VERSION_MIN_ERROR' => 'phpBB %1$s or newer is required to install this version of the Skeleton Extension. You are using phpBB %2$s.',
170+
'PHPBB_VERSION_MAX_ERROR' => 'phpBB %1$s or above is not supported by this version of the Skeleton Extension. You are using phpBB %2$s. Please check for a newer version of this extension.'
168171
]);

tests/ext_test.php

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,25 +87,57 @@ public function test_enable_failed_returns_expected(): void
8787
$this->assertEquals(['LANG: SOME_ERROR'], $method->invoke($ext));
8888
}
8989

90-
public function test_phpbb_requirement_min_error(): void
90+
public function test_enable_failed_returns_parameterized_error()
91+
{
92+
$ext = $this->getMockBuilder(ext::class)
93+
->disableOriginalConstructor()
94+
->getMock();
95+
96+
$this->setExtErrors($ext, [['PHP_VERSION_MIN_ERROR', '7.1.0', '5.5.0']]);
97+
98+
$languageMock = $this->createMock(language::class);
99+
$languageMock->method('add_lang')->willReturn(null);
100+
$languageMock->method('lang')->willReturnCallback(function (...$args) {
101+
return implode(':', $args);
102+
});
103+
104+
$containerMock = $this->createMock(ContainerInterface::class);
105+
$containerMock->method('get')->with('language')->willReturn($languageMock);
106+
107+
$this->setProperty($ext, 'container', $containerMock);
108+
109+
$method = (new \ReflectionClass($ext))->getMethod('enable_failed');
110+
$method->setAccessible(true);
111+
112+
$this->assertEquals(['PHP_VERSION_MIN_ERROR:7.1.0:5.5.0'], $method->invoke($ext));
113+
}
114+
115+
public function test_phpbb_requirement_min_error()
91116
{
92117
$this->setExtErrors($this->ext, []);
93118
$this->invokeProtectedMethod($this->ext, 'phpbb_requirement', ['3.2.2']);
94-
$this->assertContains('PHPBB_VERSION_ERROR', $this->getExtErrors($this->ext));
119+
$this->assertContains('PHPBB_VERSION_MIN_ERROR', $this->getExtErrorKeys($this->ext));
120+
}
121+
122+
public function test_phpbb_requirement_max_error()
123+
{
124+
$this->setExtErrors($this->ext, []);
125+
$this->invokeProtectedMethod($this->ext, 'phpbb_requirement', ['4.0.0-dev']);
126+
$this->assertContains('PHPBB_VERSION_MAX_ERROR', $this->getExtErrorKeys($this->ext));
95127
}
96128

97-
public function test_php_requirement_error(): void
129+
public function test_php_requirement_error()
98130
{
99131
$this->setExtErrors($this->ext, []);
100132
$this->invokeProtectedMethod($this->ext, 'php_requirement', [50500]);
101-
$this->assertContains('PHP_VERSION_ERROR', $this->getExtErrors($this->ext));
133+
$this->assertContains('PHP_VERSION_MIN_ERROR', $this->getExtErrorKeys($this->ext));
102134
}
103135

104136
public function test_ziparchive_exists_error(): void
105137
{
106138
$this->setExtErrors($this->ext, []);
107139
$this->invokeProtectedMethod($this->ext, 'ziparchive_exists', ['NotZipArchive']);
108-
$this->assertContains('NO_ZIPARCHIVE_ERROR', $this->getExtErrors($this->ext));
140+
$this->assertContains('NO_ZIPARCHIVE_ERROR', $this->getExtErrorKeys($this->ext));
109141
}
110142

111143
// --- Helpers ---
@@ -120,6 +152,13 @@ protected function getExtErrors($ext): array
120152
return (new ReflectionClass($ext))->getProperty('errors')->getValue($ext);
121153
}
122154

155+
protected function getExtErrorKeys($ext): array
156+
{
157+
return array_map(static function ($e) {
158+
return is_array($e) ? $e[0] : $e;
159+
}, $this->getExtErrors($ext));
160+
}
161+
123162
protected function setExtErrors($ext, array $errors): void
124163
{
125164
$prop = (new ReflectionClass($ext))->getProperty('errors');

0 commit comments

Comments
 (0)