Config File

This is an overview of all of the options provided in ~/config/doctrine.php

Entity Manager

An entity manager (em) contains all of the information Doctrine needs to understand, retrieve, and manipulate a set of entities.

The name for the default entity manager is default. This is configured in the config file by the array key name under managers.

return [
    'managers' => [
        'default' => [  // This is the entity manager name
            ...
        ],

Within the entity manager name array are configuration settings. These are

  • dev - defaults to the APP_DEBUG setting of the application.

  • meta - The type of metadata configuration. Valid values are attributes, xml, simplified_xml, static_php, php. The majority of configurations use attributes or xml and these metadata configurtions are recommended.

  • connection - This is the DB_CONNECTION variable from the .env file by default. Connections are handled by Laravel. See the database.php config file.

  • namespaces - If your entities are not located in the configured app namespace, you can specify a different one here.

  • paths - The path(s) where the mapping configurations for your entities are located.

  • repository - An EntityRepository serves as a repository for entities with generic as well as business specific methods for retrieving entities.

  • decorator - A custom entity manager decorator to override the default.

  • proxies.namespace - Namespace (if different) specified for proxy classes.

  • proxies.path - The path where proxy classes should be generated.

  • proxies.auto_generate - Should proxy classes be generated every time an entity manager is created? Turn off for production.

  • events.subscribers - Subscribers should implement Doctrine\Common\EventSubscriber

  • events.listeners - Key should be event type. e.g. Doctrine\ORM\Events::onFlush. Value should be the listener class

  • filters - Filter system that allows the developer to add SQL to the conditional clauses of queries, regardless the place where the SQL is generated

Multiple Entity Managers

Multiple entity managers are supported in the configuration.

To use more than one entity manager, create another entry in the managers array.

return [
    'managers' => [
        'default' => [  // This is the first entity manager configuration
            ...
        ],
        'second' => [  // This is the second entity manager configuration
            ...
        ]

Example configuration

Namespace Alias

To use namespace alias, you just have to specify then as key of each namespace.

Example:

'managers' => [
    'default' => [
        ...
        'connection' => env('DB_CONNECTION', 'mysql'),
        'namespaces' => [
            'Foo' => 'App\Model\Foo\Entities',
            'Bar' => 'App\Model\Bar\Entities',
        ],
        'paths'      => [
            base_path('app')
        ],
        ...
    ]
]

Whenever you need to specify entities in these namespaces, you can simple use the alias as follow:

SELECT f FROM Foo:SomeEntity

or

EntityManager::getRepository('Bar:SomeEntity');

Extensions

Extensions can be enabled by adding them to this array. They provide additional functionality Entities (Timestamps, Loggable, etc.)

To use the extensions in this sample you must install the extensions package.

composer require laravel-doctrine/extensions

and follow the installation instructions.

'extensions'                => [
    //LaravelDoctrine\ORM\Extensions\TablePrefix\TablePrefixExtension::class,
    //LaravelDoctrine\Extensions\Timestamps\TimestampableExtension::class,
    //LaravelDoctrine\Extensions\SoftDeletes\SoftDeleteableExtension::class,
    //LaravelDoctrine\Extensions\Sluggable\SluggableExtension::class,
    //LaravelDoctrine\Extensions\Sortable\SortableExtension::class,
    //LaravelDoctrine\Extensions\Tree\TreeExtension::class,
    //LaravelDoctrine\Extensions\Loggable\LoggableExtension::class,
    //LaravelDoctrine\Extensions\Blameable\BlameableExtension::class,
    //LaravelDoctrine\Extensions\IpTraceable\IpTraceableExtension::class,
    //LaravelDoctrine\Extensions\Translatable\TranslatableExtension::class
],

Custom Types

Custom types are classes that allow Doctrine to marshal data to/from the data source in a custom format.

To register a custom type simple add the class to this list. For more information on custom types refer to the Doctrine documentation.

Custom Functions

These are classes that extend the functionality of Doctrine’s DQL language. More information on what functions are available at the repository

To use the extensions in this sample you must install the extensions package:

doctrine require laravel-doctrine/extensions

and follow the installation instructions.

If you include the BeberleiExtensionsServiceProvider all custom functions will automatically be registered.

To add a function simply add it to the correct list using this format: 'FUNCTION_NAME' => 'Path\To\Class'

/*
|--------------------------------------------------------------------------
| DQL custom datetime functions
|--------------------------------------------------------------------------
*/
'custom_datetime_functions' => [],
/*
|--------------------------------------------------------------------------
| DQL custom numeric functions
|--------------------------------------------------------------------------
*/
'custom_numeric_functions'  => [],
/*
|--------------------------------------------------------------------------
| DQL custom string functions
|--------------------------------------------------------------------------
*/
'custom_string_functions'   => [],

Custom Hydration Modes

This option enables you to register your Hydrator classes to use as custom hydration modes. For more information about custom hydration modes see Doctrine documentation.

To register custom hydrator, add it to the list in following format:

'hydrationModeName' => MyHydrator::class

/*
|--------------------------------------------------------------------------
| Register custom hydrators
|--------------------------------------------------------------------------
*/
'custom_hydration_modes'     => [
    'hydrationModeName' => MyHydrator::class,
],

Logger

Enable logging of Laravel Doctrine and Doctrine by using the logger functionality.

Available loggers

  • LaravelDoctrine\ORM\Loggers\LaravelDebugbarLogger

  • LaravelDoctrine\ORM\Loggers\ClockworkLogger

  • LaravelDoctrine\ORM\Loggers\FileLogger

'logger' => env('DOCTRINE_LOGGER', false),

Cache

Caches will be used to cache metadata, results, and queries.

Available cache providers

  • apc

  • array

  • file

  • memcached

  • redis

Config settings

  • cache.default - The default cache provider to use.

  • cache.namespace - Will add namespace to the cache key. This is useful if you need extra control over handling key names collisions in your cache solution.

  • cache.second_level - The Second Level Cache is designed to reduce the amount of necessary database access. It sits between your application and the database to avoid the number of database hits as much as possible. When turned on, entities will be first searched in cache and if they are not found, a database query will be fired an then the entity result will be stored in a cache provider. When used, READ_ONLY is mostly used. ReadOnly cache can do reads, inserts and deletes, and cannot perform updates.

  • cache.metadata - Your class metadata can be parsed from a few different sources like YAML, XML, Annotations, etc. Instead of parsing this information on each request we should cache it using one of the cache drivers.

  • cache.query - Cache transformation of a DQL query to its SQL counterpart.

  • cache.result - The result cache can be used to cache the results of your

  • queries so you don’t have to query the database or hydrate the data again after the first time.

Gedmo

This is an option for use with Extensions.

To use this option you must first install the extensions package

composer require laravel-doctrine/extensions

and follow the installation instructions.


This is documentation for laravel-doctrine/orm. Please add your ★ star to the project.