installation-bundle/src/Controller/InstallationController.php
private function setUpDatabaseConnection(): Response
    {
        $request = $this->container->get('request_stack')->getCurrentRequest();

        if (null === $request) {
            throw new \RuntimeException('The request stack did not contain a request');
        }

        // Only warn the user if the connection fails and the env component is used
        if (false !== getenv('DATABASE_URL')) {
            return $this->render('misconfigured_database_url.html.twig');
        }

        $parameters = [
            'parameters' => [
                'database_host' => $this->getContainerParameter('database_host'),
                'database_port' => $this->getContainerParameter('database_port'),
                'database_user' => $this->getContainerParameter('database_user'),
                'database_password' => $this->getContainerParameter('database_password'),
                'database_name' => $this->getContainerParameter('database_name'),
            ],
        ];

        if ('tl_database_login' !== $request->request->get('FORM_SUBMIT')) {
            return $this->render('database.html.twig', $parameters);
        }

        $parameters = [
            'parameters' => [
                'database_host' => $request->request->get('dbHost'),
                'database_port' => $request->request->get('dbPort'),
                'database_user' => $request->request->get('dbUser'),
                'database_password' => $this->getContainerParameter('database_password'),
                'database_name' => $request->request->get('dbName'),
            ],
        ];

        if ('*****' !== $request->request->get('dbPassword')) {
            $parameters['parameters']['database_password'] = $request->request->get('dbPassword');
        }

        if (false !== strpos($parameters['parameters']['database_name'], '.')) {
            return $this->render('database.html.twig', array_merge(
                $parameters,
                ['database_error' => $this->trans('database_dot_in_dbname')]
            ));
        }

        $installTool = $this->container->get('contao.install_tool');
        $installTool->setConnection(ConnectionFactory::create($parameters));

        if (!$installTool->canConnectToDatabase($parameters['parameters']['database_name'])) {
            return $this->render('database.html.twig', array_merge(
                $parameters,
                ['database_error' => $this->trans('database_could_not_connect')]
            ));
        }

        $dumper = new ParameterDumper($this->getContainerParameter('kernel.project_dir'));
        $dumper->setParameters($parameters);
        $dumper->dump();

        $this->purgeSymfonyCache();

        return $this->getRedirectResponse();
    }
private function setUpDatabaseConnection(): Response
    {
        $request = $this->container->get('request_stack')->getCurrentRequest();

        if (null === $request) {
            throw new \RuntimeException('The request stack did not contain a request');
        }

        // Only warn the user if the connection fails and the env component is used
        if (false !== getenv('DATABASE_URL')) {
            return $this->render('misconfigured_database_url.html.twig');
        }

        $parameters = [
            'parameters' => [
                'database_host' => $this->getContainerParameter('database_host'),
                'database_port' => $this->getContainerParameter('database_port'),
                'database_user' => $this->getContainerParameter('database_user'),
                'database_password' => $this->getContainerParameter('database_password'),
                'database_name' => $this->getContainerParameter('database_name'),
            ],
        ];

        if ('tl_database_login' !== $request->request->get('FORM_SUBMIT')) {
            return $this->render('database.html.twig', $parameters);
        }

        $parameters = [
            'parameters' => [
                'database_host' => $request->request->get('dbHost'),
                'database_port' => $request->request->get('dbPort'),
                'database_user' => $request->request->get('dbUser'),
                'database_password' => $this->getContainerParameter('database_password'),
                'database_name' => $request->request->get('dbName'),
            ],
        ];

        if ('*****' !== $request->request->get('dbPassword')) {
            $parameters['parameters']['database_password'] = $request->request->get('dbPassword');
        }

        if (false !== strpos($parameters['parameters']['database_name'], '.')) {
            return $this->render('database.html.twig', array_merge(
                $parameters,
                ['database_error' => $this->trans('database_dot_in_dbname')]
            ));
        }

        $installTool = $this->container->get('contao.install_tool');
        $installTool->setConnection(ConnectionFactory::create($parameters));

        if (!$installTool->canConnectToDatabase($parameters['parameters']['database_name'])) {
            return $this->render('database.html.twig', array_merge(
                $parameters,
                ['database_error' => $this->trans('database_could_not_connect')]
            ));
        }

        $dumper = new ParameterDumper($this->getContainerParameter('kernel.project_dir'));
        $dumper->setParameters($parameters);
        $dumper->dump();

        $this->purgeSymfonyCache();

        return $this->getRedirectResponse();
    }
Renders a form to set up the database connection.

@throws \RuntimeException

@return Response|RedirectResponse