Skip to content

Commit 09627d3

Browse files
crynoboneStyleCIBottaylorotwell
authored
[5.x] Throw exceptions when trying to use Installer on PHP environment without required extensions (#373)
* [5.x] Add polyfill for `mb_rtrim()` for PHP 8.3 and below Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * Apply fixes from StyleCI * remove example extension Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * formatting * remove test * Apply fixes from StyleCI --------- Signed-off-by: Mior Muhammad Zaki <[email protected]> Co-authored-by: StyleCI Bot <[email protected]> Co-authored-by: Taylor Otwell <[email protected]>
1 parent ebdd1d1 commit 09627d3

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/NewCommand.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ protected function interact(InputInterface $input, OutputInterface $output)
8585
| |___| (_| | | | (_| |\ V / __/ |
8686
|______\__,_|_| \__,_| \_/ \___|_|</>'.PHP_EOL.PHP_EOL);
8787

88+
$this->ensureExtensionsAreAvailable($input, $output);
89+
8890
if (! $input->getArgument('name')) {
8991
$input->setArgument('name', text(
9092
label: 'What is the name of your project?',
@@ -147,6 +149,38 @@ protected function interact(InputInterface $input, OutputInterface $output)
147149
// }
148150
}
149151

152+
/**
153+
* Ensure that the required PHP extensions are installed.
154+
*
155+
* @param \Symfony\Component\Console\Input\InputInterface $input
156+
* @param \Symfony\Component\Console\Output\OutputInterface $output
157+
* @return void
158+
*
159+
* @throws \RuntimeException
160+
*/
161+
protected function ensureExtensionsAreAvailable(InputInterface $input, OutputInterface $output): void
162+
{
163+
$availableExtensions = get_loaded_extensions();
164+
165+
$missingExtensions = collect([
166+
'ctype',
167+
'filter',
168+
'hash',
169+
'mbstring',
170+
'openssl',
171+
'session',
172+
'tokenizer',
173+
])->reject(fn ($extension) => in_array($extension, $availableExtensions));
174+
175+
if ($missingExtensions->isEmpty()) {
176+
return;
177+
}
178+
179+
throw new \RuntimeException(
180+
sprintf('The following PHP extensions are required but are not installed: %s', $missingExtensions->join(', ', ', and '))
181+
);
182+
}
183+
150184
/**
151185
* Execute the command.
152186
*

0 commit comments

Comments
 (0)