Skip to content

Commit

Permalink
add community manager service compiler pass
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz committed Jun 16, 2016
1 parent df4ab1e commit 7f0ebaf
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 68 deletions.
50 changes: 50 additions & 0 deletions DependencyInjection/CompilerPass/CommunityManagerCompilerPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?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 Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* Create foreach configured webspace a community manager.
*/
class CommunityManagerCompilerPass implements CompilerPassInterface
{
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
$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.

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

namespace Sulu\Bundle\CommunityBundle;

use Sulu\Bundle\CommunityBundle\DependencyInjection\CompilerPass\CommunityManagerCompilerPass;
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());
}
}

0 comments on commit 7f0ebaf

Please sign in to comment.