Hi,

i'm currently developing a plugin for easily producing REST web services
using Symfony.
I started implementing PUT and DELETE support yesterday and realized
that Symfony did not support these methods.
I also find request method management a bit weird : at the moment, it's
sfRequest that holds the constants for GET and POST along with the
get/setMethod code.
Wouldn't it make more sense to have all this code in sfWebRequest ?

I coded a patch that :

 * removes all http methods related code from sfRequest and pushes it
into sfWebRequest
 * patches code that was broken because of the modification
 * implements support for PUT, DELETE and HEAD

before opening a patch ticket and coding an upgrade task for BC, i
wanted to be sure that i was not completely missing the point :P

patch is attached to mail.

thanks in advance for your advice,

++
tristan


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "symfony 
developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/symfony-devs?hl=en
-~----------~----~----~----~------~----~------~--~---

Index: lib/symfony/action/sfAction.class.php
===================================================================
--- lib/symfony/action/sfAction.class.php       (revision 3102)
+++ lib/symfony/action/sfAction.class.php       (working copy)
@@ -352,15 +352,23 @@
   *
   * @return int One of the following values:
   *
-   *             - sfRequest::GET
-   *             - sfRequest::POST
-   *             - sfRequest::NONE
+   *             - sfWebRequest::GET
+   *             - sfWebRequest::POST
+   *             - sfWebRequest::NONE
+   *             - sfWebRequest::PUT
+   *             - sfWebRequest::HEAD
+   *             - sfWebRequest::DELETE
   *
-   * @see sfRequest
+   * @see sfWebRequest
   */
  public function getRequestMethods()
  {
-    return sfRequest::GET | sfRequest::POST | sfRequest::NONE;
+ return sfWebRequest::GET + | sfWebRequest::POST + | sfWebRequest::PUT + | sfWebRequest::DELETE + | sfWebRequest::HEAD + | sfWebRequest::NONE;
  }

  /**
Index: lib/symfony/request/sfRequest.class.php
===================================================================
--- lib/symfony/request/sfRequest.class.php     (revision 3102)
+++ lib/symfony/request/sfRequest.class.php     (working copy)
@@ -22,23 +22,6 @@
 */
abstract class sfRequest
{
-  /**
-   * Process validation and execution for only GET requests.
-   *
-   */
-  const GET = 2;
-
-  /**
-   * Skip validation and execution for any request method.
-   *
-   */
-  const NONE = 1;
-
-  /**
-   * Process validation and execution for only POST requests.
-   *
-   */
-  const POST = 4;

  protected
    $errors          = array(),
@@ -43,7 +26,6 @@
  protected
    $errors          = array(),
    $context         = null,
-    $method          = null,
    $parameterHolder = null,
    $config          = null,
    $attributeHolder = null;
@@ -119,18 +101,6 @@
  }

  /**
-   * Retrieve this request's method.
-   *
-   * @return int One of the following constants:
-   *             - sfRequest::GET
-   *             - sfRequest::POST
-   */
-  public function getMethod()
-  {
-    return $this->method;
-  }
-
-  /**
   * Indicates whether or not an error exists.
   *
   * @param string An error name.
@@ -260,33 +230,6 @@
    $this->errors = array_merge($this->errors, $errors);
  }

-  /**
-   * Set the request method.
-   *
-   * @param int One of the following constants:
-   *            - sfRequest::GET
-   *            - sfRequest::POST
-   *
-   * @return void
-   *
-   * @throws <b>sfException</b> - If the specified request method is invalid.
-   */
-  public function setMethod($method)
-  {
-    if ($method == self::GET || $method == self::POST)
-    {
-      $this->method = $method;
-
-      return;
-    }
-
-    // invalid method type
-    $error = 'Invalid request method: %s';
-    $error = sprintf($error, $method);
-
-    throw new sfException($error);
-  }
-
  public function getParameterHolder()
  {
    return $this->parameterHolder;
Index: lib/symfony/request/sfWebRequest.class.php
===================================================================
--- lib/symfony/request/sfWebRequest.class.php  (revision 3102)
+++ lib/symfony/request/sfWebRequest.class.php  (working copy)
@@ -23,6 +23,43 @@
 */
class sfWebRequest extends sfRequest
{
+
+  /**
+   * Skip validation and execution for any request method.
+   *
+   */
+  const NONE = 1;
+ + /**
+   * Process validation and execution for only GET requests.
+   *
+   */
+  const GET = 2;
+
+  /**
+   * Process validation and execution for only POST requests.
+   *
+   */
+  const POST = 4;
+ + /**
+   * Process validation and execution for only PUT requests.
+   *
+   */
+  const PUT = 8;
+
+  /**
+   * Process validation and execution for only DELETE requests.
+   *
+   */
+  const DELETE = 16;
+
+  /**
+   * Process validation and execution for only HEAD requests.
+   *
+   */
+  const HEAD = 32;
+ /**
   * A list of languages accepted by the browser.
   * @var array
@@ -36,10 +73,19 @@
  protected $charsets = null;

  /**
-   * @var array  List of content types accepted by the client.
+   * List of content types accepted by the client.
+   * @var array
   */
  protected $acceptableContentTypes = null;

+  /**
+   * Current request method code.
+   * (see class constants for codes)
+ * + * @var int
+   */
+  protected $method = null;
+
  protected $pathInfoArray = null;

  protected $relativeUrlRoot = null;
@@ -280,6 +326,18 @@
          $this->setMethod(self::POST);
          break;

+        case 'PUT':
+          $this->setMethod(self::PUT);
+          break;
+
+        case 'DELETE':
+          $this->setMethod(self::DELETE);
+          break;
+
+        case 'HEAD':
+          $this->setMethod(self::HEAD);
+          break;
+
        default:
          $this->setMethod(self::GET);
      }
@@ -769,6 +827,55 @@
  }

  /**
+   * Set the request method.
+   *
+   * @param int One of the following constants:
+ * + * # sfWebRequest::GET
+   *                 # sfWebRequest::POST
+   *                 # sfWebRequest::PUT
+   *                 # sfWebRequest::DELETE
+   *                 # sfWebRequest::HEAD
+ * + * @return void
+   *
+   * @throws <b>sfException</b> - If the specified request method is invalid.
+   */
+  public function setMethod($method_code)
+  {
+    $available_methods = array(self::GET, self::POST, self::PUT, self::DELETE, 
self::HEAD);
+    if (in_array($method_code, $available_methods))
+    {
+      $this->method = $method_code;
+
+      return;
+    }
+
+    // invalid method type
+    $error = 'Invalid request method: %s';
+    $error = sprintf($error, $this->getMethodName());
+
+    throw new sfException($error);
+  }
+
+  /**
+   * Retrieve this request's method.
+   *
+   * @return int One of the following constants:
+ * + * # sfWebRequest::GET
+   *                  # sfWebRequest::POST
+   *                  # sfWebRequest::PUT
+   *                  # sfWebRequest::DELETE
+   *                  # sfWebRequest::HEAD
+ * + */
+  public function getMethod()
+  {
+    return $this->method;
+  }
+
+  /**
   * Execute the shutdown procedure.
   *
   * @return void

Reply via email to