PHP code example of camelot / doctrine-inheritance-mapping

1. Go to this page and download the library: Download camelot/doctrine-inheritance-mapping library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

camelot / doctrine-inheritance-mapping example snippets


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);

// config/bundles.php

return [
    // ...
    Camelot\DoctrineInheritanceMapping\Bridge\Symfony\DoctrineInheritanceMappingBundle::class => ['all' => true],
];


namespace App\Entity;

use Camelot\DoctrineInheritanceMapping\Annotation\DiscriminatorMapItem;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity()
 * @ORM\InheritanceType("SINGLE_TABLE")
 * @DiscriminatorMapItem(value="SingleTable")
 */
class SingleTable
{
    // ...
}



namespace App\Entity;

use Camelot\DoctrineInheritanceMapping\Annotation\DiscriminatorMapItem;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity()
 * @DiscriminatorMapItem(value="SingleTableChild")
 */
class SingleTableChild extends SingleTable
{
    // ...
}