Explorar el Código

[HttpFoundation] added a way to retrieve raw body from a request

Fabien Potencier hace 14 años
padre
commit
a7c81577c7
Se han modificado 1 ficheros con 16 adiciones y 0 borrados
  1. 16 0
      src/Symfony/Component/HttpFoundation/Request.php

+ 16 - 0
src/Symfony/Component/HttpFoundation/Request.php

@@ -56,6 +56,7 @@ class Request
      */
     public $headers;
 
+    protected $content;
     protected $languages;
     protected $charsets;
     protected $acceptableContentTypes;
@@ -106,6 +107,7 @@ class Request
         $this->server = new ParameterBag(null !== $server ? $server : $_SERVER);
         $this->headers = new HeaderBag($this->initializeHeaders());
 
+        $this->content = null;
         $this->languages = null;
         $this->charsets = null;
         $this->acceptableContentTypes = null;
@@ -604,6 +606,20 @@ class Request
         return in_array($this->getMethod(), array('GET', 'HEAD'));
     }
 
+    /**
+     * Return the request body content.
+     *
+     * @return string The request body content.
+     */
+    public function getContent()
+    {
+        if (null === $this->content) {
+            $this->content = file_get_contents('php://input');
+        }
+
+        return $this->content;
+    }
+
     public function getETags()
     {
         return preg_split('/\s*,\s*/', $this->headers->get('if_none_match'), null, PREG_SPLIT_NO_EMPTY);