Skip to content

Commit

Permalink
add session management for own event hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
ElectricMaxxx committed Jun 10, 2014
1 parent 86d2c76 commit 3fd8303
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
17 changes: 16 additions & 1 deletion DependencyInjection/DoctrineOrmPhpcrAdapterExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,25 @@ public function load(array $configs, ContainerBuilder $container)
*/
public function loadReferencedManagers(array $config, ContainerBuilder $container)
{
// the configuration setting will prevent us from using wrong type
$sessions = array();
foreach ($config as $manager) {
$this->referenceManagers[$manager['type']][$manager['name']] = new Reference($manager['service']);

// session for each manager connection
if (!isset($sessions[$manager['name']])) {
$sessions[$manager['name']] = sprintf('doctrine_orm_phpcr_adapter.%s_session', $manager['name']);
}
}

$container->setParameter('doctrine_orm_phpcr_adapter.sessions', $sessions);

// no sessions configured
if (empty($config['default_session'])) {
return;
}

$container->setParameter('doctrine_orm_phpcr_adapter.default_session', $config['default_session']);
$container->setAlias('doctrine_orm_phpcr_adapter.session', $sessions[$config['default_session']]);
}

public function getAlias()
Expand Down
11 changes: 11 additions & 0 deletions DoctrineOrmPhpcrAdapterBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,16 @@ class DoctrineOrmPhpcrAdapterBundle extends Bundle
public function build(ContainerBuilder $container)
{
parent::build($container);

if (class_exists('Doctrine\ODM\PHPCR\Version')) {
$container->addCompilerPass(
new RegisterEventListenersAndSubscribersPass(
'doctrine_orm_phpcr_adapter.sessions',
'doctrine_orm_phpcr_adapter.adapter.%s_event_manager',
'doctrine_adapter'
),
PassConfig::TYPE_BEFORE_OPTIMIZATION
);
}
}
}
2 changes: 2 additions & 0 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
<parameter key="doctrine_orm_phpcr_adapter.configuration.class">Doctrine\ORM\ODMAdapter\Configuration</parameter>

<parameter key="doctrine_orm_phpcr_adapter.adapter.event_manager.class">Symfony\Bridge\Doctrine\ContainerAwareEventManager</parameter>

<parameter key="doctrine_orm_phpcr_adapter.sessions" type="collection" />
</parameters>

<services>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,30 @@ public function testManagerAdapterSetting()
$this->assertContainerBuilderHasService('doctrine_orm_phpcr_adapter.adapter.default_event_manager');
$this->assertContainerBuilderHasService('doctrine_orm_phpcr_adapter.adapter.default_configuration');
}

public function testDefaultSessionSetting()
{
$this->container->setParameter(
'kernel.bundles',
array()
);
$this->container->setParameter('kernel.root_dir', 'test');
$this->container->setParameter('kernel.environment', 'test');
$this->load(array(
'managers' => array(
'reference-phpcr' => array('default' => 'doctrine_phpcr.odm.default_document_manager'),
'reference-dbal-orm' => array('default' => 'doctrine.orm.default_entity_manager',
),
),
'adapter' => array(
'auto_mapping' => true,
'auto_generate_proxy_classes' => false,
'mappings' => array(),
),
));

$this->assertContainerBuilderHasParameter('doctrine_orm_phpcr_adapter.sessions', array(
'default' => 'doctrine_orm_phpcr_adapter.default_session',
));
}
}

0 comments on commit 3fd8303

Please sign in to comment.