Details
-
Type:
Patch
-
Status:
Resolved
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 1.5.0RC1
-
Fix Version/s: 1.5.0
-
Component/s: Zend_Controller
-
Labels:None
-
Fix Version Priority:Should Have
Description
For some recent RESTful architecture development I was working on, I came across the need to to use Zend_Controller_Request_Http to check for other HTTP requests than POST and to also access the raw entity body of the posted or put request. To achieve this, we extended Zend_Controller_Request_Http and added the needed methods and then set the Zend Framework request to our child class using the front controller's setRequest() method. However, I think these methods should be incorporated back into the Zend Framework itself.
Patch follows...
library.diff
--- library/Zend/Controller/Request/Http.php (revision 8365)
+++ library/Zend/Controller/Request/Http.php (working copy)
@@ -742,6 +742,92 @@
}
/**
+ * Was the request made by GET?
+ *
+ * @return boolean
+ */
+ public function isGet()
+ {
+ if ('GET' == $this->getMethod()) {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Was the request made by PUT?
+ *
+ * @return boolean
+ */
+ public function isPut()
+ {
+ if ('PUT' == $this->getMethod()) {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Was the request made by DELETE?
+ *
+ * @return boolean
+ */
+ public function isDelete()
+ {
+ if ('DELETE' == $this->getMethod()) {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Was the request made by HEAD?
+ *
+ * @return boolean
+ */
+ public function isHead()
+ {
+ if ('HEAD' == $this->getMethod()) {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Was the request made by OPTIONS?
+ *
+ * @return boolean
+ */
+ public function isOptions()
+ {
+ if ('OPTIONS' == $this->getMethod()) {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Return the raw entity body of the request, if present
+ *
+ * @return string|false Raw entity body, or false if not present
+ */
+ public function getEntityBody()
+ {
+ $body = file_get_contents('php://input');
+
+ if (strlen(trim($body)) > 0) {
+ return $body;
+ }
+
+ return false;
+ }
+
+ /**
* Return the value of the given HTTP header. Pass the header name as the
* plain, HTTP-specified header name. Ex.: Ask for 'Accept' to get the
* Accept header, 'Accept-Encoding' to get the Accept-Encoding header.
Scheduling for 1.5.0 RC2