8000 [Security]replaced acl:init command with postGenerateSchema listener · symfony/symfony@e809458 · GitHub
[go: up one dir, main page]

Skip to content

Commit e809458

Browse files
schmittjohvicb
authored andcommitted
[Security]replaced acl:init command with postGenerateSchema listener
1 parent d2d7aec commit e809458

File tree

5 files changed

+82
-4
lines changed

5 files changed

+82
-4
lines changed

src/Symfony/Bundle/SecurityBundle/DependencyInjection/MainConfiguration.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@ private function addAclSection(ArrayNodeDefinition $rootNode)
8989
->children()
9090
->arrayNode('acl')
9191
->children()
92-
->scalarNode('connection')->setInfo('any name configured in doctrine.dbal section')->end()
92+
->scalarNode('connection')
93+
->defaultValue('default')
94+
->cannotBeEmpty()
95+
->setInfo('any name configured in doctrine.dbal section')
96+
->end()
9397
->arrayNode('cache')
9498
->addDefaultsIfNotSet()
9599
->children()

src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,16 @@ private function configureDbalAclProvider(array $config, ContainerBuilder $conta
133133
{
134134
$loader->load('security_acl_dbal.xml');
135135

136-
if (isset($config['connection'])) {
137 8000 -
$container->setAlias('security.acl.dbal.connection', sprintf('doctrine.dbal.%s_connection', $config['connection']));
138-
}
136+
$container->setAlias('security.acl.dbal.connection', sprintf('doctrine.dbal.%s_connection', $config['connection']));
137+
138+
$container
139+
->getDefinition('security.acl.dbal.schema_listener')
140+
->addTag('doctrine.event_listener', array(
141+
'connection' => $config['connection'],
142+
'event' => 'postGenerateSchema'
143+
))
144+
;
145+
139146
$container->getDefinition('security.acl.cache.doctrine')->addArgument($config['cache']['prefix']);
140147

141148
$container->setParameter('security.acl.dbal.class_table_name', $config['tables']['class']);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony framework.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
11+
12+
namespace Symfony\Bundle\SecurityBundle\EventListener;
13+
14+
use Symfony\Component\DependencyInjection\ContainerInterface;
15+
use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs;
16+
17+
/**
18+
* Merges ACL schema into the given schema.
19+
*
20+
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
21+
*/
22+
class AclSchemaListener
23+
{
24+
private $container;
25+
26+
public function __construct(ContainerInterface $container)
27+
{
28+
$this->container = $container;
29+
}
30+
31+
public function postGenerateSchema(GenerateSchemaEventArgs $args)
32+
{
33+
$schema = $args->getSchema();
34+
$this->container->get('security.acl.dbal.schema')->addToSchema($schema);
35+
}
36+
}

src/Symfony/Bundle/SecurityBundle/Resources/config/security_acl_dbal.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
<parameters>
88
<parameter key="security.acl.dbal.provider.class">Symfony\Component\Security\Acl\Dbal\MutableAclProvider</parameter>
9+
<parameter key="security.acl.dbal.schema.class">Symfony\Component\Security\Acl\Dbal\Schema</parameter>
10+
<parameter key="security.acl.dbal.schema_listener.class">Symfony\Bundle\SecurityBundle\EventListener\AclSchemaListener</parameter>
911
</parameters>
1012

1113
<services>
@@ -24,6 +26,19 @@
2426
<argument type="service" id="security.acl.cache" on-invalid="null" />
2527
</service>
2628

29+
<service id="security.acl.dbal.schema" class="%security.acl.dbal.schema.class%">
30+
<argument type="collection">
31+
<argument key="class_table_name">%security.acl.dbal.class_table_name%</argument>
32+
<argument key="entry_table_name">%security.acl.dbal.entry_table_name%</argument>
33+
<argument key="oid_table_name">%security.acl.dbal.oid_table_name%</argument>
34+
<argument key="oid_ancestors_table_name">%security.acl.dbal.oid_ancestors_table_name%</argument>
35+
<argument key="sid_table_name">%security.acl.dbal.sid_table_name%</argument>
36+
</argument>
37+
</service>
38+
<service id="security.acl.dbal.schema_listener" class="%security.acl.dbal.schema_listener.class%" public="false">
39+
<argument type="service" id="service_container" />
40+
</service>
41+
2742
<service id="security.acl.provider" alias="security.acl.dbal.provider" />
2843

2944
<service id="security.acl.cache.doctrine" class="%security.acl.cache.doctrine.class%" public="false">

src/Symfony/Component/Security/Acl/Dbal/Schema.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,22 @@ public function __construct(array $options, SchemaConfig $schemaConfig = null)
4242
$this->addEntryTable();
4343
}
4444

45+
/**
46+
* Merges ACL schema with the given schema.
47+
*
48+
* @param BaseSchema $schema
49+
*/
50+
public function addToSchema(BaseSchema $schema)
51+
{
52+
foreach ($this->getTables() as $table) {
53+
$schema->_addTable($table);
54+
}
55+
56+
foreach ($this->getSequences() as $sequence) {
57+
$schema->_addSequence($sequence);
58+
}
59+
}
60+
4561
/**
4662
* Adds the class table to the schema
4763
*/

0 commit comments

Comments
 (0)
0