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

Add community manager service compiler pass #7

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
52 changes: 52 additions & 0 deletions DependencyInjection/CompilerPass/CommunityManagerCompilerPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/*
* This file is part of Sulu.
*
* (c) MASSIVE ART WebServices GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Sulu\Bundle\CommunityBundle\DependencyInjection\CompilerPass;

use Sulu\Bundle\CommunityBundle\DependencyInjection\Configuration;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\DefinitionDecorator;

/**
* Create foreach configured webspace a community manager.
*/
class CommunityManagerCompilerPass implements CompilerPassInterface
{
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
$config = $container->getParameter('sulu_community.config');

foreach ($config[Configuration::WEBSPACES] as $webspaceKey => $webspaceConfig) {
// Set firewall by webspace key
if ($webspaceConfig[Configuration::FIREWALL] === null) {
$webspaceConfig[Configuration::FIREWALL] = $webspaceKey;
}

// Set role by webspace key
if ($webspaceConfig[Configuration::ROLE] === null) {
$webspaceConfig[Configuration::ROLE] = ucfirst($webspaceKey) . 'User';
}

$definition = new DefinitionDecorator('sulu_community.community_manager');
$definition->replaceArgument(0, $webspaceConfig);
$definition->replaceArgument(1, $webspaceKey);

$container->setDefinition(
sprintf('sulu_community.%s.community_manager', $webspaceKey),
$definition
);
}
}
}
34 changes: 1 addition & 33 deletions DependencyInjection/SuluCommunityExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@

namespace Sulu\Bundle\CommunityBundle\DependencyInjection;

use Sulu\Bundle\CommunityBundle\Manager\CommunityManager;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

/**
Expand All @@ -35,36 +32,7 @@ public function load(array $configs, ContainerBuilder $container)
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

foreach ($config[Configuration::WEBSPACES] as $webspaceKey => $webspaceConfig) {
// Set firewall by webspace key
if ($webspaceConfig[Configuration::FIREWALL] === null) {
$webspaceConfig[Configuration::FIREWALL] = $webspaceKey;
}

// Set role by webspace key
if ($webspaceConfig[Configuration::ROLE] === null) {
$webspaceConfig[Configuration::ROLE] = ucfirst($webspaceKey) . 'User';
}

$container->setDefinition(
sprintf('sulu_community.%s.community_manager', $webspaceKey),
new Definition(
CommunityManager::class,
[
$webspaceConfig,
$webspaceKey,
new Reference('doctrine.orm.entity_manager'),
new Reference('event_dispatcher'),
new Reference('security.token_storage'),
new Reference('sulu_security.token_generator'),
new Reference('sulu_core.webspace.webspace_manager'),
new Reference('sulu.repository.user'),
new Reference('sulu.repository.role'),
new Reference('sulu.repository.contact'),
]
)
);
}
$container->setParameter('sulu_community.config', $config);

$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.xml');
Expand Down
39 changes: 29 additions & 10 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<parameters>
<!-- Event Constants -->
Expand All @@ -14,15 +14,34 @@

<services>
<!-- Community Manager -->
<service id="sulu_community.community_manager"
class="Sulu\Bundle\CommunityBundle\Manager\CommunityManager"
abstract="true">
<argument/>
<argument/>
<argument type="service" id="doctrine.orm.entity_manager"/>
<argument type="service" id="event_dispatcher"/>
<argument type="service" id="security.token_storage"/>
<argument type="service" id="sulu_security.token_generator"/>
<argument type="service" id="sulu_core.webspace.webspace_manager"/>
<argument type="service" id="sulu.repository.user"/>
<argument type="service" id="sulu.repository.role"/>
<argument type="service" id="sulu.repository.contact"/>
</service>

<!-- Mail Listener -->
<service id="sulu_community.mail_listener" class="Sulu\Bundle\CommunityBundle\EventListener\MailListener">
<argument type="service" id="mailer" />
<argument type="service" id="translator" />
<argument type="service" id="templating" />

<tag name="kernel.event_listener" event="%sulu_community.event.registered%" method="sendRegistrationEmails" />
<tag name="kernel.event_listener" event="%sulu_community.event.confirmed%" method="sendConfirmationEmails" />
<tag name="kernel.event_listener" event="%sulu_community.event.password_forgot%" method="sendPasswordForgetEmails" />
<tag name="kernel.event_listener" event="%sulu_community.event.password_reseted%" method="sendPasswordResetEmails" />
<argument type="service" id="mailer"/>
<argument type="service" id="translator"/>
<argument type="service" id="templating"/>

<tag name="kernel.event_listener" event="%sulu_community.event.registered%"
method="sendRegistrationEmails"/>
<tag name="kernel.event_listener" event="%sulu_community.event.confirmed%" method="sendConfirmationEmails"/>
<tag name="kernel.event_listener" event="%sulu_community.event.password_forgot%"
method="sendPasswordForgetEmails"/>
<tag name="kernel.event_listener" event="%sulu_community.event.password_reseted%"
method="sendPasswordResetEmails"/>
</service>

<!-- sulu-admin -->
Expand Down
25 changes: 0 additions & 25 deletions Resources/config/validation.yml

This file was deleted.

14 changes: 14 additions & 0 deletions SuluCommunityBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,22 @@

namespace Sulu\Bundle\CommunityBundle;

use Sulu\Bundle\CommunityBundle\DependencyInjection\CompilerPass\CommunityManagerCompilerPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;

/**
* Register the bundles compiler passes.
*/
class SuluCommunityBundle extends Bundle
{
/**
* {@inheritdoc}
*/
public function build(ContainerBuilder $container)
{
parent::build($container);

$container->addCompilerPass(new CommunityManagerCompilerPass());
}
}