Skip to content

Fix ClassMetadata::fullyQualifiedClassName #11925

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: 4.0.x
Choose a base branch
from

Conversation

WinterSilence
Copy link
Contributor

Fix for cases like as:
entity class in namespace X, listener class in global namespace and passed as ::class constant (#[\Doctrine\ORM\Mapping\EntityListeners([\ProductImageFile::class])]). In this case PHP convert class name to ProductImageFile when pass to EntityListeners::__construct().

Fix for cases like as: 
entity class in namespace X, listener class in global namespace and defined as ::class constant (`#[\Doctrine\ORM\Mapping\EntityListeners([\ProductImageFile::class])]`)
In this case PHP convert class name to `ProductImageFile` in argument.
@greg0ire
Copy link
Member

This should come with a test, and shouldn't break existing tests

@WinterSilence
Copy link
Contributor Author

WinterSilence commented Apr 27, 2025

@greg0ire

and shouldn't break existing tests

it's not possible, I can only update existed tests

@WinterSilence
Copy link
Contributor Author

WinterSilence commented May 2, 2025

@greg0ire tests extended and fixed

@greg0ire
Copy link
Member

greg0ire commented May 2, 2025

tests extended and fixed

On top of this, you should create an entirely new test function showcasing the use case you described in your PR description. It might help me understand what this is all about (I must admit it's not entirely clear right now).

@WinterSilence
Copy link
Contributor Author

WinterSilence commented May 2, 2025

@greg0ire

I must admit it's not entirely clear right now

I post full case here:

<?php
namespace Entities;

#[\Doctrine\ORM\Mapping\Entity]
#[\Doctrine\ORM\Mapping\Table(name: 'product_images')]
#[\Doctrine\ORM\Mapping\EntityListeners([\ProductImageFile::class])]
class ProductImage
{
   ...
}
<?php
class ProductImageFile
{
    ...

    #[\Doctrine\ORM\Mapping\PostRemove]
    public function onRemoveEntity(\Entities\ProductImage $productImage): void
    {
        $this->deleteFile($productImage);
    }
}

When PHP create instance of #[\Doctrine\ORM\Mapping\EntityListeners([\ProductImageFile::class])], passed listener class converted to ProductImageFile. Entity class in namespace Entities and ClassMetadata::fullyQualifiedClassName() convert class name to Entities\ProductImageFile, this class not exists and it's throw exception at execution. I.e. ClassMetadata::fullyQualifiedClassName() may generates not existed class names.

@WinterSilence
Copy link
Contributor Author

@greg0ire PR updated. I don't think it's BC, because not existed class couldn't be created later.

@greg0ire
Copy link
Member

greg0ire commented May 2, 2025

If you don't think it's a breaking change, then why are you targeting 4.0.x?

@greg0ire
Copy link
Member

greg0ire commented May 2, 2025

I post full case here:

You should probably create a functional test case of that.

@WinterSilence
Copy link
Contributor Author

@greg0ire

If you don't think it's a breaking change, then why are you targeting 4.0.x?

It's not critical problem, but I want to fix it in future versions

You should probably create a functional test case of that.

It's hard to reproduce in test - I still learn Doctrine. testFullyQualifiedClassNameNotAppendNamespaceToClassInGlobalNamespace cover all same cases

@WinterSilence WinterSilence requested a review from greg0ire May 24, 2025 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants