Skip to content

Commit 4c20d32

Browse files
authored
[make:entity] fix compatibility with api-platform 3.0 (#1199)
1 parent bc0ed75 commit 4c20d32

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/Maker/MakeEntity.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
namespace Symfony\Bundle\MakerBundle\Maker;
1313

14-
use ApiPlatform\Core\Annotation\ApiResource;
14+
use ApiPlatform\Core\Annotation\ApiResource as LegacyApiResource;
15+
use ApiPlatform\Metadata\ApiResource;
1516
use Doctrine\DBAL\Types\Type;
1617
use Symfony\Bundle\MakerBundle\ConsoleStyle;
1718
use Symfony\Bundle\MakerBundle\DependencyBuilder;
@@ -133,7 +134,7 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma
133134

134135
if (
135136
!$input->getOption('api-resource') &&
136-
class_exists(ApiResource::class) &&
137+
(class_exists(ApiResource::class) || class_exists(LegacyApiResource::class)) &&
137138
!class_exists($this->generator->createClassNameDetails($entityClassName, 'Entity\\')->getFullName())
138139
) {
139140
$description = $command->getDefinition()->getOption('api-resource')->getDescription();
@@ -317,10 +318,17 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
317318
public function configureDependencies(DependencyBuilder $dependencies, InputInterface $input = null): void
318319
{
319320
if (null !== $input && $input->getOption('api-resource')) {
320-
$dependencies->addClassDependency(
321-
ApiResource::class,
322-
'api'
323-
);
321+
if (class_exists(ApiResource::class)) {
322+
$dependencies->addClassDependency(
323+
ApiResource::class,
324+
'api'
325+
);
326+
} else {
327+
$dependencies->addClassDependency(
328+
LegacyApiResource::class,
329+
'api'
330+
);
331+
}
324332
}
325333

326334
if (null !== $input && $input->getOption('broadcast')) {

tests/Maker/MakeEntityTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function getTestDetails(): \Generator
7474
$this->assertFileExists($runner->getPath('src/Entity/User.php'));
7575

7676
$content = file_get_contents($runner->getPath('src/Entity/User.php'));
77-
$this->assertStringContainsString('use ApiPlatform\Core\Annotation\ApiResource;', $content);
77+
$this->assertStringContainsString('use ApiPlatform\Metadata\ApiResource;', $content);
7878
$this->assertStringContainsString('#[ApiResource]', $content);
7979

8080
$this->runEntityTest($runner);

0 commit comments

Comments
 (0)