[Security]replaced acl:init command with postGenerateSchema listener
This commit is contained in:
parent
d2d7aecb64
commit
e8094589f0
@ -89,7 +89,11 @@ class MainConfiguration implements ConfigurationInterface
|
||||
->children()
|
||||
->arrayNode('acl')
|
||||
->children()
|
||||
->scalarNode('connection')->setInfo('any name configured in doctrine.dbal section')->end()
|
||||
->scalarNode('connection')
|
||||
->defaultValue('default')
|
||||
->cannotBeEmpty()
|
||||
->setInfo('any name configured in doctrine.dbal section')
|
||||
->end()
|
||||
->arrayNode('cache')
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
|
@ -133,9 +133,16 @@ class SecurityExtension extends Extension
|
||||
{
|
||||
$loader->load('security_acl_dbal.xml');
|
||||
|
||||
if (isset($config['connection'])) {
|
||||
$container->setAlias('security.acl.dbal.connection', sprintf('doctrine.dbal.%s_connection', $config['connection']));
|
||||
}
|
||||
$container->setAlias('security.acl.dbal.connection', sprintf('doctrine.dbal.%s_connection', $config['connection']));
|
||||
|
||||
$container
|
||||
->getDefinition('security.acl.dbal.schema_listener')
|
||||
->addTag('doctrine.event_listener', array(
|
||||
'connection' => $config['connection'],
|
||||
'event' => 'postGenerateSchema'
|
||||
))
|
||||
;
|
||||
|
||||
$container->getDefinition('security.acl.cache.doctrine')->addArgument($config['cache']['prefix']);
|
||||
|
||||
$container->setParameter('security.acl.dbal.class_table_name', $config['tables']['class']);
|
||||
|
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bundle\SecurityBundle\EventListener;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs;
|
||||
|
||||
/**
|
||||
* Merges ACL schema into the given schema.
|
||||
*
|
||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*/
|
||||
class AclSchemaListener
|
||||
{
|
||||
private $container;
|
||||
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
public function postGenerateSchema(GenerateSchemaEventArgs $args)
|
||||
{
|
||||
$schema = $args->getSchema();
|
||||
$this->container->get('security.acl.dbal.schema')->addToSchema($schema);
|
||||
}
|
||||
}
|
@ -6,6 +6,8 @@
|
||||
|
||||
<parameters>
|
||||
<parameter key="security.acl.dbal.provider.class">Symfony\Component\Security\Acl\Dbal\MutableAclProvider</parameter>
|
||||
<parameter key="security.acl.dbal.schema.class">Symfony\Component\Security\Acl\Dbal\Schema</parameter>
|
||||
<parameter key="security.acl.dbal.schema_listener.class">Symfony\Bundle\SecurityBundle\EventListener\AclSchemaListener</parameter>
|
||||
</parameters>
|
||||
|
||||
<services>
|
||||
@ -24,6 +26,19 @@
|
||||
<argument type="service" id="security.acl.cache" on-invalid="null" />
|
||||
</service>
|
||||
|
||||
<service id="security.acl.dbal.schema" class="%security.acl.dbal.schema.class%">
|
||||
<argument type="collection">
|
||||
<argument key="class_table_name">%security.acl.dbal.class_table_name%</argument>
|
||||
<argument key="entry_table_name">%security.acl.dbal.entry_table_name%</argument>
|
||||
<argument key="oid_table_name">%security.acl.dbal.oid_table_name%</argument>
|
||||
<argument key="oid_ancestors_table_name">%security.acl.dbal.oid_ancestors_table_name%</argument>
|
||||
<argument key="sid_table_name">%security.acl.dbal.sid_table_name%</argument>
|
||||
</argument>
|
||||
</service>
|
||||
<service id="security.acl.dbal.schema_listener" class="%security.acl.dbal.schema_listener.class%" public="false">
|
||||
<argument type="service" id="service_container" />
|
||||
</service>
|
||||
|
||||
<service id="security.acl.provider" alias="security.acl.dbal.provider" />
|
||||
|
||||
<service id="security.acl.cache.doctrine" class="%security.acl.cache.doctrine.class%" public="false">
|
||||
|
@ -42,6 +42,22 @@ final class Schema extends BaseSchema
|
||||
$this->addEntryTable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges ACL schema with the given schema.
|
||||
*
|
||||
* @param BaseSchema $schema
|
||||
*/
|
||||
public function addToSchema(BaseSchema $schema)
|
||||
{
|
||||
foreach ($this->getTables() as $table) {
|
||||
$schema->_addTable($table);
|
||||
}
|
||||
|
||||
foreach ($this->getSequences() as $sequence) {
|
||||
$schema->_addSequence($sequence);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the class table to the schema
|
||||
*/
|
||||
|
Reference in New Issue
Block a user