Trivial Response Object

Coding Critique is the place to post source code for peer review by other members of DevNetwork. Any kind of code can be posted. Code posted does not have to be limited to PHP. All members are invited to contribute constructive criticism with the goal of improving the code. Posted code should include some background information about it and what areas you specifically would like help with.

Popular code excerpts may be moved to "Code Snippets" by the moderators.

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Trivial Response Object

Post by alex.barylski »

I don't need the abstraction of Zend, really something as simple as possible but that still meets the requirements of most web based applications (no CLI, etc).

Does anyone have any input on the following psuedo-response object?

Have you ever encountered a situation where you needed to clear previously pushed headers? Can you give me an example of when that might be needed from a real life experience? That is an example of a missing function.

Code: Select all

class QC_Response{

	/* private */ var $_head = null;
	/* private */ var $_buff = '';

	function addHeader($name, $value){ $this->_head[$name] = $value; }
	function getHeader($name){ return $this->_head[$name]; }


	function setContent($text){ $this->_buff = $text; }
	function getContent(){ return $this->_buff; }

	function fetchResponse($auto = false)
	{
		$arr = $this->_head;
		foreach($arr as $key => $value)
			header("$key: $value");

		if($auto)
			echo $this->_text;
		else
			return $this->_text;
	}
}
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Well you already have the abstraction of Zend. If you want simpler then remove the get*() methods. I also have always thought that $auto is a pretty variable name.
(#10850)
Post Reply