gordinskiy/doctrine-fluent-mappin-bundle

Symfony Bundle for Fluent Mapping Driver from laravel-doctrine

v0.0.3 2023-05-07 18:13 UTC

README

Latest Stable Version Run Tests codecov License

Symfony Bundle for laravel-doctrine/fluent that provide alternative PHP Mapping Driver for Doctrine ORM.
Works as extension for doctrine/DoctrineBundle.

How It Works

Doctrine provides the ability to implement your own mapping driver (Documentation).
Fluent Mapping Driver - Doctrine mapping driver implementation from authors of laravel-doctrine/orm (Documentation).

allows you to manage your mappings in an Object Oriented approach, separating your entities from your mapping configuration without the need for configuration files like XML or YAML.

Despite the vendor name, this package does not contain any dependency on Laravel framework or its components.

DoctrineBundle - Symfony bundle that provides integration of Doctrine projects with Symfony framework (Documentation).

DoctrineFluentMappingBundle configures Fluent Mapping Driver and registers it as default mapping driver for DoctrineBundle by replacing definition of doctrine.orm.default_metadata_driver.

Installation

Run this command in your terminal:
composer require gordinskiy/doctrine-fluent-mapping-bundle

If you don't use Symfony Flex, you must enable the bundle manually in the application:

// config/bundles.php    
return [  
    ...  
    Gordinskiy\DoctrineFluentMappingBundle\DoctrineFluentMappingBundle::class => ['all' => true],  
];

Configuration

Create config/packages/doctrine_fluent.yaml file and list your entity mappings in it:

doctrine_fluent:
    mappings:
        - Infrastructure\Doctrine\Mappings\UserMapping
        - Infrastructure\Doctrine\Mappings\RoleMapping
        - Infrastructure\Doctrine\Mappings\AccountMapping

Configure by directories list

You can also configure mappings by directories list:

doctrine_fluent:
    mappings_paths:
        - src/Context/Infrastructure/Doctrine/Mappings
        - src/SomeAnotherContext/Infrastructure/Doctrine/Mappings
        - src/ActivityLog/Infrastructure/Doctrine/Mappings
        - src/OneMoreContext/Infrastructure/Doctrine/Mappings

You can use absolute paths or paths relative to the project root directory.
All classes in these directories that implement Mapping interface will be automatically registered as mappings.