symfony2 annotation documentation - symfony

Where can I find documentation for a complete list of annotations possible for different Symfony2 components?
Example, http://symfony.com/doc/current/components/routing/introduction.html here there's not enough information about "options" of the config and documentation about routing via yml in whole.
The same questions for controller annotations. I've found separate references to different annotations possible in controller(http://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/routing.html, http://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/view.html), but no COMPLETE list of possible annotations.
There MUST be something I'm missing, because people somehow know what options to use and how.

You can find all details about annotation in SensioFrameworkExtraBundle documentation (#Route , #Method , #ParamConverter ,#Template ,#Cache and #Security )
If you want the list for your Entity you can read doctrine documentation .

Related

Symfony doctrine reverse engineering and Apiplatform

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.
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.

Symfony: FOSRESTBundle and JMSSerializerBundle, how to exclude a property on listing

I have a rest api on a symfony project using FOSRest and JMSSerializer.
I want to exclude one of the properties of the objects in the cgetObjectAction (api/my-objects) method but leave it on the single get endpoint (api/my-objects/1).
I've been reading and I came accross the possibility to use groups for the JMS Serializer https://jmsyst.com/libs/serializer/master/reference/annotations (I'm already familiar with the possibility of excluding/exposing a var in every method)
But my question is, how can I specify in the cgetObjectAction method to use the group I define (i.e. collection and single).
Thanks in advance
I'm a bit late, but in case someone needs an answer, here is some help.
To specify the group you want to use, you need to add this in the View annotation of your controller :
#JMS\View(serializerGroups={"YOUR_GROUP_NAME"})
And don't forget to add the use statement :
use FOS\RestBundle\Controller\Annotations as JMS;

override mapping for a specific Entity class

I'm using a standard Symfony 2.8 framework with Doctrine.
My entities' mappings are all annotated, but I would need to map a single entity by using the PHP way (by defining loadMetadata static method) . I know there's a way to override a mapping Bundle configuration like explained here, but what I would like is specifying a single Entity. Is that possible? Thanks
No you can't mix the formats
A bundle can accept only one metadata definition format. For example, it's not possible to mix YAML metadata definitions with annotated PHP entity class definitions.
see doc here:
http://symfony.com/doc/current/doctrine.html
if you really need to change the mapping format then I suggest you create a new bundle for your specific entity. I also had this problem. I wished to have different mapping format (yml and annotation in my case) but I had to create a new bundle.

Generic comment system in Symfony2

I have in my Symfony 2.1 RC app a simple Comment model (using Doctrine 2). Every comment has a user and a message.
Currently, the CommentBundle manages comments on articles. I'd like it to be more generic to be able to comment any kind of entity without copying code across different bundles dedicated to comments...
For this to work, I also need a way to reference any entity from the comment one. I think having two fields entity_type and entity_id can be a nice solution. However, I can't get the object from these without mapping entity_type to classes manually and using the find method.
So how do I reference an entity from a comment ? And how can I create generic behavior working on several entities ?
You can create a abstract base class entity called Commentable and create entities that inherit Commentable such as Document or Post.
Since Document and Post are derived from Commentable, you can create a one to many relationship between the entities Commentable and Comment respectively.
Make sure to include in your base class ORM annotations for inheritance:
#InheritanceType
#DiscriminatorColumn
#DiscriminatorMap
Examples can be found on Doctrine Project Inheritance Documentation

Configurable parameters in Symfony2 entity annotation

I'm trying to create a join across multiple databases (one of them belonging to a legacy application) as described in the Doctrine blog. However, the example suggests hardcoding the name of the database right into the schema, which I'd like to avoid for obvious reasons.
Is there a way to read parameters defined in parameters.ini or config.yml and use them as a value for the annotations, like this?
/**
* #ORM\Table(name="%legacy_db_name%.%legacy_table_name%")
*/
No, it's impossible. The "%key%" form is only available in the DIC.
Why would you put these data in a yml file? Would it be useful?

Resources