Story: Doctrine 2 lead up
Posted by John Kleijn • Friday, July 23. 2010 • Category: PHPI had been waiting for PHP 5.3 for a long time, and looking at the progress for Zend Framework 2.0, I got very frustrated. But it made me keep a closer eye on the ZF Wiki, and when I encountered a proposal for Zend_Db_Mapper, I recognized many of the PoEAA patterns I had abandoned for reasons of practicality, but longed for so much. But the work was far from done, so I emailed the proposer, Benjamin Eberlei, on 19 December last year, offering my assistance. He responded..
Hello John,
I stopped to work on Zend Entity (and Db Mapper) when we realized that
it actually would end up being sort of a clone of the Doctrine 2 project,
so we joined forces and we will see some pretty neat ZF and Doctrine 1 /2
integration very soon.
you are always welcome to contribute to doctrine 2, its quite advanced
already.
greetings,
Benjamin
I was very disappointed. Zend Framework has a certain robustness, a defensiveness, that I've come to expect (although around this same time ZF started to disappoint in this regard). Doctrine, to me, was superior in functionality to Zend_Db_Table, but it definitely lacked defensiveness. It was messy. And "you can't build a palace on a pile of shit", the lesson I extracted from my experience with the SilverStripe CMS.
I responded to Benjamin expressing my disappointment and lack of faith in the quality of Doctrine. And even though he responded with assurances that Doctrine 2 was very different from Doctrine 1, I remained skeptical and disappointed.
Some months passed, and eventually I did have another look at D2, which had reached the last Alpha stage. I didn't really look at the docs, I assumed that it would be better than D1, but remained skeptical. Regardless, a bleak hope of "a better Doctrine" started to glimmer, and I started to investigate. I quickly came across this presentation by Jonathan Wage. He had me at "completely rewritten", but going on to "kill the magic", it really caught my attention. The "magic" had annoyed me greatly, as it is very inflexible, a source of unclear execution flow, and perhaps the primary source of the lack of defensiveness in D1. Going on to replace the magic with proper OO principles, I was sold. This Doctrine was indeed better, fundamentally better. There was more to the presentation, but it was just icing on the cake. The realization that it was still in alpha, tempered my enthusiasm enough to let it be.
Then I came across a project, that had the need for composite objects in a hierarchal structure, that needed to be persistent. Given the possible nesting level of these structures, I needed something that doesn't require many round trips to the database. Enter Nested Set (aka "Modified Preorder Tree Traversal"). Doctrine 1 does support that, but as it turned out, the combination of inheritance using "column aggregation" and nested set, was asking too much. This was mostly due to the poor inheritance mapping in D1. In desperation (and remembering a promise of "better support for inheritance"), I looked at the latest release of Doctrine, which turned out to be 2.0 BETA1. I was pleased the project had finally reached beta status, and started looking at the docs. I became more and more convinced that it was doable to rip out the guts of the application and replace it with D2.
This was a daunting task though, and I did underestimate it. I ended up namespacing the whole application, creating my own Nested Set implementation for use with D2, and overall just making mayor changes to the application. It put mayor stress on the deadline and myself, especially halfway through. But, the end result seemed worth it, and I am truly impressed with Doctrine 2.
Another thing I am anticipation of is Symfony 2. I never cared much for S1, but I had a look at S2 and it looks pretty good. It relies pretty heavily on DI, another prerequisite for effective Domain Driven Development. Regrettably it won't reach beta until next year. Fabien Potencier apparently coined the expression "kill the magic", and seems as impressed with D2 as I am:
And man, Doctrine 2.0 is gorgeous. Doctrine 2.0 is one of best things that's happened to PHP in a long time.
