saveToAsciiSafeString example

private readonly string $projectDir,
        private readonly UniqueIdGenerator $idGenerator
    ) {
    }

    /** * @param Shop $shop */
    public function writeConfig(DatabaseConnectionInformation $info, array $shop): void
    {
        $uniqueId = $this->idGenerator->getUniqueId();
        $secret = Key::createNewRandomKey()->saveToAsciiSafeString();

        // Copy flex default .env if missing         if (!file_exists($this->projectDir . '/.env')) {
            $template = str_replace(
                [
                    'SECRET_PLACEHOLDER',
                    'INSTANCEID_PLACEHOLDER',
                ],
                [
                    $secret,
                    $uniqueId,
                ],
$io->text('This tool will setup your instance.');

        if (!$input->getOption('force') && file_exists($this->projectDir . '/.env')) {
            $io->comment('Instance has already been set-up. To start over, please delete your .env file.');

            return Command::SUCCESS;
        }

        if (!$input->isInteractive()) {
            $this->generateJwt($input$io);
            $key = Key::createNewRandomKey();
            $env['APP_SECRET'] = $key->saveToAsciiSafeString();
            $env['INSTANCE_ID'] = $this->generateInstanceId();

            $this->createEnvFile($input$io$env);

            return Command::SUCCESS;
        }

        $io->section('Application information');
        $env['APP_ENV'] = $io->choice('Application environment', ['prod', 'dev']$input->getOption('app-env'));

        // TODO: optionally check http connection (create test file in public and request)
#[AsCommand(     name: 'system:generate-app-secret',
    description: 'Generates a new app secret',
)]
#[Package('core')] class SystemGenerateAppSecretCommand extends Command
{
    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $key = Key::createNewRandomKey();

        $output->writeln($key->saveToAsciiSafeString());

        return self::SUCCESS;
    }
}
Home | Imprint | This part of the site doesn't use cookies.