448191 Posted May 17, 2007 Share Posted May 17, 2007 I'm thinking about having Http_Header ValueObjects. Motivation: 1. Ensure that headers are valid 2. Simplify setting of headers by providing a set (and documented) list of available headers when editing. So I set off and created a Http_Header class. And I was pretty pleased with the simplicity and elegance of it (aside from the long winded names). A Header object is created pretty simply: $header = new Backbone_Http_Header_Response(Backbone_Http_Header_Response::H_TESTHEADER, "test"); Obviously it doesn't check if the value of the header is valid (other than that it's a string), but I'm not so sure I even want to implement that. What I'm doing is the following: a) For easy editing, I declare all the possible headers as constants, and assign codes to them (borrowed from http://msdn2.microsoft.com/en_us/library/ms537417.aspx). b) To be able to check if a header name is valid, I use reflection to create a static associative array of header names, indexed by code. c) To fetch the name of a Header instance, lookup the instance's header code in the static array. Backbone_Http_Header lists header names valid for both responses and requests, subclasses Backbone_Http_Header_Response and *_Request headers specific to a respectively a request or a response. Anyway, the reason for my post: isn't there some sort of build-in functionality that can accomplish this? I get the feeling that I am reinventing the wheel... Quote Link to comment https://forums.phpfreaks.com/topic/51795-http-headers/ Share on other sites More sharing options...
448191 Posted May 17, 2007 Author Share Posted May 17, 2007 It does however work very nicely with Zend Studio's autocomplete: Quote Link to comment https://forums.phpfreaks.com/topic/51795-http-headers/#findComment-255252 Share on other sites More sharing options...
448191 Posted May 17, 2007 Author Share Posted May 17, 2007 Unless someone can point out some serious performance concerns, I guess it's a keeper. Quote Link to comment https://forums.phpfreaks.com/topic/51795-http-headers/#findComment-255903 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.