From e8094589f0f718d06d96fd56df7e0e6eaf08b485 Mon Sep 17 00:00:00 2001 From: "Johannes M. Schmitt" Date: Sun, 11 Mar 2012 13:54:49 +0100 Subject: [PATCH] [Security]replaced acl:init command with postGenerateSchema listener --- .../DependencyInjection/MainConfiguration.php | 6 +++- .../DependencyInjection/SecurityExtension.php | 13 +++++-- .../EventListener/AclSchemaListener.php | 36 +++++++++++++++++++ .../Resources/config/security_acl_dbal.xml | 15 ++++++++ .../Component/Security/Acl/Dbal/Schema.php | 16 +++++++++ 5 files changed, 82 insertions(+), 4 deletions(-) create mode 100644 src/Symfony/Bundle/SecurityBundle/EventListener/AclSchemaListener.php diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/MainConfiguration.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/MainConfiguration.php index 5f975628ef..30dd54be57 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/MainConfiguration.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/MainConfiguration.php @@ -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() diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php index 14f36b1372..0fb4929362 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php @@ -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']); diff --git a/src/Symfony/Bundle/SecurityBundle/EventListener/AclSchemaListener.php b/src/Symfony/Bundle/SecurityBundle/EventListener/AclSchemaListener.php new file mode 100644 index 0000000000..2e8b191676 --- /dev/null +++ b/src/Symfony/Bundle/SecurityBundle/EventListener/AclSchemaListener.php @@ -0,0 +1,36 @@ + + * + * 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 + */ +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); + } +} \ No newline at end of file diff --git a/src/Symfony/Bundle/SecurityBundle/Resources/config/security_acl_dbal.xml b/src/Symfony/Bundle/SecurityBundle/Resources/config/security_acl_dbal.xml index e1f36cabc3..d5cbb34f31 100644 --- a/src/Symfony/Bundle/SecurityBundle/Resources/config/security_acl_dbal.xml +++ b/src/Symfony/Bundle/SecurityBundle/Resources/config/security_acl_dbal.xml @@ -6,6 +6,8 @@ Symfony\Component\Security\Acl\Dbal\MutableAclProvider + Symfony\Component\Security\Acl\Dbal\Schema + Symfony\Bundle\SecurityBundle\EventListener\AclSchemaListener @@ -24,6 +26,19 @@ + + + %security.acl.dbal.class_table_name% + %security.acl.dbal.entry_table_name% + %security.acl.dbal.oid_table_name% + %security.acl.dbal.oid_ancestors_table_name% + %security.acl.dbal.sid_table_name% + + + + + + diff --git a/src/Symfony/Component/Security/Acl/Dbal/Schema.php b/src/Symfony/Component/Security/Acl/Dbal/Schema.php index 010a51e2ce..7d47e1c023 100644 --- a/src/Symfony/Component/Security/Acl/Dbal/Schema.php +++ b/src/Symfony/Component/Security/Acl/Dbal/Schema.php @@ -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 */