-
-
Notifications
You must be signed in to change notification settings - Fork 72
Open
Description
When defining ORM mapping using the php
driver there is $metadata
variable floating around in the mapping file. IDE's complain about type hinting.
It would be nice to be able to return a static function that gets the $metadata variable as an argument, so then you can write the mapping in php like this:
// config/orm/mapping/App.Entity.User.php
<?php
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder;
use Doctrine\ORM\Mapping\ClassMetadata;
return static function (ClassMetadata $metadata): void
{
$builder = new ClassMetadataBuilder($metadata);
// ...
};
I modified the PHP driver to be able to do this (lib/Doctrine/Persistence/Mapping/Driver/PHPDriver.php
):
// ...
protected function loadMappingFile($file)
{
$metadata = $this->metadata;
$mapping = include $file;
if (is_callable($mapping)) {
$mapping($metadata);
}
return [$metadata->getName() => $metadata];
}
// ...
Is there any argument against doing this? The big advantage here is that you at least have a type hint.
DominicLuidold
Metadata
Metadata
Assignees
Labels
No labels