Skip to content

Commit 8286895

Browse files
committed
custom mapping in doctrine.rst
1 parent 9919bca commit 8286895

File tree

1 file changed

+133
-0
lines changed

1 file changed

+133
-0
lines changed

reference/configuration/doctrine.rst

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,4 +499,137 @@ can be placed directly under ``doctrine.orm`` config level.
499499
This shortened version is commonly used in other documentation sections.
500500
Keep in mind that you can't use both syntaxes at the same time.
501501

502+
Custom Mapping
503+
--------------
504+
505+
It's possible to not rely on the auto mapping and set all the configuration
506+
on your own.
507+
508+
For example, you can overwrite the configuration directory for a given bundle.
509+
Keep in mind that the bundle you want to overwrite has to exist.
510+
511+
.. configuration-block::
512+
513+
.. code-block:: yaml
514+
515+
doctrine:
516+
# ...
517+
orm:
518+
# ...
519+
auto_mapping: true
520+
mappings:
521+
# ...
522+
AppBundle:
523+
dir: Resources/config/doctrine
524+
525+
.. code-block:: xml
526+
527+
<?xml version="1.0" charset="UTF-8" ?>
528+
<container xmlns="http://symfony.com/schema/dic/services"
529+
xmlns:doctrine="http://symfony.com/schema/dic/doctrine">
530+
531+
<doctrine:config>
532+
<doctrine:orm auto-mapping="true">
533+
<mapping name="AppBundle" dir="Resources/config/doctrine" />
534+
</doctrine:orm>
535+
</doctrine:config>
536+
</container>
537+
538+
.. code-block:: php
539+
540+
$container->loadFromExtension('doctrine', array(
541+
'orm' => array(
542+
'auto_mapping' => true,
543+
'mappings' => array(
544+
'AppBundle' => array('dir' => 'Resources/config/doctrine'),
545+
),
546+
),
547+
));
548+
549+
550+
You can also create new mappings. For example outside of the Symfony folder.
551+
552+
.. configuration-block::
553+
554+
.. code-block:: yaml
555+
556+
doctrine:
557+
# ...
558+
orm:
559+
# ...
560+
mappings:
561+
# ...
562+
SomeEntityNamespace:
563+
type: annotation
564+
dir: %kernel.root_dir%/../src/Entity
565+
is_bundle: false
566+
prefix: App\Entity
567+
alias: App
568+
569+
.. code-block:: xml
570+
571+
<?xml version="1.0" charset="UTF-8" ?>
572+
<container xmlns="http://symfony.com/schema/dic/services"
573+
xmlns:doctrine="http://symfony.com/schema/dic/doctrine">
574+
575+
<doctrine:config>
576+
<doctrine:orm>
577+
<mapping name="SomeEntityNamespace"
578+
type="annotation"
579+
dir="%kernel.root_dir%/../src/Entity"
580+
is-bundle="false"
581+
prefix="App\Entity"
582+
alias="App"
583+
/>
584+
</doctrine:orm>
585+
</doctrine:config>
586+
</container>
587+
588+
.. code-block:: php
589+
590+
$container->loadFromExtension('doctrine', array(
591+
'orm' => array(
592+
'auto_mapping' => true,
593+
'mappings' => array(
594+
'SomeEntityNamespace' => array(
595+
'type' => 'annotation',
596+
'dir' => '%kernel.root_dir%/../src/Entity',
597+
'is_bundle' => false,
598+
'prefix' => 'App\Entity',
599+
'alias' => 'App',
600+
),
601+
),
602+
),
603+
));
604+
605+
606+
Detecting a Mapping MetadataDriver
607+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
608+
609+
If the ``type`` on the bundle configuration isn't set,
610+
the DoctrineBundle will try to detect the correct metadata driver for
611+
the bundle. The DoctrineBundle will look for files following the filename pattern
612+
``[BundleDirectory]/[ResourceConfigurationDirectory]/*.orm.[Extension]``.
613+
The ``ResourceConfigurationDirectory``, by default, points to
614+
``Resources/config/doctrine``.
615+
616+
The bundle looks for (in this order) XML, YAML and PHP files.
617+
Every bundle can by default just register one ``MetadataDriver``.
618+
619+
If it wasn't possible to determine a ``MetadataDriver``, it will check if
620+
there is an ``Entity`` folder in the bundle's root directory.
621+
If the folder does not exist, Doctrine will fall back to using an annotation driver.
622+
623+
The Configuration Directory
624+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
625+
626+
The default configuration value depends on the used driver.
627+
For drivers that rely on the PHP files (annotation, staticphp) it will
628+
be ``[Bundle]/Entity``. For drivers that are using configuration
629+
files (XML, YAML, ...) it will be ``[Bundle]/Resources/config/doctrine``.
630+
631+
If you set the ``dir`` and the ``is_bundle`` bundle configuration to ``true``,
632+
it will be prefixed with the path of the current bundle and becomes
633+
the configuration directory.
634+
502635
.. _`DQL User Defined Functions`: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/cookbook/dql-user-defined-functions.html

0 commit comments

Comments
 (0)