You are browsing a version that is no longer maintained.

Configuring multiple sessions for PHPCR-ODM

If you need more than one PHPCR backend, you can define sessions as child of the session information. Each session has a name and the configuration following the same schema as what is directly in session. You can also overwrite which session to use as default_session. Once you have multiple sessions, you can also configure multiple document managers with those sessions.

Autowiring always gives you the default session and the default document manager. When working with multiple sessions and managers, you need to explicitly specify the services. For the document managers, you can also go through the manager registry (see at the end of this page).

Multiple PHPCR Sessions

1# app/config/config.yml doctrine_phpcr: session: default_session: ~ sessions: <name>: workspace: ... # Required username: ~ password: ~ backend: # ... options: # ...
2
3
4
5
6
7
8
9
10
11
12
13

Multiple Document Managers

If you are using the ODM, you will also want to configure multiple document managers.

Inside the odm section, you can add named entries in the document_managers. To use the non-default session, specify the session attribute.

1# app/config/config.yml odm: default_document_manager: ~ document_managers: <name>: session: <sessionname> # ... configuration as above
2
3
4
5
6
7

Bringing it all together

The following full example uses the default manager for AppBundle and the documents provided by the CMF. Additionally, it has a website and DMS manager that connects to the Jackrabbit of Magnolia CMS. That manager looks for models in the MagnoliaBundle.

1doctrine_phpcr: # configure the PHPCR sessions session: sessions: default: backend: "%phpcr_backend%" workspace: "%phpcr_workspace%" username: "%phpcr_user%" password: "%phpcr_pass%" website: backend: type: jackrabbit url: "%magnolia_url%" workspace: website username: "%magnolia_user%" password: "%magnolia_pass%" dms: backend: type: jackrabbit url: "%magnolia_url%" workspace: dms username: "%magnolia_user%" password: "%magnolia_pass%" # enable the ODM layer odm: auto_generate_proxy_classes: "%kernel.debug%" document_managers: default: session: default mappings: AppBundle: ~ CmfContentBundle: ~ CmfMenuBundle: ~ CmfRoutingBundle: ~ website: session: website configuration_id: magnolia.odm_configuration mappings: MagnoliaBundle: ~ dms: session: dms configuration_id: magnolia.odm_configuration mappings: MagnoliaBundle: ~
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

You can access the managers through the manager registry available in the service Doctrine\Bundle\PHPCRBundle\ManagerRegistry:

use Doctrine\Bundle\PHPCRBundle\ManagerRegistry;

/** @var $container \Symfony\Component\DependencyInjection\ContainerInterface */

// get the named manager from the registry
$ dm = $container->get(ManagerRegistry::class)->getManager('website');

// get the manager for a specific document class
$ dm = $container->get(ManagerRegistry::class)->getManagerForClass('CmfContentBundle:StaticContent');

Additionally, each manager is available as a service in the DI container. The service name pattern is doctrine_phpcr.odm.<name>_document_manager so for example the website manager is called doctrine_phpcr.odm.website_document_manager.