diff --git a/src/NewCommand.php b/src/NewCommand.php index 7af1dca..e0744ec 100644 --- a/src/NewCommand.php +++ b/src/NewCommand.php @@ -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?', @@ -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. *