Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move configuration to PHP
Browse files Browse the repository at this point in the history
core23 committed Jul 4, 2020

Verified

This commit was signed with the committer’s verified signature.
snyk-bot Snyk bot
1 parent c6da880 commit e1d1959
Showing 27 changed files with 592 additions and 252 deletions.
27 changes: 14 additions & 13 deletions src/DependencyInjection/NucleosUserExtension.php
Original file line number Diff line number Diff line change
@@ -19,10 +19,11 @@
use Nucleos\UserBundle\Util\TokenGeneratorInterface;
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Loader\FileLoader;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

@@ -59,14 +60,14 @@ public function load(array $configs, ContainerBuilder $container): void

$config = $processor->processConfiguration($configuration, $configs);

$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));

if ('custom' !== $config['db_driver']) {
if (isset(self::$doctrineDrivers[$config['db_driver']])) {
$loader->load('doctrine.xml');
$loader->load('doctrine.php');
$container->setAlias('nucleos_user.doctrine_registry', new Alias(self::$doctrineDrivers[$config['db_driver']]['registry'], false));
} else {
$loader->load(sprintf('%s.xml', $config['db_driver']));
$loader->load(sprintf('%s.php', $config['db_driver']));
}
$container->setParameter($this->getAlias().'.backend_type_'.$config['db_driver'], true);
}
@@ -77,7 +78,7 @@ public function load(array $configs, ContainerBuilder $container): void
}

foreach (['validator', 'security', 'util', 'mailer', 'listeners', 'commands'] as $basename) {
$loader->load(sprintf('%s.xml', $basename));
$loader->load(sprintf('%s.php', $basename));
}

if (!$config['use_authentication_listener']) {
@@ -86,7 +87,7 @@ public function load(array $configs, ContainerBuilder $container): void

if ($config['use_flash_notifications']) {
$this->sessionNeeded = true;
$loader->load('flash_notifications.xml');
$loader->load('flash_notifications.php');
}

$container->setAlias('nucleos_user.util.email_canonicalizer', new Alias($config['service']['email_canonicalizer'], true));
@@ -187,15 +188,15 @@ private function remapParametersNamespaces(array $config, ContainerBuilder $cont
}
}

private function loadChangePassword(XmlFileLoader $loader): void
private function loadChangePassword(FileLoader $loader): void
{
$loader->load('change_password.xml');
$loader->load('change_password.php');
}

private function loadResetting(array $config, ContainerBuilder $container, XmlFileLoader $loader, string $fromEmail): void
private function loadResetting(array $config, ContainerBuilder $container, FileLoader $loader, string $fromEmail): void
{
$this->mailerNeeded = true;
$loader->load('resetting.xml');
$loader->load('resetting.php');

if (isset($config['from_email'])) {
// overwrite the global one
@@ -214,13 +215,13 @@ private function loadResetting(array $config, ContainerBuilder $container, XmlFi
]);
}

private function loadGroups(array $config, ContainerBuilder $container, XmlFileLoader $loader, string $dbDriver): void
private function loadGroups(array $config, ContainerBuilder $container, FileLoader $loader, string $dbDriver): void
{
if ('custom' !== $dbDriver) {
if (isset(self::$doctrineDrivers[$dbDriver])) {
$loader->load('doctrine_group.xml');
$loader->load('doctrine_group.php');
} else {
$loader->load(sprintf('%s_group.xml', $dbDriver));
$loader->load(sprintf('%s_group.php', $dbDriver));
}
}

41 changes: 41 additions & 0 deletions src/Resources/config/change_password.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/*
* This file is part of the NucleosUserBundle package.
*
* (c) Christian Gripp <mail@core23.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Nucleos\UserBundle\Action\ChangePasswordAction;
use Nucleos\UserBundle\Form\Model\ChangePassword;
use Nucleos\UserBundle\Form\Type\ChangePasswordFormType;
use Symfony\Component\DependencyInjection\Reference;

return static function (ContainerConfigurator $container): void {
$container->services()

->set(ChangePasswordFormType::class)
->tag('form.type')
->args([
ChangePassword::class,
])

->set(ChangePasswordAction::class)
->public()
->tag('form.type')
->args([
new Reference('twig'),
new Reference('router'),
new Reference('security.helper'),
new Reference('event_dispatcher'),
new Reference('form.factory'),
new Reference('nucleos_user.user_manager'),
])

;
};
17 changes: 0 additions & 17 deletions src/Resources/config/change_password.xml

This file was deleted.

74 changes: 74 additions & 0 deletions src/Resources/config/commands.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

/*
* This file is part of the NucleosUserBundle package.
*
* (c) Christian Gripp <mail@core23.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Nucleos\UserBundle\Command\ActivateUserCommand;
use Nucleos\UserBundle\Command\ChangePasswordCommand;
use Nucleos\UserBundle\Command\CreateUserCommand;
use Nucleos\UserBundle\Command\DeactivateUserCommand;
use Nucleos\UserBundle\Command\DemoteUserCommand;
use Nucleos\UserBundle\Command\PromoteUserCommand;
use Symfony\Component\DependencyInjection\Reference;

return static function (ContainerConfigurator $container): void {
$container->services()

->set(ActivateUserCommand::class)
->tag('console.command', [
'command' => 'nucleos:user:activate',
])
->args([
new Reference('nucleos_user.util.user_manipulator'),
])

->set(ChangePasswordCommand::class)
->tag('console.command', [
'command' => 'nucleos:user:change-password',
])
->args([
new Reference('nucleos_user.util.user_manipulator'),
])

->set(CreateUserCommand::class)
->tag('console.command', [
'command' => 'nucleos:user:create',
])
->args([
new Reference('nucleos_user.util.user_manipulator'),
])

->set(DeactivateUserCommand::class)
->tag('console.command', [
'command' => 'nucleos:user:deactivate',
])
->args([
new Reference('nucleos_user.util.user_manipulator'),
])

->set(DemoteUserCommand::class)
->tag('console.command', [
'command' => 'nucleos:user:demote',
])
->args([
new Reference('nucleos_user.util.user_manipulator'),
])

->set(PromoteUserCommand::class)
->tag('console.command', [
'command' => 'nucleos:user:promote',
])
->args([
new Reference('nucleos_user.util.user_manipulator'),
])

;
};
29 changes: 0 additions & 29 deletions src/Resources/config/commands.xml

This file was deleted.

44 changes: 44 additions & 0 deletions src/Resources/config/doctrine.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/*
* This file is part of the NucleosUserBundle package.
*
* (c) Christian Gripp <mail@core23.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Doctrine\Persistence\ObjectManager;
use Nucleos\UserBundle\Doctrine\UserListener;
use Nucleos\UserBundle\Doctrine\UserManager;
use Symfony\Component\DependencyInjection\Parameter;
use Symfony\Component\DependencyInjection\Reference;

return static function (ContainerConfigurator $container): void {
$container->services()

->set('nucleos_user.user_manager.default', UserManager::class)
->args([
new Reference('nucleos_user.util.password_updater'),
new Reference('nucleos_user.util.canonical_fields_updater'),
new Reference('nucleos_user.object_manager'),
new Parameter('nucleos_user.model.user.class'),
])

// The factory is configured in the DI extension class to support more Symfony versions
->set('nucleos_user.object_manager', ObjectManager::class)
->args([
new Parameter('nucleos_user.model_manager_name'),
])

->set('nucleos_user.user_listener', UserListener::class)
->args([
new Reference('nucleos_user.util.password_updater'),
new Reference('nucleos_user.util.canonical_fields_updater'),
])

;
};
19 changes: 0 additions & 19 deletions src/Resources/config/doctrine.xml

This file was deleted.

28 changes: 28 additions & 0 deletions src/Resources/config/doctrine_group.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/*
* This file is part of the NucleosUserBundle package.
*
* (c) Christian Gripp <mail@core23.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Nucleos\UserBundle\Doctrine\GroupManager;
use Symfony\Component\DependencyInjection\Parameter;
use Symfony\Component\DependencyInjection\Reference;

return static function (ContainerConfigurator $container): void {
$container->services()

->set('nucleos_user.group_manager.default', GroupManager::class)
->args([
new Reference('nucleos_user.object_manager'),
new Parameter('nucleos_user.model.group.class'),
])

;
};
9 changes: 0 additions & 9 deletions src/Resources/config/doctrine_group.xml

This file was deleted.

28 changes: 28 additions & 0 deletions src/Resources/config/flash_notifications.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/*
* This file is part of the NucleosUserBundle package.
*
* (c) Christian Gripp <mail@core23.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Nucleos\UserBundle\EventListener\FlashListener;
use Symfony\Component\DependencyInjection\Reference;

return static function (ContainerConfigurator $container): void {
$container->services()

->set(FlashListener::class)
->tag('kernel.event_subscriber')
->args([
new Reference('session.flash_bag'),
new Reference('translator'),
])

;
};
10 changes: 0 additions & 10 deletions src/Resources/config/flash_notifications.xml

This file was deleted.

Loading

0 comments on commit e1d1959

Please sign in to comment.