Merge branch '4.4' into 5.0
* 4.4: Fixed translations file dumper behavior When set, get secret from config variable [FrameworkBundle] Set the parameter bag as resolved in ContainerLintCommand [SecurityBundle] Fix switch_user provider configuration handling
This commit is contained in:
commit
fb08d9c101
@ -20,6 +20,7 @@ use Symfony\Component\DependencyInjection\Compiler\CheckTypeDeclarationsPass;
|
||||
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag;
|
||||
|
||||
final class ContainerLintCommand extends Command
|
||||
{
|
||||
@ -71,7 +72,11 @@ final class ContainerLintCommand extends Command
|
||||
$buildContainer = \Closure::bind(function () { return $this->buildContainer(); }, $kernel, \get_class($kernel));
|
||||
$container = $buildContainer();
|
||||
} else {
|
||||
(new XmlFileLoader($container = new ContainerBuilder(), new FileLocator()))->load($kernel->getContainer()->getParameter('debug.container.dump'));
|
||||
(new XmlFileLoader($container = new ContainerBuilder($parameterBag = new EnvPlaceholderParameterBag()), new FileLocator()))->load($kernel->getContainer()->getParameter('debug.container.dump'));
|
||||
|
||||
$refl = new \ReflectionProperty($parameterBag, 'resolved');
|
||||
$refl->setAccessible(true);
|
||||
$refl->setValue($parameterBag, true);
|
||||
}
|
||||
|
||||
return $this->containerBuilder = $container;
|
||||
|
@ -24,19 +24,19 @@ class AnonymousFactory implements SecurityFactoryInterface
|
||||
public function create(ContainerBuilder $container, $id, $config, $userProvider, $defaultEntryPoint)
|
||||
{
|
||||
if (null === $config['secret']) {
|
||||
$firewall['anonymous']['secret'] = new Parameter('container.build_hash');
|
||||
$config['secret'] = new Parameter('container.build_hash');
|
||||
}
|
||||
|
||||
$listenerId = 'security.authentication.listener.anonymous.'.$id;
|
||||
$container
|
||||
->setDefinition($listenerId, new ChildDefinition('security.authentication.listener.anonymous'))
|
||||
->replaceArgument(1, $firewall['anonymous']['secret'])
|
||||
->replaceArgument(1, $config['secret'])
|
||||
;
|
||||
|
||||
$providerId = 'security.authentication.provider.anonymous.'.$id;
|
||||
$container
|
||||
->setDefinition($providerId, new ChildDefinition('security.authentication.provider.anonymous'))
|
||||
->replaceArgument(0, $firewall['anonymous']['secret'])
|
||||
->replaceArgument(0, $config['secret'])
|
||||
;
|
||||
|
||||
return [$providerId, $listenerId, $defaultEntryPoint];
|
||||
|
@ -676,7 +676,7 @@ class SecurityExtension extends Extension implements PrependExtensionInterface
|
||||
return $exceptionListenerId;
|
||||
}
|
||||
|
||||
private function createSwitchUserListener(ContainerBuilder $container, string $id, array $config, string $defaultProvider, bool $stateless): string
|
||||
private function createSwitchUserListener(ContainerBuilder $container, string $id, array $config, ?string $defaultProvider, bool $stateless): string
|
||||
{
|
||||
$userProvider = isset($config['provider']) ? $this->getUserProviderId($config['provider']) : $defaultProvider;
|
||||
|
||||
|
@ -389,6 +389,30 @@ class SecurityExtensionTest extends TestCase
|
||||
];
|
||||
}
|
||||
|
||||
public function testSwitchUserWithSeveralDefinedProvidersButNoFirewallRootProviderConfigured()
|
||||
{
|
||||
$container = $this->getRawContainer();
|
||||
$container->loadFromExtension('security', [
|
||||
'providers' => [
|
||||
'first' => ['id' => 'foo'],
|
||||
'second' => ['id' => 'bar'],
|
||||
],
|
||||
|
||||
'firewalls' => [
|
||||
'foobar' => [
|
||||
'switch_user' => [
|
||||
'provider' => 'second',
|
||||
],
|
||||
'anonymous' => true,
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$container->compile();
|
||||
|
||||
$this->assertEquals(new Reference('security.user.provider.concrete.second'), $container->getDefinition('security.authentication.switchuser_listener.foobar')->getArgument(1));
|
||||
}
|
||||
|
||||
protected function getRawContainer()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
@ -51,36 +51,37 @@ abstract class FileDumper implements DumperInterface
|
||||
throw new InvalidArgumentException('The file dumper needs a path option.');
|
||||
}
|
||||
|
||||
$hasMessageFormatter = class_exists(\MessageFormatter::class);
|
||||
|
||||
// save a file for each domain
|
||||
foreach ($messages->getDomains() as $domain) {
|
||||
$fullpath = $options['path'].'/'.$this->getRelativePath($domain, $messages->getLocale());
|
||||
if (!file_exists($fullpath)) {
|
||||
$directory = \dirname($fullpath);
|
||||
if ($hasMessageFormatter) {
|
||||
$defaultDomain = $domain.MessageCatalogue::INTL_DOMAIN_SUFFIX;
|
||||
$altDomain = $domain;
|
||||
} else {
|
||||
$defaultDomain = $domain;
|
||||
$altDomain = $domain.MessageCatalogue::INTL_DOMAIN_SUFFIX;
|
||||
}
|
||||
$defaultPath = $options['path'].'/'.$this->getRelativePath($defaultDomain, $messages->getLocale());
|
||||
$altPath = $options['path'].'/'.$this->getRelativePath($altDomain, $messages->getLocale());
|
||||
|
||||
if (!file_exists($defaultPath) && file_exists($altPath)) {
|
||||
[$defaultPath, $altPath] = [$altPath, $defaultPath];
|
||||
}
|
||||
|
||||
if (!file_exists($defaultPath)) {
|
||||
$directory = \dirname($defaultPath);
|
||||
if (!file_exists($directory) && !@mkdir($directory, 0777, true)) {
|
||||
throw new RuntimeException(sprintf('Unable to create directory "%s".', $directory));
|
||||
}
|
||||
}
|
||||
|
||||
$intlDomain = $domain.MessageCatalogue::INTL_DOMAIN_SUFFIX;
|
||||
$intlMessages = $messages->all($intlDomain);
|
||||
|
||||
if ($intlMessages) {
|
||||
$intlPath = $options['path'].'/'.$this->getRelativePath($intlDomain, $messages->getLocale());
|
||||
file_put_contents($intlPath, $this->formatCatalogue($messages, $intlDomain, $options));
|
||||
|
||||
$messages->replace([], $intlDomain);
|
||||
|
||||
try {
|
||||
if ($messages->all($domain)) {
|
||||
file_put_contents($fullpath, $this->formatCatalogue($messages, $domain, $options));
|
||||
}
|
||||
continue;
|
||||
} finally {
|
||||
$messages->replace($intlMessages, $intlDomain);
|
||||
}
|
||||
if (file_exists($altPath)) {
|
||||
// clear alternative translation file
|
||||
file_put_contents($altPath, $this->formatCatalogue(new MessageCatalogue($messages->getLocale()), $altDomain, $options));
|
||||
}
|
||||
|
||||
file_put_contents($fullpath, $this->formatCatalogue($messages, $domain, $options));
|
||||
file_put_contents($defaultPath, $this->formatCatalogue($messages, $domain, $options));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,11 +27,15 @@ class FileDumperTest extends TestCase
|
||||
$dumper = new ConcreteFileDumper();
|
||||
$dumper->dump($catalogue, ['path' => $tempDir]);
|
||||
|
||||
$this->assertFileExists($tempDir.'/messages.en.concrete');
|
||||
$suffix = class_exists(\MessageFormatter::class) ? '+intl-icu' : '';
|
||||
$this->assertFileExists($tempDir."/messages$suffix.en.concrete");
|
||||
|
||||
@unlink($tempDir.'/messages.en.concrete');
|
||||
@unlink($tempDir."/messages$suffix.en.concrete");
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires extension intl
|
||||
*/
|
||||
public function testDumpIntl()
|
||||
{
|
||||
$tempDir = sys_get_temp_dir();
|
||||
@ -42,13 +46,11 @@ class FileDumperTest extends TestCase
|
||||
$catalogue->add(['bar' => 'foo'], 'd2+intl-icu');
|
||||
|
||||
$dumper = new ConcreteFileDumper();
|
||||
@unlink($tempDir.'/d2.en.concrete');
|
||||
$dumper->dump($catalogue, ['path' => $tempDir]);
|
||||
|
||||
$this->assertStringEqualsFile($tempDir.'/d1.en.concrete', 'foo=bar');
|
||||
@unlink($tempDir.'/d1.en.concrete');
|
||||
$this->assertFileNotExists($tempDir.'/d1.en.concrete');
|
||||
|
||||
$this->assertStringEqualsFile($tempDir.'/d1+intl-icu.en.concrete', 'bar=foo');
|
||||
$this->assertStringEqualsFile($tempDir.'/d1+intl-icu.en.concrete', 'bar=foo&foo=bar');
|
||||
@unlink($tempDir.'/d1+intl-icu.en.concrete');
|
||||
|
||||
$this->assertFileNotExists($tempDir.'/d2.en.concrete');
|
||||
@ -60,7 +62,8 @@ class FileDumperTest extends TestCase
|
||||
{
|
||||
$tempDir = sys_get_temp_dir();
|
||||
$translationsDir = $tempDir.'/test/translations';
|
||||
$file = $translationsDir.'/messages.en.concrete';
|
||||
$suffix = class_exists(\MessageFormatter::class) ? '+intl-icu' : '';
|
||||
$file = $translationsDir."/messages$suffix.en.concrete";
|
||||
|
||||
$catalogue = new MessageCatalogue('en');
|
||||
$catalogue->add(['foo' => 'bar']);
|
||||
|
Reference in New Issue
Block a user