Skip to content

Commit

Permalink
[5.x] Throw exceptions when trying to use Installer on PHP environmen…
Browse files Browse the repository at this point in the history
…t 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]>
  • Loading branch information
3 people authored Dec 11, 2024
1 parent ebdd1d1 commit 09627d3
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/NewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ protected function interact(InputInterface $input, OutputInterface $output)
| |___| (_| | | | (_| |\ V / __/ |
|______\__,_|_| \__,_| \_/ \___|_|</>'.PHP_EOL.PHP_EOL);

$this->ensureExtensionsAreAvailable($input, $output);

if (! $input->getArgument('name')) {
$input->setArgument('name', text(
label: 'What is the name of your project?',
Expand Down Expand Up @@ -147,6 +149,38 @@ protected function interact(InputInterface $input, OutputInterface $output)
// }
}

/**
* Ensure that the required PHP extensions are installed.
*
* @param \Symfony\Component\Console\Input\InputInterface $input
* @param \Symfony\Component\Console\Output\OutputInterface $output
* @return void
*
* @throws \RuntimeException
*/
protected function ensureExtensionsAreAvailable(InputInterface $input, OutputInterface $output): void
{
$availableExtensions = get_loaded_extensions();

$missingExtensions = collect([
'ctype',
'filter',
'hash',
'mbstring',
'openssl',
'session',
'tokenizer',
])->reject(fn ($extension) => in_array($extension, $availableExtensions));

if ($missingExtensions->isEmpty()) {
return;
}

throw new \RuntimeException(
sprintf('The following PHP extensions are required but are not installed: %s', $missingExtensions->join(', ', ', and '))
);
}

/**
* Execute the command.
*
Expand Down

0 comments on commit 09627d3

Please sign in to comment.