Jump to content

Do you recommend XML or DocBlock for Doctrine metadata?


NotionCommotion

Recommended Posts

I'd go XML.

Keep in mind that DocBlocks are just comments, and in theory one should be able to strip out comments without affecting how a script works.  Doing mappings and other things inside the DocBlock is turning your comments into code that is essential for your script to operate.  This can cause problems in some instances such as if you use an opcache that doesn't preserve comments.

 

 

Link to comment
Share on other sites

24 minutes ago, kicken said:

I'd go XML.

Keep in mind that DocBlocks are just comments, and in theory one should be able to strip out comments without affecting how a script works.  Doing mappings and other things inside the DocBlock is turning your comments into code that is essential for your script to operate.  This can cause problems in some instances such as if you use an opcache that doesn't preserve comments.

 

 

Thanks kicken,  I was starting to lean that way.  The thought of having the schema so dependent on some PHP script scares me.  What do you think about Doctrine?  While I think some aspects are great, it just seems that it degrades the databases integrity.  Yeah, more I think of it, definitely XML over DocBlocks.

Link to comment
Share on other sites

  • 1 month later...

I've been using XML for Doctrine's metadata, and I soon after started using Symphony's serializer, and continued on the XML path.  I still dislike the idea of the database schema being dependent upon comments in a PHP file, but am starting to question whether it might be worth using DocBlocks.

One issue with XML is the lack of documentation as most of both Doctrine and the serializer focused on DocBlocks, however, by cross-referencing the various documents, one is able to connect the dots.

Another issue is making a modification to the Doctrine XML file required changing the classes, however, I created a small script which uses Doctrine's class builder and to create new classes and then edit the class files to make my desired modifications, and this is not a big deal.

A third issue is needing to focus on three separate files at the same time (the entity class, doctrine XML, and serializer XML) which is a bigger issue than I would have expected.  Any thoughts how to make this easier?  Using a single XML document for both the Doctrine and serializer definitions would definitely help, but I don't think this is possible.  Locating them in the same directory might help a little since they will be located next to each other, but wouldn't help much and might create other issues.  I guess I could get a third monitor, but my work space is somewhat limited in space.  Any other ideas?

 

Link to comment
Share on other sites

If you don't mind the whole comments are now code thing then feel free to use them. Just remember to set opcache.save_comments=1 if you use opcache.  Since annotations are popular that is the default.

For whatever reason using annotations in docblocks has become really popular and it is indeed much easier overall to just follow the trend. As you've noticed it can be harder to find information about other methods.  I've run into that many times with symfony because I do everything via YAML configuration but it seems most of the internet only cares about docblock annotations.  Ive had to go digging into the source a few times to find the yaml equivalent of a few annotations.

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.