PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, January 11, 2022

[FIXED] Symfony doctrine reverse engineering and Apiplatform

 January 11, 2022     api-platform.com, doctrine-orm, entities, symfony     No comments   

Issue

Is there a way to create Apiplatform enabled entities directly from database schemas?

I successfully create the entities using php bin/console doctrine:mapping:import "App\Entity" annotation --path=src/Entity , but now i have to add manually the reference to Apiplatform resources in 120 entities like here. Is there another way? Thanks in advance.


Solution

This feature isn’t supported out of the box (but it would be nice to add it). There is an open issue to add this feature to MakerBundle, but this hasn’t been implemented at time of writing.

However, you can easily achieve the same effect by using the "search and replace" feature of your IDE or by using sed: find every occurrences of @ORM\Entity and replace them with:

@ORM\Entity
@\ApiPlatform\Core\Annotation\ApiResource

You may want to run PHP CS Fixer after that to change the fully qualified class name by a use statement.



Answered By - Kévin Dunglas
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing