@@ -14,31 +14,31 @@ register the mappings for your model classes.
14
14
For non-reusable bundles, the easiest option is to put your model classes
15
15
in the default locations: ``Entity `` for the Doctrine ORM or ``Document ``
16
16
for one of the ODMs. For reusable bundles, rather than duplicate model classes
17
- just to get the auto mapping, use the compiler pass.
17
+ just to get the auto- mapping, use the compiler pass.
18
18
19
19
.. versionadded :: 2.3
20
20
The base mapping compiler pass was introduced in Symfony 2.3. The Doctrine bundles
21
21
support it from DoctrineBundle >= 1.2.1, MongoDBBundle >= 3.0.0,
22
- PHPCRBundle >= 1.0.0-alpha2 and the (unversioned) CouchDBBundle supports the
22
+ PHPCRBundle >= 1.0.0 and the (unversioned) CouchDBBundle supports the
23
23
compiler pass since the `CouchDB Mapping Compiler Pass pull request `_
24
24
was merged.
25
25
26
- If you want your bundle to support older versions of Symfony and
27
- Doctrine, you can provide a copy of the compiler pass in your bundle .
28
- See for example the ` FOSUserBundle mapping configuration `_
29
- `` addRegisterMappingsPass ``.
30
-
26
+ .. versionadded :: 2.6
27
+ Support for defining namespace aliases was introduced in Symfony 2.6 .
28
+ It is safe to define the aliases with older versions of Symfony as
29
+ the aliases are the last argument to `` createXmlMappingDriver `` and
30
+ are ignored by PHP if that argument doesn't exist.
31
31
32
32
In your bundle class, write the following code to register the compiler pass.
33
- This one is written for the FOSUserBundle , so parts of it will need to
33
+ This one is written for the CmfRoutingBundle , so parts of it will need to
34
34
be adapted for your case::
35
35
36
36
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass;
37
37
use Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler\DoctrineMongoDBMappingsPass;
38
38
use Doctrine\Bundle\CouchDBBundle\DependencyInjection\Compiler\DoctrineCouchDBMappingsPass;
39
39
use Doctrine\Bundle\PHPCRBundle\DependencyInjection\Compiler\DoctrinePhpcrMappingsPass;
40
40
41
- class FOSUserBundle extends Bundle
41
+ class CmfRoutingBundle extends Bundle
42
42
{
43
43
public function build(ContainerBuilder $container)
44
44
{
@@ -47,16 +47,17 @@ be adapted for your case::
47
47
48
48
$modelDir = realpath(__DIR__.'/Resources/config/doctrine/model');
49
49
$mappings = array(
50
- $modelDir => 'FOS\UserBundle \Model',
50
+ $modelDir => 'Symfony\Cmf\RoutingBundle \Model',
51
51
);
52
52
53
53
$ormCompilerClass = 'Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass';
54
54
if (class_exists($ormCompilerClass)) {
55
55
$container->addCompilerPass(
56
56
DoctrineOrmMappingsPass::createXmlMappingDriver(
57
57
$mappings,
58
- array('fos_user.model_manager_name'),
59
- 'fos_user.backend_type_orm'
58
+ array('cmf_routing.model_manager_name'),
59
+ 'cmf_routing.backend_type_orm',
60
+ array('CmfRoutingBundle' => 'Symfony\Cmf\RoutingBundle\Model')
60
61
));
61
62
}
62
63
@@ -65,8 +66,9 @@ be adapted for your case::
65
66
$container->addCompilerPass(
66
67
DoctrineMongoDBMappingsPass::createXmlMappingDriver(
67
68
$mappings,
68
- array('fos_user.model_manager_name'),
69
- 'fos_user.backend_type_mongodb'
69
+ array('cmf_routing.model_manager_name'),
70
+ 'cmf_routing.backend_type_mongodb',
71
+ array('CmfRoutingBundle' => 'Symfony\Cmf\RoutingBundle\Model')
70
72
));
71
73
}
72
74
@@ -75,8 +77,9 @@ be adapted for your case::
75
77
$container->addCompilerPass(
76
78
DoctrineCouchDBMappingsPass::createXmlMappingDriver(
77
79
$mappings,
78
- array('fos_user.model_manager_name'),
79
- 'fos_user.backend_type_couchdb'
80
+ array('cmf_routing.model_manager_name'),
81
+ 'cmf_routing.backend_type_couchdb',
82
+ array('CmfRoutingBundle' => 'Symfony\Cmf\RoutingBundle\Model')
80
83
));
81
84
}
82
85
@@ -85,8 +88,9 @@ be adapted for your case::
85
88
$container->addCompilerPass(
86
89
DoctrinePhpcrMappingsPass::createXmlMappingDriver(
87
90
$mappings,
88
- array('fos_user.model_manager_name'),
89
- 'fos_user.backend_type_phpcr'
91
+ array('cmf_routing.model_manager_name'),
92
+ 'cmf_routing.backend_type_phpcr',
93
+ array('CmfRoutingBundle' => 'Symfony\Cmf\RoutingBundle\Model')
90
94
));
91
95
}
92
96
}
@@ -99,17 +103,20 @@ decide which to use.
99
103
The compiler pass provides factory methods for all drivers provided by Doctrine:
100
104
Annotations, XML, Yaml, PHP and StaticPHP. The arguments are:
101
105
102
- * a map/hash of absolute directory path to namespace;
103
- * an array of container parameters that your bundle uses to specify the name of
104
- the Doctrine manager that it is using. In the above example, the FOSUserBundle
105
- stores the manager name that's being used under the ``fos_user .model_manager_name ``
106
+ * A map/hash of absolute directory path to namespace;
107
+ * An array of container parameters that your bundle uses to specify the name of
108
+ the Doctrine manager that it is using. In the example above , the CmfRoutingBundle
109
+ stores the manager name that's being used under the ``cmf_routing .model_manager_name ``
106
110
parameter. The compiler pass will append the parameter Doctrine is using
107
111
to specify the name of the default manager. The first parameter found is
108
112
used and the mappings are registered with that manager;
109
- * an optional container parameter name that will be used by the compiler
113
+ * An optional container parameter name that will be used by the compiler
110
114
pass to determine if this Doctrine type is used at all. This is relevant if
111
115
your user has more than one type of Doctrine bundle installed, but your
112
- bundle is only used with one type of Doctrine.
116
+ bundle is only used with one type of Doctrine;
117
+ * A map/hash of aliases to namespace. This should be the same convention used
118
+ by Doctrine auto-mapping. In the example above, this allows the user to call
119
+ ``$om->getRepository('CmfRoutingBundle:Route') ``.
113
120
114
121
.. note ::
115
122
@@ -120,7 +127,7 @@ Annotations, XML, Yaml, PHP and StaticPHP. The arguments are:
120
127
of the class as their filename (e.g. ``BlogPost.orm.xml ``)
121
128
122
129
If you also need to map a base class, you can register a compiler pass
123
- with the ``DefaultFileLocator `` like this. This code is simply taken from the
130
+ with the ``DefaultFileLocator `` like this. This code is taken from the
124
131
``DoctrineOrmMappingsPass `` and adapted to use the ``DefaultFileLocator ``
125
132
instead of the ``SymfonyFileLocator ``::
126
133
@@ -138,6 +145,9 @@ Annotations, XML, Yaml, PHP and StaticPHP. The arguments are:
138
145
);
139
146
}
140
147
148
+ Note that you do not need to provide a namespace alias unless your users are
149
+ expected to ask Doctrine for the base classes.
150
+
141
151
Now place your mapping file into ``/Resources/config/doctrine-base `` with the
142
152
fully qualified class name, separated by ``. `` instead of ``\ ``, for example
143
153
``Other.Namespace.Model.Name.orm.xml ``. You may not mix the two as otherwise
@@ -146,4 +156,3 @@ Annotations, XML, Yaml, PHP and StaticPHP. The arguments are:
146
156
Adjust accordingly for the other Doctrine implementations.
147
157
148
158
.. _`CouchDB Mapping Compiler Pass pull request` : https://github.com/doctrine/DoctrineCouchDBBundle/pull/27
149
- .. _`FOSUserBundle mapping configuration` : https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/FOSUserBundle.php
0 commit comments