@@ -17,7 +17,6 @@ register the mappings for your model classes.
17
17
just to get the auto mapping, use the compiler pass.
18
18
19
19
.. versionadded :: 2.3
20
-
21
20
The base mapping compiler pass was added in Symfony 2.3. The Doctrine bundles
22
21
support it from DoctrineBundle >= 1.2.1, MongoDBBundle >= 3.0.0,
23
22
PHPCRBundle >= 1.0.0-alpha2 and the (unversioned) CouchDBBundle supports the
@@ -30,7 +29,9 @@ register the mappings for your model classes.
30
29
``addRegisterMappingsPass ``.
31
30
32
31
33
- In your bundle class, write the following code to register the compiler pass::
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
34
+ be adapted for your case::
34
35
35
36
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass;
36
37
use Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler\DoctrineMongoDBMappingsPass;
@@ -54,6 +55,7 @@ In your bundle class, write the following code to register the compiler pass::
54
55
$container->addCompilerPass(
55
56
DoctrineOrmMappingsPass::createXmlMappingDriver(
56
57
$mappings,
58
+ array('fos_user.model_manager_name'),
57
59
'fos_user.backend_type_orm'
58
60
));
59
61
}
@@ -63,6 +65,7 @@ In your bundle class, write the following code to register the compiler pass::
63
65
$container->addCompilerPass(
64
66
DoctrineMongoDBMappingsPass::createXmlMappingDriver(
65
67
$mappings,
68
+ array('fos_user.model_manager_name'),
66
69
'fos_user.backend_type_mongodb'
67
70
));
68
71
}
@@ -72,6 +75,7 @@ In your bundle class, write the following code to register the compiler pass::
72
75
$container->addCompilerPass(
73
76
DoctrineCouchDBMappingsPass::createXmlMappingDriver(
74
77
$mappings,
78
+ array('fos_user.model_manager_name'),
75
79
'fos_user.backend_type_couchdb'
76
80
));
77
81
}
@@ -81,6 +85,7 @@ In your bundle class, write the following code to register the compiler pass::
81
85
$container->addCompilerPass(
82
86
DoctrinePhpcrMappingsPass::createXmlMappingDriver(
83
87
$mappings,
88
+ array('fos_user.model_manager_name'),
84
89
'fos_user.backend_type_phpcr'
85
90
));
86
91
}
@@ -94,12 +99,13 @@ decide which to use.
94
99
The compiler pass provides factory methods for all drivers provided by Doctrine:
95
100
Annotations, XML, Yaml, PHP and StaticPHP. The arguments are:
96
101
97
- * a map of absolute directory path to namespace;
102
+ * a map/hash of absolute directory path to namespace;
98
103
* an array of container parameters that your bundle uses to specify the name of
99
- the Doctrine manager that it is using. The compiler pass will append the
100
- parameter Doctrine is using to specify the name of the default manager. The
101
- first parameter found is used and the mappings are registered with that
102
- manager;
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
+ parameter. The compiler pass will append the parameter Doctrine is using
107
+ to specify the name of the default manager. The first parameter found is
108
+ used and the mappings are registered with that manager;
103
109
* an optional container parameter name that will be used by the compiler
104
110
pass to determine if this Doctrine type is used at all (this is relevant if
105
111
your user has more than one type of Doctrine bundle installed, but your
@@ -109,8 +115,14 @@ Annotations, XML, Yaml, PHP and StaticPHP. The arguments are:
109
115
110
116
The factory method is using the ``SymfonyFileLocator `` of Doctrine, meaning
111
117
it will only see XML and YML mapping files if they do not contain the
112
- namespace. If you also need to map a base class, you can register a
113
- compiler pass with the ``DefaultFileLocator `` like this::
118
+ full namespace as the filename. This is by design: the ``SymfonyFileLocator ``
119
+ simplifies things by assuming the files are just the "short" version
120
+ of the class as their filename (e.g. ``BlogPost.orm.xml ``)
121
+
122
+ 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
124
+ ``DoctrineOrmMappingsPass `` and adapted to use the ``DefaultFileLocator ``
125
+ instead of the ``SymfonyFileLocator ``::
114
126
115
127
private function buildMappingCompilerPass()
116
128
{
@@ -126,7 +138,7 @@ Annotations, XML, Yaml, PHP and StaticPHP. The arguments are:
126
138
);
127
139
}
128
140
129
- And place your mapping file into ``/Resources/config/doctrine-base `` with the
141
+ Now place your mapping file into ``/Resources/config/doctrine-base `` with the
130
142
fully qualified class name, separated by ``. `` instead of ``\ ``, for example
131
143
``Other.Namespace.Model.Name.orm.xml ``. You may not mix the two as otherwise
132
144
the SymfonyFileLocator will get confused.
0 commit comments