You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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:
I modified the PHP driver to be able to do this (
lib/Doctrine/Persistence/Mapping/Driver/PHPDriver.php
):Is there any argument against doing this? The big advantage here is that you at least have a type hint.
The text was updated successfully, but these errors were encountered: