From 359ba96a1e494f1fc08b36d51a74d2fe01d68e68 Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Fri, 6 Jan 2023 12:50:46 +0100 Subject: [PATCH] Fix detecting mapping with one line annotations --- .../AbstractDoctrineExtension.php | 4 +- .../DoctrineExtensionTest.php | 1 + .../AnnotationsOneLineBundle.php | 18 +++++++++ .../Entity/Person.php | 37 +++++++++++++++++++ 4 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 Tests/Fixtures/Bundles/AnnotationsOneLineBundle/AnnotationsOneLineBundle.php create mode 100644 Tests/Fixtures/Bundles/AnnotationsOneLineBundle/Entity/Person.php diff --git a/DependencyInjection/AbstractDoctrineExtension.php b/DependencyInjection/AbstractDoctrineExtension.php index a3083d2b..4b0e1ff5 100644 --- a/DependencyInjection/AbstractDoctrineExtension.php +++ b/DependencyInjection/AbstractDoctrineExtension.php @@ -318,8 +318,8 @@ private function detectMappingType(string $directory, ContainerBuilder $containe break; } if ( - preg_match('/^ \* @.*'.$quotedMappingObjectName.'\b/m', $content) || - preg_match('/^ \* @.*Embeddable\b/m', $content) + preg_match('/^(?: \*|\/\*\*) @.*'.$quotedMappingObjectName.'\b/m', $content) || + preg_match('/^(?: \*|\/\*\*) @.*Embeddable\b/m', $content) ) { $type = 'annotation'; break; diff --git a/Tests/DependencyInjection/DoctrineExtensionTest.php b/Tests/DependencyInjection/DoctrineExtensionTest.php index a7ed7ad5..b6f415e2 100644 --- a/Tests/DependencyInjection/DoctrineExtensionTest.php +++ b/Tests/DependencyInjection/DoctrineExtensionTest.php @@ -279,6 +279,7 @@ public function testUnrecognizedCacheDriverException() public function providerBundles() { yield ['AnnotationsBundle', 'annotation', '/Entity']; + yield ['AnnotationsOneLineBundle', 'annotation', '/Entity']; yield ['FullEmbeddableAnnotationsBundle', 'annotation', '/Entity']; if (\PHP_VERSION_ID >= 80000) { yield ['AttributesBundle', 'attribute', '/Entity']; diff --git a/Tests/Fixtures/Bundles/AnnotationsOneLineBundle/AnnotationsOneLineBundle.php b/Tests/Fixtures/Bundles/AnnotationsOneLineBundle/AnnotationsOneLineBundle.php new file mode 100644 index 00000000..6d401bae --- /dev/null +++ b/Tests/Fixtures/Bundles/AnnotationsOneLineBundle/AnnotationsOneLineBundle.php @@ -0,0 +1,18 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Fixtures\Bundles\AnnotationsOneLineBundle; + +use Symfony\Component\HttpKernel\Bundle\Bundle; + +class AnnotationsOneLineBundle extends Bundle +{ +} diff --git a/Tests/Fixtures/Bundles/AnnotationsOneLineBundle/Entity/Person.php b/Tests/Fixtures/Bundles/AnnotationsOneLineBundle/Entity/Person.php new file mode 100644 index 00000000..b55fe6f8 --- /dev/null +++ b/Tests/Fixtures/Bundles/AnnotationsOneLineBundle/Entity/Person.php @@ -0,0 +1,37 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Fixtures\Bundles\AnnotationsOneLineBundle\Entity; + +use Doctrine\ORM\Mapping\Column; +use Doctrine\ORM\Mapping\Entity; +use Doctrine\ORM\Mapping\Id; + +/** @Entity */ +class Person +{ + /** @Id @Column(type="integer") */ + protected $id; + + /** @Column(type="string") */ + public $name; + + public function __construct($id, $name) + { + $this->id = $id; + $this->name = $name; + } + + public function __toString(): string + { + return (string) $this->name; + } +}