Accumulate evidence

Friday, October 19, 2012

Symfony + REST = Put the gun down

At the time of this posting, I am working on building a web services architecture via REST by using Symfony 2, Doctrine, and FOSRestBundle.  I have used Symfony 1.4 some time ago, and I figured that many of the unique caveats carried over.  Yeah, no.

Symfony2 is what happens when Java hate-fucks PHP at gunpoint to show off how superior it is.  Instead of working with the limitations of PHP, the Symfony community has decided to stuff as many Java methodologies into PHP as possible.  (The ACL system and, to a point, the Dependency Injection is, literally, a 100% code lift from Spring MVC)

And why not?  PHP and Java totally treat objects exactly the same way, despite PHP having loose data typing, no JIT, lack of weak references, extremely limited multiple inheritance, lack of first-class functions, and Fisher Price's My First Closures.  (No, seriously, I love having my dependency injection and event listeners be established in a data file that my IDE can't integrate with.  Everyone loves obscure stack traces!)  Configuration vs convention?  No way, man!  The configuration IS the convention!  Web 3.0!

Symfony isn't even compliant with the HTTP protocol.  There is no native PATCH support in the forms, which means this hilariously common scenario is true:  A user has a name, a password, and a collection of friends he's made.  If you want to update the user's password via a PUT request, you have to pass up all of his friends as well, or else the Symfony Form will null all of your friends.  That's how PUT is supposed to be, which is fine, ASSUMING PATCH WORKS AS WELL. But you know what?  Forget PATCH... the Form obfuscates this ridiculousness by automagically generating form elements in HTML!   All is well!

...except for... well... the whole "I am building REST service" part where HTML forms are useless.  Mobile apps, tablets, browsers, and other assorted RIAs with their own templating systems, which don't give one angry drop of piss about HTML, have to interface with it.

FOSRestBundle's automatic route generation doesn't even have a consistant naming convention between POST and the other methods. POSTs are all singular (POST /user), while GET, DELETE, and PUT are plural. (GET /users)  And if you try to discover the rationale for this, you'll unlock the secret level where you'll find the cited REST example has all its methods as plural.  Mindfuck achievement unlocked!

For super extra bonus points, bring this total lack of HTTP compliance on the official chat channel on Freenode and you'll be told that you're adhering to the REST standard too much!  After all, if it exists in the codebase, there must be a really good reason it's there!  Dirty open-source plebeian, W.W.J.D. (What Would Java Do?) solves all!

As for using Doctrine with Postgres?  Kiss your views goodbye.  (You goddamn right you're going to do all your business reporting in the application layer!  I have seen the future, and it is PHP as the backbone for all MapReduce!)  If you try to represent a view as an ORM, Doctrine tries to write to it when you do a schema update (Fastest way to piss Jenkins off, btw)  Hope you like having tons of bloat on top of those raw SQL queries!

So if you are looking to try Symfony as the backbone for your REST architecture, put the gun down.  If you want to use Java, use Java.  If you want to use PHP, use PHP.  If you merge them together, you're a fucking idiot.

ADDENDUM: I'm cruel and bitter in real-life, too.  I've already put in my tickets and PRs to fix some of this shit, but every other user who wants to do the same damned thing is going to encounter this nonsense, then discard the entire stack in a fit of rage like any sensible person would.

4 comments:

  1. You're funny :) Anyway, to quote Fabien: Create a patch, make a test, write the documentation... everything is open source and free for you to improve ;)

    ReplyDelete
    Replies
    1. Absolutely. I should mention that the HttpFoundation itself is pretty steller. Everything after the Controller is extremely suspect. I'm in the process of putting together some solutions to help make more sense of these things.

      Delete
  2. This is my first opportunity to visit this website. I found some interesting things and I will apply to the development of my blog. Thanks for sharing useful information.
    symfony application

    ReplyDelete
  3. Haha Thanks for the reference!

    - https://github.com/FriendsOfSymfony/FOSRestBundle/issues/247

    ReplyDelete