Skip to content

Commit 05582da

Browse files
bug symfony#48896 [DoctrineBridge] Fix detecting mapping with one line annotations (franmomu)
This PR was merged into the 5.4 branch. Discussion ---------- [DoctrineBridge] Fix detecting mapping with one line annotations | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead --> | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> <!-- Replace this notice by a short README for your feature/bugfix. This will help reviewers and should be a good start for the documentation. Additionally (see https://symfony.com/releases): - Always add tests and ensure they pass. - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against the latest branch. - For new features, provide some code snippets to help understand usage. - Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry - Never break backward compatibility (see https://symfony.com/bc). --> When using one line comment (which is enabled by default when using [`doctrine/coding-standard` 11](https://github.com/doctrine/coding-standard/releases/tag/11.0.0)) to specify that a class is an `Entity`: ```php /** `@Entity` */ class Person { // ... } ``` it doesn't detect properly the annotation and returns `attribute` instead of `annotation`. Commits ------- af52de0 Fix detecting mapping with one line annotations
2 parents 996f93e + af52de0 commit 05582da

File tree

4 files changed

+58
-2
lines changed

4 files changed

+58
-2
lines changed

src/Symfony/Bridge/Doctrine/DependencyInjection/AbstractDoctrineExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,8 @@ private function detectMappingType(string $directory, ContainerBuilder $containe
318318
break;
319319
}
320320
if (
321-
preg_match('/^ \* @.*'.$quotedMappingObjectName.'\b/m', $content) ||
322-
preg_match('/^ \* @.*Embeddable\b/m', $content)
321+
preg_match('/^(?: \*|\/\*\*) @.*'.$quotedMappingObjectName.'\b/m', $content) ||
322+
preg_match('/^(?: \*|\/\*\*) @.*Embeddable\b/m', $content)
323323
) {
324324
$type = 'annotation';
325325
break;

src/Symfony/Bridge/Doctrine/Tests/DependencyInjection/DoctrineExtensionTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ public function testUnrecognizedCacheDriverException()
279279
public function providerBundles()
280280
{
281281
yield ['AnnotationsBundle', 'annotation', '/Entity'];
282+
yield ['AnnotationsOneLineBundle', 'annotation', '/Entity'];
282283
yield ['FullEmbeddableAnnotationsBundle', 'annotation', '/Entity'];
283284
if (\PHP_VERSION_ID >= 80000) {
284285
yield ['AttributesBundle', 'attribute', '/Entity'];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Fixtures\Bundles\AnnotationsOneLineBundle;
13+
14+
use Symfony\Component\HttpKernel\Bundle\Bundle;
15+
16+
class AnnotationsOneLineBundle extends Bundle
17+
{
18+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Fixtures\Bundles\AnnotationsOneLineBundle\Entity;
13+
14+
use Doctrine\ORM\Mapping\Column;
15+
use Doctrine\ORM\Mapping\Entity;
16+
use Doctrine\ORM\Mapping\Id;
17+
18+
/** @Entity */
19+
class Person
20+
{
21+
/** @Id @Column(type="integer") */
22+
protected $id;
23+
24+
/** @Column(type="string") */
25+
public $name;
26+
27+
public function __construct($id, $name)
28+
{
29+
$this->id = $id;
30+
$this->name = $name;
31+
}
32+
33+
public function __toString(): string
34+
{
35+
return (string) $this->name;
36+
}
37+
}

0 commit comments

Comments
 (0)