Skip to content

Commit 77eb509

Browse files
authored
Merge pull request #168 from iMattPro/enhanced-cli
UI improvements
2 parents d5e619f + 417e652 commit 77eb509

File tree

4 files changed

+85
-14
lines changed

4 files changed

+85
-14
lines changed

console/create.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,47 @@ protected function interact(InputInterface $input, OutputInterface $output)
114114

115115
$this->helper = $this->getHelper('question');
116116

117+
$this->display_banner();
118+
117119
$output->writeln($this->language->lang('SKELETON_CLI_COMPOSER_QUESTIONS'));
118120
$this->get_composer_data();
119121

120122
$output->writeln($this->language->lang('SKELETON_CLI_COMPONENT_QUESTIONS'));
121123
$this->get_component_data();
122124
}
123125

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

ext.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ class ext extends \phpbb\extension\base
2121

2222
public const MIN_PHPBB_ALLOWED = '3.3.0';
2323
public const MAX_PHPBB_ALLOWED = '4.0.0-dev';
24-
public const MIN_PHP_ALLOWED = 70100;
24+
public const MIN_PHP_ALLOWED = '7.1.0';
25+
public const MIN_PHP_ID_ALLOWED = 70100;
2526

2627
/**
2728
* @var array An array of installation error messages
@@ -53,11 +54,11 @@ protected function phpbb_requirement($phpBB_version = PHPBB_VERSION)
5354
{
5455
if (phpbb_version_compare($phpBB_version, self::MIN_PHPBB_ALLOWED, '<'))
5556
{
56-
$this->errors[] = 'PHPBB_VERSION_MIN_ERROR';
57+
$this->errors[] = ['PHPBB_VERSION_MIN_ERROR', self::MIN_PHPBB_ALLOWED, $phpBB_version];
5758
}
5859
else if (phpbb_version_compare($phpBB_version, self::MAX_PHPBB_ALLOWED, '>='))
5960
{
60-
$this->errors[] = 'PHPBB_VERSION_MAX_ERROR';
61+
$this->errors[] = ['PHPBB_VERSION_MAX_ERROR', self::MAX_PHPBB_ALLOWED, $phpBB_version];
6162
}
6263
}
6364

@@ -69,9 +70,9 @@ protected function phpbb_requirement($phpBB_version = PHPBB_VERSION)
6970
*/
7071
protected function php_requirement($php_version = PHP_VERSION_ID)
7172
{
72-
if ($php_version < self::MIN_PHP_ALLOWED)
73+
if ($php_version < self::MIN_PHP_ID_ALLOWED)
7374
{
74-
$this->errors[] = 'PHP_VERSION_ERROR';
75+
$this->errors[] = ['PHP_VERSION_MIN_ERROR', self::MIN_PHP_ALLOWED, PHP_VERSION];
7576
}
7677
}
7778

@@ -101,7 +102,9 @@ protected function enable_failed()
101102
{
102103
$language = $this->container->get('language');
103104
$language->add_lang('common', 'phpbb/skeleton');
104-
return array_map([$language, 'lang'], $this->errors);
105+
return array_map(static function ($error) use ($language) {
106+
return is_array($error) ? call_user_func_array([$language, 'lang'], $error) : $language->lang($error);
107+
}, $this->errors);
105108
}
106109

107110
return false;

language/en/common.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
'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>].',
2929
'PHPBB_SKELETON_EXT_HELP' => 'Learn More',
3030

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

163-
'NO_ZIPARCHIVE_ERROR' => 'The ZipArchive class is required, but was not found in your PHP configuration.',
164-
'PHP_VERSION_ERROR' => 'PHP 5.6 or newer is required to use this extension.',
165-
'PHPBB_VERSION_MIN_ERROR' => 'phpBB 3.2.3 or newer is required to use this extension.',
166-
'PHPBB_VERSION_MAX_ERROR' => 'phpBB 4 is not supported with this version of the extension. Please check for a newer version of this extension.'
165+
'NO_ZIPARCHIVE_ERROR' => 'The ZipArchive class is required, but was not found in your PHP configuration.',
166+
'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.',
167+
'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.',
168+
'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.'
167169
]);

tests/ext_test.php

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,32 +97,57 @@ public function test_enable_failed_returns_expected()
9797
$this->assertEquals(['LANG: SOME_ERROR'], $method->invoke($ext));
9898
}
9999

100+
public function test_enable_failed_returns_parameterized_error()
101+
{
102+
$ext = $this->getMockBuilder(ext::class)
103+
->disableOriginalConstructor()
104+
->getMock();
105+
106+
$this->setExtErrors($ext, [['PHP_VERSION_MIN_ERROR', '7.1.0', '5.5.0']]);
107+
108+
$languageMock = $this->createMock(language::class);
109+
$languageMock->method('add_lang')->willReturn(null);
110+
$languageMock->method('lang')->willReturnCallback(function (...$args) {
111+
return implode(':', $args);
112+
});
113+
114+
$containerMock = $this->createMock(ContainerInterface::class);
115+
$containerMock->method('get')->with('language')->willReturn($languageMock);
116+
117+
$this->setProperty($ext, 'container', $containerMock);
118+
119+
$method = (new \ReflectionClass($ext))->getMethod('enable_failed');
120+
$method->setAccessible(true);
121+
122+
$this->assertEquals(['PHP_VERSION_MIN_ERROR:7.1.0:5.5.0'], $method->invoke($ext));
123+
}
124+
100125
public function test_phpbb_requirement_min_error()
101126
{
102127
$this->setExtErrors($this->ext, []);
103128
$this->invokeProtectedMethod($this->ext, 'phpbb_requirement', ['3.2.2']);
104-
$this->assertContains('PHPBB_VERSION_MIN_ERROR', $this->getExtErrors($this->ext));
129+
$this->assertContains('PHPBB_VERSION_MIN_ERROR', $this->getExtErrorKeys($this->ext));
105130
}
106131

107132
public function test_phpbb_requirement_max_error()
108133
{
109134
$this->setExtErrors($this->ext, []);
110135
$this->invokeProtectedMethod($this->ext, 'phpbb_requirement', ['4.0.0-dev']);
111-
$this->assertContains('PHPBB_VERSION_MAX_ERROR', $this->getExtErrors($this->ext));
136+
$this->assertContains('PHPBB_VERSION_MAX_ERROR', $this->getExtErrorKeys($this->ext));
112137
}
113138

114139
public function test_php_requirement_error()
115140
{
116141
$this->setExtErrors($this->ext, []);
117142
$this->invokeProtectedMethod($this->ext, 'php_requirement', [50500]);
118-
$this->assertContains('PHP_VERSION_ERROR', $this->getExtErrors($this->ext));
143+
$this->assertContains('PHP_VERSION_MIN_ERROR', $this->getExtErrorKeys($this->ext));
119144
}
120145

121146
public function test_ziparchive_exists_error()
122147
{
123148
$this->setExtErrors($this->ext, []);
124149
$this->invokeProtectedMethod($this->ext, 'ziparchive_exists', ['NotZipArchive']);
125-
$this->assertContains('NO_ZIPARCHIVE_ERROR', $this->getExtErrors($this->ext));
150+
$this->assertContains('NO_ZIPARCHIVE_ERROR', $this->getExtErrorKeys($this->ext));
126151
}
127152

128153
// --- Helpers ---
@@ -141,6 +166,13 @@ protected function getExtErrors($ext): array
141166
return $prop->getValue($ext);
142167
}
143168

169+
protected function getExtErrorKeys($ext): array
170+
{
171+
return array_map(static function ($e) {
172+
return is_array($e) ? $e[0] : $e;
173+
}, $this->getExtErrors($ext));
174+
}
175+
144176
protected function setExtErrors($ext, array $errors): void
145177
{
146178
$prop = (new \ReflectionClass($ext))->getProperty('errors');

0 commit comments

Comments
 (0)