Re: Thinking About A PEAR Package - Looking For Comments

From: Date: Sun, 06 Sep 2009 16:29:59 +0000
Subject: Re: Thinking About A PEAR Package - Looking For Comments
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-52769@lists.php.net to get a copy of this message
On Sep 6, 2009, at 9:11 AM, Brandon Savage wrote:
All, I was browsing PEAR last night looking for a package that would allow me to take various requests to my web application (POST, GET, JSON, XML, XML-RPC, etc) and convert them into an object that I could then inject into my other objects. To my surprise, I didn't find one. I talked with ashnazg about it, and he recommended I ping this list, and see if such a package already exists. If not, I may begin writing one, mostly because I think it's a pretty common problem, but also because I hate putting superglobals in classes (as I've blogged about many times). Suggestions of existing classes would be great, and if there's already one out there, fantastic! And for those of you who write PEAR packages, thanks! They're great and I really appreciate them. They make life much easier. Best, Brandon Savage
Brandon, At Digg I wrote a package called PHP_SuperGlobals. The main use case was so that I could mock setcookie(), as such calls were breaking unit tests (sending headers). So in your code you would do something like: $cookie = PHP_SuperGlobals::singleton('Cookie'); or $cookie = PHP_SuperGlobals::singleton('CookieMock'); $cookie->setcookie('/', 'foo'); That sort of thing. It has support for $_GET, $_POST, $_COOKIE, and I think $_SERVER. We've gotten pretty used to using it for all of those for mocking input, as well as the setcookie case. But there's a decent interface for customizing it for your needs (IMO). I'm pretty sure this is decoupled from Digg code, and would be willing to make it available if anyone has interest in it. Thoughts? Cheers, Bill

« previous php.pear.dev (#52769) next »