Skip to content

Commit a83d293

Browse files
dunglasweaverryan
authored andcommitted
use attributes for API Platform when using PHP 8+
1 parent 0065779 commit a83d293

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/Resources/skeleton/doctrine/Entity.tpl.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@
88
use Doctrine\ORM\Mapping as ORM;
99

1010
/**
11-
<?php if ($api_resource): ?> * @ApiResource()
11+
<?php if ($api_resource && !$use_attributes): ?> * @ApiResource()
1212
<?php endif ?>
1313
* @ORM\Entity(repositoryClass=<?= $repository_class_name ?>::class)
1414
<?php if ($should_escape_table_name): ?> * @ORM\Table(name="`<?= $table_name ?>`")
1515
<?php endif ?>
1616
*/
17+
<?php if ($api_resource && $use_attributes): ?>
18+
#[ApiResource]
19+
<?php endif ?>
1720
class <?= $class_name."\n" ?>
1821
{
1922
/**

tests/Maker/MakeEntityTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function getTestDetails()
5252

5353
$content = file_get_contents($directory.'/src/Entity/User.php');
5454
$this->assertStringContainsString('use ApiPlatform\Core\Annotation\ApiResource;', $content);
55-
$this->assertStringContainsString('@ApiResource', $content);
55+
$this->assertStringContainsString(\PHP_VERSION_ID >= 80000 ? '#[ApiResource]' : '@ApiResource', $content);
5656
}),
5757
];
5858

0 commit comments

Comments
 (0)