Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/camelotproject/doctrine-inheritance-mapping
Doctrine inheritance mapping library
https://github.com/camelotproject/doctrine-inheritance-mapping
doctrine doctrine-orm inheritance-mapping orm symfony symfony-bundle
Last synced: 2 days ago
JSON representation
Doctrine inheritance mapping library
- Host: GitHub
- URL: https://github.com/camelotproject/doctrine-inheritance-mapping
- Owner: CamelotProject
- License: mit
- Created: 2019-10-06T10:47:59.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2019-12-04T06:25:48.000Z (almost 5 years ago)
- Last Synced: 2024-04-22T22:21:31.029Z (7 months ago)
- Topics: doctrine, doctrine-orm, inheritance-mapping, orm, symfony, symfony-bundle
- Language: PHP
- Homepage: https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/reference/inheritance-mapping.html
- Size: 32.2 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Camelot Doctrine Inheritance Mapping
====================================**NOTE:** For legacy PHP support (7.1+) please use the 1.0 branch.
Installation
------------Open a command console, enter your project directory and execute:
```console
$ composer require camelot/doctrine-inheritance-mapping
```This command requires you to have Composer installed globally, as explained
in the [installation chapter](https://getcomposer.org/doc/00-intro.md)
of the Composer documentation.### Standalone Configuration
```php
use Camelot\DoctrineInheritanceMapping\Annotation\DiscriminatorMapLoader;
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\DocParser;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;// Annotation reader & driver
$reader = new AnnotationReader(new DocParser());
$driver = new AnnotationDriver($reader);
$driver->addPaths(['/path/to/entities']);// Doctrine configuration
$config = new Configuration();
$config->setMetadataDriverImpl($driver);$classMetadata = new ClassMetadata(YourEntityName::class);
$loader = new DiscriminatorMapLoader($reader, $config);
$loader->loadClassMetadata($classMetadata);
```### Framework Configuration
#### Symfony Bundle
If using the Symfony Framework, you can enable the bundle by adding it to the
list of registered bundles in the `config/bundles.php` file of your project:```php
// config/bundles.phpreturn [
// ...
Camelot\DoctrineInheritanceMapping\Bridge\Symfony\DoctrineInheritanceMappingBundle::class => ['all' => true],
];
```Usage
-----### Single Table Inheritance
#### `@DiscriminatorMapItem` Annotation
Doctrine's [Single Table Inheritance][single-table-inheritance] is an
inheritance mapping strategy where all classes of a hierarchy are mapped to a
single database table.The mapping is handled by a "discriminator" column, defined in the mapping
definition of the parent class. This column value defines the entity class to
use, based on the inheritance hierarchy. This binds the parent to the children
and mixes responsibilities in the process.To separate these concerns, this library provides the `@DiscriminatorMapItem`
annotation for use in *each* entity in a hierarchy, replacing the parent class
use of Doctrine's `@DiscriminatorMap`, thus eliminating the need to update the
parent for each subclass.##### Example
###### Parent Class
```php