We've got this shiny new request object from Symfony2, let's use it!
OK, baby steps...
The attached patch begins the process of replacing our legacy scattered-functions with a proper request object. It is not a final version of what we want, but it's an incremental improvement on what we have now.
- Extends the Symfony Request class to a Drupal request class.
- Moves several of our existing random functions into methods in the request class, specifically current_path(), request_path(), and arg().
- Provides real unit tests for requestPath() and pathElement().
- Introduces a trivial factory function, request(), to make the request object accessible.
- Replaces current_path(), request_path(), arg(), and ip_address() with trivial calls to request().
- Marks request(), current_path(), request_path(), arg(), and ip_address() as deprecated.
Note: This patch requires the RTBC namespace reorganization in #1400748: Proposal for unified namespace organization. I've attached it twice, once including that patch (for testbot) and once without (for review purposes). Presumably that one will be committed first.
Once this is in:
- Someone needs to go expunge all use of current_path(), request_path(), arg(), and ip_address() in favor of the direct methods on the request object. Yes, that means some lucky developer will be able to go down in history as the person who killed arg().
- The path lookup system needs to be OOPified and made properly unit testable. We cannot provide real unit tests of the systemPath() method until that's done, because it depends on the path aliasing system. I am tempted to say that we need to move systemPath() out of being a method because of that, but I am punting on that question until we have a proper dependency injection system in core.
- The request() function is not final and will not be staying through to code freeze. It's just there for now since we don't yet have a proper injection system. Once we do, it will be removed in favor of a larger refactoring. But at least we can kill arg().
User interface changes
current_path(), request_path(), arg(), and ip_address() are now deprecated and should be removed in later patches in favor of the new methods on the request object.
Note: The patch is not quite ready, sorry. As I was writing this I realized there were a few places I needed to exterminate arg() yet just to make things work, which is taking past my bed time. Stand by.