Skip to content

Commit e55f0f7

Browse files
committed
[symfony#2669] Proofreading and minor fixes for updates to mapping mode classes
1) Fixed missed second argument to the `createXmlMappingDriver` methods 2) Clarified the final note about the SymfonyFileLocator 3) Other minor changes
1 parent e0b83a3 commit e55f0f7

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

cookbook/doctrine/mapping_model_classes.rst

+22-10
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ register the mappings for your model classes.
1717
just to get the auto mapping, use the compiler pass.
1818

1919
.. versionadded:: 2.3
20-
2120
The base mapping compiler pass was added in Symfony 2.3. The Doctrine bundles
2221
support it from DoctrineBundle >= 1.2.1, MongoDBBundle >= 3.0.0,
2322
PHPCRBundle >= 1.0.0-alpha2 and the (unversioned) CouchDBBundle supports the
@@ -30,7 +29,9 @@ register the mappings for your model classes.
3029
``addRegisterMappingsPass``.
3130

3231

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::
3435

3536
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass;
3637
use Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler\DoctrineMongoDBMappingsPass;
@@ -54,6 +55,7 @@ In your bundle class, write the following code to register the compiler pass::
5455
$container->addCompilerPass(
5556
DoctrineOrmMappingsPass::createXmlMappingDriver(
5657
$mappings,
58+
array('fos_user.model_manager_name'),
5759
'fos_user.backend_type_orm'
5860
));
5961
}
@@ -63,6 +65,7 @@ In your bundle class, write the following code to register the compiler pass::
6365
$container->addCompilerPass(
6466
DoctrineMongoDBMappingsPass::createXmlMappingDriver(
6567
$mappings,
68+
array('fos_user.model_manager_name'),
6669
'fos_user.backend_type_mongodb'
6770
));
6871
}
@@ -72,6 +75,7 @@ In your bundle class, write the following code to register the compiler pass::
7275
$container->addCompilerPass(
7376
DoctrineCouchDBMappingsPass::createXmlMappingDriver(
7477
$mappings,
78+
array('fos_user.model_manager_name'),
7579
'fos_user.backend_type_couchdb'
7680
));
7781
}
@@ -81,6 +85,7 @@ In your bundle class, write the following code to register the compiler pass::
8185
$container->addCompilerPass(
8286
DoctrinePhpcrMappingsPass::createXmlMappingDriver(
8387
$mappings,
88+
array('fos_user.model_manager_name'),
8489
'fos_user.backend_type_phpcr'
8590
));
8691
}
@@ -94,12 +99,13 @@ decide which to use.
9499
The compiler pass provides factory methods for all drivers provided by Doctrine:
95100
Annotations, XML, Yaml, PHP and StaticPHP. The arguments are:
96101

97-
* a map of absolute directory path to namespace;
102+
* a map/hash of absolute directory path to namespace;
98103
* 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;
103109
* an optional container parameter name that will be used by the compiler
104110
pass to determine if this Doctrine type is used at all (this is relevant if
105111
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:
109115

110116
The factory method is using the ``SymfonyFileLocator`` of Doctrine, meaning
111117
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``::
114126

115127
private function buildMappingCompilerPass()
116128
{
@@ -126,7 +138,7 @@ Annotations, XML, Yaml, PHP and StaticPHP. The arguments are:
126138
);
127139
}
128140

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
130142
fully qualified class name, separated by ``.`` instead of ``\``, for example
131143
``Other.Namespace.Model.Name.orm.xml``. You may not mix the two as otherwise
132144
the SymfonyFileLocator will get confused.

0 commit comments

Comments
 (0)