From b93f3769bffea9cd942f8d49c3b5c736c44cf1a1 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Wed, 28 Dec 2022 12:08:39 -0500 Subject: [PATCH 1/7] WIP - bump minimum service contracts req --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b063d12af..fd87de4e4 100644 --- a/composer.json +++ b/composer.json @@ -44,7 +44,8 @@ "conflict": { "doctrine/orm": "<2.10", "doctrine/doctrine-bundle": "<2.4", - "symfony/doctrine-bridge": "<5.4" + "symfony/doctrine-bridge": "<5.4", + "symfony/service-contracts": "<2.5" }, "autoload": { "psr-4": { "Symfony\\Bundle\\MakerBundle\\": "src/" } From b02fae1a4f03fd89dc46158169243312df8bfb35 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Wed, 28 Dec 2022 12:36:23 -0500 Subject: [PATCH 2/7] tmp - disable annotation support in tests --- tests/Doctrine/EntityRegeneratorTest.php | 6 +++--- tests/Maker/MakeControllerTest.php | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/Doctrine/EntityRegeneratorTest.php b/tests/Doctrine/EntityRegeneratorTest.php index ec9760e58..833a6c81b 100644 --- a/tests/Doctrine/EntityRegeneratorTest.php +++ b/tests/Doctrine/EntityRegeneratorTest.php @@ -159,9 +159,9 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load 'utf8' => true, ], 'http_method_override' => false, - 'annotations' => [ - 'enabled' => true, - ], +// 'annotations' => [ +// 'enabled' => true, +// ], ]); $dbal = [ diff --git a/tests/Maker/MakeControllerTest.php b/tests/Maker/MakeControllerTest.php index 984131bce..3b22c3265 100644 --- a/tests/Maker/MakeControllerTest.php +++ b/tests/Maker/MakeControllerTest.php @@ -29,11 +29,11 @@ private function getControllerTest(): MakerTestDetails return $this ->createMakerTest() ->preRun(function (MakerTestRunner $runner) { - if ($runner->getSymfonyVersion() < 60000) { - // Because MakeController::configureDependencies() is executed in the main thread, - // we need to manually add in `doctrine/annotations` for Symfony 5.4 tests. - $runner->runProcess('composer require doctrine/annotations'); - } +// if ($runner->getSymfonyVersion() < 60000) { +// // Because MakeController::configureDependencies() is executed in the main thread, +// // we need to manually add in `doctrine/annotations` for Symfony 5.4 tests. +// $runner->runProcess('composer require doctrine/annotations'); +// } }); } From c4143a977d4f7131e0fdbd1dc2205df55db76b01 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Wed, 28 Dec 2022 12:52:54 -0500 Subject: [PATCH 3/7] remove / disable annotation references --- src/Doctrine/EntityRegenerator.php | 2 +- src/Maker/MakeController.php | 8 ++++---- src/Maker/MakeRegistrationForm.php | 16 ++++++++-------- src/Maker/MakeResetPassword.php | 2 +- src/Util/ClassDetails.php | 10 ++++++++++ 5 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/Doctrine/EntityRegenerator.php b/src/Doctrine/EntityRegenerator.php index 77e6ce02e..7fe70e241 100644 --- a/src/Doctrine/EntityRegenerator.php +++ b/src/Doctrine/EntityRegenerator.php @@ -204,7 +204,7 @@ private function createClassManipulator(string $classPath): ClassSourceManipulat // if properties need to be generated then, by definition, // some non-annotation config is being used, and so, the // properties should not have annotations added to them - useAttributesForDoctrineMapping: false + useAttributesForDoctrineMapping: true // We always want to use attributes? ); } diff --git a/src/Maker/MakeController.php b/src/Maker/MakeController.php index e5a8f78db..e62f967d6 100644 --- a/src/Maker/MakeController.php +++ b/src/Maker/MakeController.php @@ -120,10 +120,10 @@ public function configureDependencies(DependencyBuilder $dependencies): void return; } - $dependencies->addClassDependency( - Annotation::class, - 'doctrine/annotations' - ); +// $dependencies->addClassDependency( +// Annotation::class, +// 'doctrine/annotations' +// ); } private function isTwigInstalled(): bool diff --git a/src/Maker/MakeRegistrationForm.php b/src/Maker/MakeRegistrationForm.php index 5bd4eacab..c20e0208c 100644 --- a/src/Maker/MakeRegistrationForm.php +++ b/src/Maker/MakeRegistrationForm.php @@ -143,11 +143,11 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma // see if it makes sense to add the UniqueEntity constraint $userClassDetails = new ClassDetails($this->userClass); - $addAnnotation = false; - if (!$userClassDetails->doesDocBlockContainAnnotation('@UniqueEntity')) { - $addAnnotation = $io->confirm(sprintf('Do you want to add a @UniqueEntity validation annotation on your %s class to make sure duplicate accounts aren\'t created?', Str::getShortClassName($this->userClass))); + $addAttribute = false; + if (!$userClassDetails->isClassUnique()) { + $addAttribute = $io->confirm(sprintf('Do you want to add a #[UniqueEntity] validation attribute on your %s class to make sure duplicate accounts aren\'t created?', Str::getShortClassName($this->userClass))); } - $this->addUniqueEntityConstraint = $addAnnotation; + $this->addUniqueEntityConstraint = $addAttribute; $this->willVerifyEmail = $io->confirm('Do you want to send an email to verify the user\'s email address after registration?', true); @@ -488,10 +488,10 @@ private function getMissingComponentsComposerMessage(): ?string public function configureDependencies(DependencyBuilder $dependencies): void { - $dependencies->addClassDependency( - Annotation::class, - 'doctrine/annotations' - ); +// $dependencies->addClassDependency( +// Annotation::class, +// 'doctrine/annotations' +// ); $dependencies->addClassDependency( AbstractType::class, diff --git a/src/Maker/MakeResetPassword.php b/src/Maker/MakeResetPassword.php index ad2521156..635bd1a9c 100644 --- a/src/Maker/MakeResetPassword.php +++ b/src/Maker/MakeResetPassword.php @@ -122,7 +122,7 @@ public function configureDependencies(DependencyBuilder $dependencies): void ORMDependencyBuilder::buildDependencies($dependencies); - $dependencies->addClassDependency(Annotation::class, 'annotations'); +// $dependencies->addClassDependency(Annotation::class, 'annotations'); // reset-password-bundle 1.6 includes the ability to generate a fake token. // we need to check that version 1.6 is installed diff --git a/src/Util/ClassDetails.php b/src/Util/ClassDetails.php index 337609494..25463f4ff 100644 --- a/src/Util/ClassDetails.php +++ b/src/Util/ClassDetails.php @@ -11,6 +11,8 @@ namespace Symfony\Bundle\MakerBundle\Util; +use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; + /** * @internal */ @@ -61,6 +63,7 @@ public function getPath(): string * An imperfect, but simple way to check for the presence of an annotation. * * @param string $annotation The annotation - e.g. @UniqueEntity + * @deprecated We dont support anntations anymore.. */ public function doesDocBlockContainAnnotation(string $annotation): bool { @@ -72,4 +75,11 @@ public function doesDocBlockContainAnnotation(string $annotation): bool return str_contains($docComment, $annotation); } + + public function isClassUnique(): bool + { + $reflected = new \ReflectionClass($this->fullClassName); + + return !empty($reflected->getAttributes(UniqueEntity::class)); + } } From e1c2b116ad880ff97a015d8d6e9a75ac178f9b24 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Wed, 28 Dec 2022 13:07:54 -0500 Subject: [PATCH 4/7] yup we still need this to support xml mapping --- src/Doctrine/EntityRegenerator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Doctrine/EntityRegenerator.php b/src/Doctrine/EntityRegenerator.php index 7fe70e241..3b3aea7b7 100644 --- a/src/Doctrine/EntityRegenerator.php +++ b/src/Doctrine/EntityRegenerator.php @@ -202,9 +202,9 @@ private function createClassManipulator(string $classPath): ClassSourceManipulat sourceCode: $this->fileManager->getFileContents($classPath), overwrite: $this->overwrite, // if properties need to be generated then, by definition, - // some non-annotation config is being used, and so, the + // some non-annotation config is being used (e.g. XML), and so, the // properties should not have annotations added to them - useAttributesForDoctrineMapping: true // We always want to use attributes? + useAttributesForDoctrineMapping: false ); } From 63e25bdd19f70605cfc2648c31e0b6bd862c2760 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Wed, 28 Dec 2022 14:52:49 -0500 Subject: [PATCH 5/7] Revert "WIP - bump minimum service contracts req" This reverts commit b93f3769bffea9cd942f8d49c3b5c736c44cf1a1. --- composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index fd87de4e4..b063d12af 100644 --- a/composer.json +++ b/composer.json @@ -44,8 +44,7 @@ "conflict": { "doctrine/orm": "<2.10", "doctrine/doctrine-bundle": "<2.4", - "symfony/doctrine-bridge": "<5.4", - "symfony/service-contracts": "<2.5" + "symfony/doctrine-bridge": "<5.4" }, "autoload": { "psr-4": { "Symfony\\Bundle\\MakerBundle\\": "src/" } From 2e8bfafa0118150e5900dc4e1cb01c8806df83f3 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Wed, 28 Dec 2022 14:54:40 -0500 Subject: [PATCH 6/7] revert changes in subsequent prs --- src/Maker/MakeController.php | 8 ++++---- src/Maker/MakeRegistrationForm.php | 16 ++++++++-------- src/Maker/MakeResetPassword.php | 2 +- src/Util/ClassDetails.php | 10 ---------- tests/Maker/MakeControllerTest.php | 10 +++++----- 5 files changed, 18 insertions(+), 28 deletions(-) diff --git a/src/Maker/MakeController.php b/src/Maker/MakeController.php index e62f967d6..e5a8f78db 100644 --- a/src/Maker/MakeController.php +++ b/src/Maker/MakeController.php @@ -120,10 +120,10 @@ public function configureDependencies(DependencyBuilder $dependencies): void return; } -// $dependencies->addClassDependency( -// Annotation::class, -// 'doctrine/annotations' -// ); + $dependencies->addClassDependency( + Annotation::class, + 'doctrine/annotations' + ); } private function isTwigInstalled(): bool diff --git a/src/Maker/MakeRegistrationForm.php b/src/Maker/MakeRegistrationForm.php index c20e0208c..5bd4eacab 100644 --- a/src/Maker/MakeRegistrationForm.php +++ b/src/Maker/MakeRegistrationForm.php @@ -143,11 +143,11 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma // see if it makes sense to add the UniqueEntity constraint $userClassDetails = new ClassDetails($this->userClass); - $addAttribute = false; - if (!$userClassDetails->isClassUnique()) { - $addAttribute = $io->confirm(sprintf('Do you want to add a #[UniqueEntity] validation attribute on your %s class to make sure duplicate accounts aren\'t created?', Str::getShortClassName($this->userClass))); + $addAnnotation = false; + if (!$userClassDetails->doesDocBlockContainAnnotation('@UniqueEntity')) { + $addAnnotation = $io->confirm(sprintf('Do you want to add a @UniqueEntity validation annotation on your %s class to make sure duplicate accounts aren\'t created?', Str::getShortClassName($this->userClass))); } - $this->addUniqueEntityConstraint = $addAttribute; + $this->addUniqueEntityConstraint = $addAnnotation; $this->willVerifyEmail = $io->confirm('Do you want to send an email to verify the user\'s email address after registration?', true); @@ -488,10 +488,10 @@ private function getMissingComponentsComposerMessage(): ?string public function configureDependencies(DependencyBuilder $dependencies): void { -// $dependencies->addClassDependency( -// Annotation::class, -// 'doctrine/annotations' -// ); + $dependencies->addClassDependency( + Annotation::class, + 'doctrine/annotations' + ); $dependencies->addClassDependency( AbstractType::class, diff --git a/src/Maker/MakeResetPassword.php b/src/Maker/MakeResetPassword.php index 635bd1a9c..ad2521156 100644 --- a/src/Maker/MakeResetPassword.php +++ b/src/Maker/MakeResetPassword.php @@ -122,7 +122,7 @@ public function configureDependencies(DependencyBuilder $dependencies): void ORMDependencyBuilder::buildDependencies($dependencies); -// $dependencies->addClassDependency(Annotation::class, 'annotations'); + $dependencies->addClassDependency(Annotation::class, 'annotations'); // reset-password-bundle 1.6 includes the ability to generate a fake token. // we need to check that version 1.6 is installed diff --git a/src/Util/ClassDetails.php b/src/Util/ClassDetails.php index 25463f4ff..337609494 100644 --- a/src/Util/ClassDetails.php +++ b/src/Util/ClassDetails.php @@ -11,8 +11,6 @@ namespace Symfony\Bundle\MakerBundle\Util; -use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; - /** * @internal */ @@ -63,7 +61,6 @@ public function getPath(): string * An imperfect, but simple way to check for the presence of an annotation. * * @param string $annotation The annotation - e.g. @UniqueEntity - * @deprecated We dont support anntations anymore.. */ public function doesDocBlockContainAnnotation(string $annotation): bool { @@ -75,11 +72,4 @@ public function doesDocBlockContainAnnotation(string $annotation): bool return str_contains($docComment, $annotation); } - - public function isClassUnique(): bool - { - $reflected = new \ReflectionClass($this->fullClassName); - - return !empty($reflected->getAttributes(UniqueEntity::class)); - } } diff --git a/tests/Maker/MakeControllerTest.php b/tests/Maker/MakeControllerTest.php index 3b22c3265..984131bce 100644 --- a/tests/Maker/MakeControllerTest.php +++ b/tests/Maker/MakeControllerTest.php @@ -29,11 +29,11 @@ private function getControllerTest(): MakerTestDetails return $this ->createMakerTest() ->preRun(function (MakerTestRunner $runner) { -// if ($runner->getSymfonyVersion() < 60000) { -// // Because MakeController::configureDependencies() is executed in the main thread, -// // we need to manually add in `doctrine/annotations` for Symfony 5.4 tests. -// $runner->runProcess('composer require doctrine/annotations'); -// } + if ($runner->getSymfonyVersion() < 60000) { + // Because MakeController::configureDependencies() is executed in the main thread, + // we need to manually add in `doctrine/annotations` for Symfony 5.4 tests. + $runner->runProcess('composer require doctrine/annotations'); + } }); } From d6650766f350640c8d123a264957cc7304913cf5 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Wed, 28 Dec 2022 14:56:06 -0500 Subject: [PATCH 7/7] no annotations needed --- tests/Doctrine/EntityRegeneratorTest.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/Doctrine/EntityRegeneratorTest.php b/tests/Doctrine/EntityRegeneratorTest.php index 833a6c81b..e59f3dec3 100644 --- a/tests/Doctrine/EntityRegeneratorTest.php +++ b/tests/Doctrine/EntityRegeneratorTest.php @@ -159,9 +159,6 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load 'utf8' => true, ], 'http_method_override' => false, -// 'annotations' => [ -// 'enabled' => true, -// ], ]); $dbal = [