You are here

protected function InstallCommand::validateProfile in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Command/InstallCommand.php \Drupal\Core\Command\InstallCommand::validateProfile()

Validates a user provided install profile.

Parameters

string $install_profile: Install profile to validate.

\Symfony\Component\Console\Style\SymfonyStyle $io: Symfony style output decorator.

Return value

bool TRUE if the profile is valid, FALSE if not.

1 call to InstallCommand::validateProfile()
InstallCommand::execute in core/lib/Drupal/Core/Command/InstallCommand.php

File

core/lib/Drupal/Core/Command/InstallCommand.php, line 284

Class

InstallCommand
Installs a Drupal site for local testing/development.

Namespace

Drupal\Core\Command

Code

protected function validateProfile($install_profile, SymfonyStyle $io) {

  // Allow people to install hidden and non-distribution profiles if they
  // supply the argument.
  $profiles = $this
    ->getProfiles(TRUE, FALSE);
  if (!isset($profiles[$install_profile])) {
    $error_msg = sprintf("'%s' is not a valid install profile.", $install_profile);
    $alternatives = [];
    foreach (array_keys($profiles) as $profile_name) {
      $lev = levenshtein($install_profile, $profile_name);
      if ($lev <= strlen($profile_name) / 4 || FALSE !== strpos($profile_name, $install_profile)) {
        $alternatives[] = $profile_name;
      }
    }
    if (!empty($alternatives)) {
      $error_msg .= sprintf(" Did you mean '%s'?", implode("' or '", $alternatives));
    }
    $io
      ->getErrorStyle()
      ->error($error_msg);
    return FALSE;
  }
  return TRUE;
}