Nettrine ORM – ResolveTargetEntityListener

MajklNajt
Člen | 471
+
0
-

Ahoj,

používate niekto vo svojich projektoch s doktrínou aj ResolveTargetEntityListener na mapovanie entít (napr. robím relácie medzi entitami z rôznych modulov pomocou interface)? v Nettrine mi chýbala možnosť si toto jednoducho nastaviť v configu, tak som si spravil vlastnú CompilerExtension:

declare(strict_types=1);

namespace App\DI;

use Doctrine\ORM\Tools\ResolveTargetEntityListener;
use Nette\DI\CompilerExtension;
use Nette\Schema\Expect;
use Nette\Schema\Schema;

final class OrmRtelExtension extends CompilerExtension
{
    public function getConfigSchema(): Schema
    {
        return Expect::structure([
            "targetEntityMappings" => Expect::array()
        ]);
    }

    public function loadConfiguration(): void
    {
        $builder = $this->getContainerBuilder();
        if ($this->config->targetEntityMappings) {
            $listener = $builder->addDefinition("rtel")
                ->setType(ResolveTargetEntityListener::class)
                ->addTag("nettrine.subscriber");
            foreach ($this->config->targetEntityMappings as $originalEntity => $targetEntity) {
                $listener->addSetup("addResolveTargetEntity", [$originalEntity, $targetEntity, []]);
            }
        }
    }
}

v configu si potom iba napárujem entity:

extensions:
	orm.rtel: App\DI\OrmRtelExtension

orm.rtel:
    targetEntityMappings:
        ICoreUser: App\Model\User
		IOtherEntity: App\Model\OtherEntity

Chcel by som spraviť PR do Nettrine, len ma zaujíma, či to vôbec má význam aj pre niekoho iného a či takéto riešenie je v súlade s politikou Nettrine – čo na to @Felix?

Je githube je na to aj založený issue, ale nikto sa tam tomu nevenuje: https://github.com/…rm/issues/52

Editoval MajklNajt (2. 10. 2019 16:24)