-
-
Notifications
You must be signed in to change notification settings - Fork 421
drop annotation support with entities #1126
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 0 additions & 26 deletions
26
src/DependencyInjection/CompilerPass/DoctrineAttributesCheckPass.php
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,6 @@ | |
|
||
use Doctrine\DBAL\Connection; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Doctrine\ORM\Mapping\Driver\AnnotationDriver; | ||
use Doctrine\ORM\Mapping\Driver\AttributeDriver; | ||
use Doctrine\ORM\Mapping\MappingException as ORMMappingException; | ||
use Doctrine\ORM\Mapping\NamingStrategy; | ||
|
@@ -25,7 +24,6 @@ | |
use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; | ||
use Doctrine\Persistence\Mapping\MappingException as PersistenceMappingException; | ||
use Symfony\Bundle\MakerBundle\Util\ClassNameDetails; | ||
use Symfony\Bundle\MakerBundle\Util\PhpCompatUtil; | ||
|
||
/** | ||
* @author Fabien Potencier <[email protected]> | ||
|
@@ -36,27 +34,12 @@ | |
*/ | ||
final class DoctrineHelper | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $entityNamespace; | ||
private $phpCompatUtil; | ||
private $registry; | ||
|
||
/** | ||
* @var array|null | ||
*/ | ||
private $mappingDriversByPrefix; | ||
|
||
private $attributeMappingSupport; | ||
|
||
public function __construct(string $entityNamespace, PhpCompatUtil $phpCompatUtil, ManagerRegistry $registry = null, bool $attributeMappingSupport = false, array $annotatedPrefixes = null) | ||
{ | ||
public function __construct( | ||
private string $entityNamespace, | ||
private ?ManagerRegistry $registry = null, | ||
private ?array $mappingDriversByPrefix = null, | ||
) { | ||
$this->entityNamespace = trim($entityNamespace, '\\'); | ||
$this->phpCompatUtil = $phpCompatUtil; | ||
$this->registry = $registry; | ||
$this->attributeMappingSupport = $attributeMappingSupport; | ||
$this->mappingDriversByPrefix = $annotatedPrefixes; | ||
} | ||
|
||
public function getRegistry(): ManagerRegistry | ||
|
@@ -114,7 +97,7 @@ public function doesClassUseDriver(string $className, string $driverClass): bool | |
} | ||
|
||
foreach ($metadataDriver->getDrivers() as $namespace => $driver) { | ||
if (0 === strpos($className, $namespace)) { | ||
if (str_starts_with($className, $namespace)) { | ||
return $this->isInstanceOf($driver, $driverClass); | ||
} | ||
} | ||
|
@@ -125,27 +108,22 @@ public function doesClassUseDriver(string $className, string $driverClass): bool | |
$managerName = array_search($em, $this->getRegistry()->getManagers(), true); | ||
|
||
foreach ($this->mappingDriversByPrefix[$managerName] as [$prefix, $prefixDriver]) { | ||
if (0 === strpos($className, $prefix)) { | ||
if (str_starts_with($className, $prefix)) { | ||
return $this->isInstanceOf($prefixDriver, $driverClass); | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public function isClassAnnotated(string $className): bool | ||
{ | ||
return $this->doesClassUseDriver($className, AnnotationDriver::class); | ||
} | ||
|
||
public function doesClassUsesAttributes(string $className): bool | ||
{ | ||
return $this->doesClassUseDriver($className, AttributeDriver::class); | ||
} | ||
|
||
public function isDoctrineSupportingAttributes(): bool | ||
{ | ||
return $this->isDoctrineInstalled() && $this->attributeMappingSupport; | ||
return $this->isDoctrineInstalled(); | ||
} | ||
|
||
public function getEntitiesForAutocomplete(): array | ||
|
@@ -168,18 +146,14 @@ public function getEntitiesForAutocomplete(): array | |
|
||
public function getMetadata(string $classOrNamespace = null, bool $disconnected = false): array|ClassMetadata | ||
{ | ||
// Invalidating the cached AnnotationDriver::$classNames to find new Entity classes | ||
// Invalidating the cached AttributeDriver::$classNames to find new Entity classes | ||
foreach ($this->mappingDriversByPrefix ?? [] as $managerName => $prefixes) { | ||
foreach ($prefixes as [$prefix, $annotationDriver]) { | ||
if (null !== $annotationDriver) { | ||
if ($annotationDriver instanceof AnnotationDriver) { | ||
$classNames = (new \ReflectionClass(AnnotationDriver::class))->getProperty('classNames'); | ||
} else { | ||
$classNames = (new \ReflectionClass(AttributeDriver::class))->getProperty('classNames'); | ||
} | ||
foreach ($prefixes as [$prefix, $attributeDriver]) { | ||
if ($attributeDriver instanceof AttributeDriver) { | ||
$classNames = (new \ReflectionClass(AttributeDriver::class))->getProperty('classNames'); | ||
|
||
$classNames->setAccessible(true); | ||
$classNames->setValue($annotationDriver, null); | ||
$classNames->setValue($attributeDriver, null); | ||
} | ||
} | ||
} | ||
|
@@ -205,14 +179,11 @@ public function getMetadata(string $classOrNamespace = null, bool $disconnected | |
} | ||
|
||
if (null === $this->mappingDriversByPrefix) { | ||
// Invalidating the cached AnnotationDriver::$classNames to find new Entity classes | ||
// Invalidating the cached AttributeDriver::$classNames to find new Entity classes | ||
$metadataDriver = $em->getConfiguration()->getMetadataDriverImpl(); | ||
|
||
if ($this->isInstanceOf($metadataDriver, MappingDriverChain::class)) { | ||
foreach ($metadataDriver->getDrivers() as $driver) { | ||
if ($this->isInstanceOf($driver, AnnotationDriver::class)) { | ||
$classNames->setValue($driver, null); | ||
} | ||
|
||
if ($this->isInstanceOf($driver, AttributeDriver::class)) { | ||
$classNames->setValue($driver, null); | ||
} | ||
|
@@ -229,7 +200,7 @@ public function getMetadata(string $classOrNamespace = null, bool $disconnected | |
return $m; | ||
} | ||
|
||
if (0 === strpos($m->getName(), $classOrNamespace)) { | ||
if (str_starts_with($m->getName(), $classOrNamespace)) { | ||
$metadata[$m->getName()] = $m; | ||
} | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After we remove that one if statement we talked about in this PR, is this used anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It won't be when we're all said and done, but
make:user
&&make:reset-password
are still calling on this.. they need to be refactored after this PR && the CSM one.