gizlab / doctrine-bundle
Extending discriminator map
This package's canonical repository appears to be gone and the package has been frozen as a result.
Installs: 952
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=5.3.2
- stof/doctrine-extensions-bundle: ~1.1@dev
- symfony/framework-bundle: ~2.1
This package is not auto-updated.
Last update: 2024-07-30 05:03:11 UTC
README
Extending discriminator map with annotation and discriminator map helper
Installation:
- Add information into composer.json
{ require:{ ... "gizlab/doctrine-bundle":"dev-master" } }
- Update vendors with composer
php composer.phar update
- Register extension in AppKernel.php
... $bundles = array( new Gizlab\Bundle\DoctrineBundle\GizlabDoctrineBundle(), ); ...
and in app/config/config.yml
gizlab_doctrine: discriminator_listener: classes: [ ... here all classes for using with discriminator helper ... ]
-
How to use
For example, configuration for next base class
# app/config/config.yml ... gizlab_doctrine: discriminator_listener: classes: [Acme\Bundle\DemoBundle\Entity\BaseEntity ]
// src\Acme\Bundle\DemoBundle\Entity\BaseEntity.php namespace Acme/Bundle/DemoBundle/Entity use Doctrine\ORM\Mapping as ORM; /** * * @ORM\Entity * @ORM\InheritanceType("SINGLE_TABLE" or "JOINED") * @ORM\DiscriminatorColumn(name="<name_of_column>", type="<type_of_column>" ...) * */ abstract class BaseEntity { ... add fields for your entity ... }
// src\Acme\Bundle\DemoBundle\Entity\SomeEntity.php namespace Acme/Bundle/DemoBundle/Entity use Gizlab\Bundle\DoctrineBundle\Annotation\DiscriminatorMapEntry; /** * * @ORM\Entity * @DiscriminatorMapEntry("some_reference_type") */ class SomeEntity extends BaseEntity {}
// src\Acme\Bundle\DemoBundle\Entity\OtherEntity.php namespace Acme/Bundle/DemoBundle/Entity use Gizlab\Bundle\DoctrineBundle\Annotation\DiscriminatorMapEntry; /** * * @ORM\Entity * @DiscriminatorMapEntry("other_reference_type") */ class OtherEntity extends BaseEntity {}
and others too ...
- How to use DiscriminatorMapHelper service
Some where in controller ...
public function someAction() { $service = $this->get('gizlab.doctrine.discriminator_map_helper'); // Try to find global // To get repository $repository = $service->findRepositroy('some_reference_type'); // To get entity class $class = $service->findClass('some_reference_type'); // To find with exact parent class, $repository = $service->findRepositroy('some_reference_type', 'Acme\Bundle\DemoBundle\Entity\BaseEntity'); $class = $service->findClass('some_reference_type', 'Acme\Bundle\DemoBundle\Entity\BaseEntity'); }