We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
The wrong Manager can be selected if configured Managers have similar namespaces.
The wrong Manager is returned when two or more Managers with similar namespaces are configured.
The correct Manager should be selected.
Configure Manager A with the namespace:
A
App\Entity
and Manager B with:
B
App\EntityFoo
MappingDriverChain::isTransient will select A for a B-configured Manager because:
MappingDriverChain::isTransient
str_starts_with($className, $namespace) returns true for both.
str_starts_with($className, $namespace)
true
A solution could be to find the best match rather than selecting the first driver that matches the namespace prefix.
Find the best namespace overlap:
public function isTransient(string $className): bool { $driver = $this->findBestMatchingDriver($className) ?? $this->defaultDriver; return $driver ? $driver->isTransient($className) : true; } private function findBestMatchingDriver(string $className): ?MappingDriver { $bestDriver = null; $maxOverlap = 0; foreach ($this->drivers as $namespace => $driver) { if ( ! str_starts_with($className, $namespace)) { continue; } $currentOverlap = similar_text($className, $namespace); if ($currentOverlap > $maxOverlap) { $maxOverlap = $currentOverlap; $bestDriver = $driver; } } return $bestDriver; }
I could create a pull request with tests if this approach is heading in the right direction. A huge thank you to all contributors!
The text was updated successfully, but these errors were encountered:
Wouldn't doing something similar as
persistence/src/Persistence/Mapping/Driver/SymfonyFileLocator.php
Line 137 in 2f078b0
Also, does this affect 4.0.0 only, or should it be contributed to 3.x as a bugfix?
Sorry, something went wrong.
What about this case? (although this might be a misconfiguration in the first place)
Class: App\Entity\Foo\Bar
App\Entity\Foo\Bar
Namespace Driver A App\Entity Namespace Driver B App\Entity\Foo
App\Entity\Foo
It will match both even with an appended backslash
--
This should be contributed to 3.x as well
This case does not look realistic… I mean who would nest namespaces?
No branches or pull requests
Bug Report
Summary
The wrong Manager can be selected if configured Managers have similar namespaces.
Current behavior
The wrong Manager is returned when two or more Managers with similar namespaces are configured.
Expected behavior
The correct Manager should be selected.
How to reproduce
Configure Manager
A
with the namespace:App\Entity
and Manager
B
with:App\EntityFoo
MappingDriverChain::isTransient
will selectA
for aB
-configured Manager because:str_starts_with($className, $namespace)
returnstrue
for both.A solution could be to find the best match rather than selecting the first driver that matches the namespace prefix.
Solution proposal
Find the best namespace overlap:
I could create a pull request with tests if this approach is heading in the right direction. A huge thank you to all contributors!
The text was updated successfully, but these errors were encountered: