First a note on Interfaces. I did a regexp search on Drupal core code for
in order to find out about some extension points and looking at the output start scanning which, where, and how some extension points were available. I started to look at this for situations where you would want to override some services that core provides. Not the usual case, but is always good to know how extensible the new Drupal can be.
I mean in the extreme of things, one should be able to bypass most of the stuff and run almost Symfony on a Drupal carcass. I still want to know if this is possible via say a module, because that would potentially be very good news for those coming from Symfony. Though we probably would leverage less from Drupal, we would gain the possibility of supporting a distribution that is Drupal and at the same time is Symfony or at best Symfonyc.
Ok now onto the serializer module. Notice I don’t say component. The serializer component is not in a Core folder but is under Component, however those classes are just 3 classes really, they are called Serialization and not Serializer. These are Json, PhpSerialize, and Yaml and they all implement SerializationInterface.
One one hand the difference and reason why there is a serializer module and a Serialization component is that Serialization component really does not use anything from Symfony except the Yaml dumper to serialize to Yaml. These 3 services are even registered into the container however they are never used, with the exception of PhpSerialize. PhpSerialize is also really a wrapper for PHP default serialization using the serialize and unserialize PHP native methods.
On the other hand the Serializer core module registers a whole architecture that inherits its basis from Symfony’s (`basic`) Serializer component. These module was ported almost a year ago and it is very complete. It has a complete service provider, compiler passes to register all encoders and normalizers, resolvers for detecting what type of objects are being serialized, and of course encoders and normalizers.
Here is a link and a snapshot of Drupal’s serializer module:
The problem is that I couldn’t find a reference of usage of this module in Core or in other modules. I read a bit on the related tickets and saw that there is some integration going on but saw a bit out dated information or maybe it is work incomplete or stalled. The library, aka Serializer module, is good to use on its own, does not have a UI, and is very flexible.
It is very interesting how Drupal is using the Serializer. In the Symfony world, the serializer is not used much, because most people like to use the JMS Serializer which goes beyond with more features but hooks your whole implementation to a complexity level that in most cases you don’t want/need. I am using so far the regular basic serializer and extending it in my projects so that I don’t use JMS Serializer and I have good reasons because it keeps simple things simple.
I really comment the usage of Serializer in this Drupal module. It may not be useful to you outside of Drupal but it is an interesting case of adapting the Serializer component to your project.