Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the Doctrine platform recognition #1010

Merged
merged 1 commit into from
Nov 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
102 changes: 97 additions & 5 deletions manager-bundle/src/ContaoManager/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,29 @@ public function getExtensionConfig($extensionName, array $extensionConfigs, Plug
case 'contao':
return $this->handlePrependLocale($extensionConfigs, $container);

case 'framework':
if (!isset($_SERVER['APP_SECRET'])) {
$container->setParameter('env(APP_SECRET)', $container->getParameter('secret'));
}

return $extensionConfigs;

case 'doctrine':
if (!isset($_SERVER['DATABASE_URL'])) {
$container->setParameter('env(DATABASE_URL)', $this->getDatabaseUrl($container));
}

return $this->addDefaultServerVersion($extensionConfigs, $container);

default:
return $extensionConfigs;
case 'swiftmailer':
if (!isset($_SERVER['MAILER_URL'])) {
$container->setParameter('env(MAILER_URL)', $this->getMailerUrl($container));
}

return $this->checkMailerTransport($extensionConfigs, $container);
}

return $extensionConfigs;
}

/**
Expand Down Expand Up @@ -291,10 +308,8 @@ private function addDefaultServerVersion(array $extensionConfigs, ContainerBuild
$params = array_merge(...$params);
}

$parameterBag = $container->getParameterBag();

foreach ($params as $key => $value) {
$params[$key] = $parameterBag->resolveValue($value);
$params[$key] = $container->resolveEnvPlaceholders($value, true);
}

// If there are no DB credentials yet (install tool), we have to set
Expand All @@ -317,4 +332,81 @@ private function addDefaultServerVersion(array $extensionConfigs, ContainerBuild

return $extensionConfigs;
}

/**
* Changes the mail transport from "mail" to "sendmail".
*
* @return array<string,array<string,array<string,array<string,mixed>>>>
*/
private function checkMailerTransport(array $extensionConfigs, ContainerBuilder $container): array
{
if ('mail' === $container->getParameter('mailer_transport')) {
$container->setParameter('mailer_transport', 'sendmail');
}

return $extensionConfigs;
}

private function getDatabaseUrl(ContainerBuilder $container): string
{
$userPassword = '';

if ($user = $container->getParameter('database_user')) {
$userPassword = $user;

if ($password = $container->getParameter('database_password')) {
$userPassword .= ':'.$password;
}

$userPassword .= '@';
}

$dbName = '';

if ($name = $container->getParameter('database_name')) {
$dbName = '/'.$name;
}

return sprintf(
'mysql://%s%s:%s%s',
$userPassword,
$container->getParameter('database_host'),
$container->getParameter('database_port'),
$dbName
);
}

private function getMailerUrl(ContainerBuilder $container): string
{
if ('sendmail' === $container->getParameter('mailer_transport')) {
return 'sendmail://localhost';
}

$parameters = [];

if ($user = $container->getParameter('mailer_user')) {
$parameters[] = 'username='.rawurlencode($user);

if ($password = $container->getParameter('mailer_password')) {
$parameters[] = 'password='.rawurlencode($password);
}
}

if ($encryption = $container->getParameter('mailer_encryption')) {
$parameters[] = 'encryption='.rawurlencode($encryption);
}

$qs = '';

if (!empty($parameters)) {
$qs = '?'.implode('&', $parameters);
}

return sprintf(
'smtp://%s:%s%s',
rawurlencode($container->getParameter('mailer_host')),
(int) $container->getParameter('mailer_port'),
$qs
);
}
}
2 changes: 0 additions & 2 deletions manager-bundle/src/ContaoManagerBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
namespace Contao\ManagerBundle;

use Contao\ManagerBundle\DependencyInjection\Compiler\ContaoManagerPass;
use Contao\ManagerBundle\DependencyInjection\Compiler\ParametersYamlPass;
use Symfony\Component\Console\Application;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
Expand All @@ -28,7 +27,6 @@ public function build(ContainerBuilder $container): void
parent::build($container);

$container->addCompilerPass(new ContaoManagerPass());
$container->addCompilerPass(new ParametersYamlPass());
}

/**
Expand Down
117 changes: 0 additions & 117 deletions manager-bundle/src/DependencyInjection/Compiler/ParametersYamlPass.php

This file was deleted.