]> git.mxchange.org Git - friendica.git/blobdiff - src/Util/HTTPInputData.php
Test file uploads
[friendica.git] / src / Util / HTTPInputData.php
index aebae9ac20e834b44ff73dead96e8d9341f63352..490dda5f66ab9756747ad3e6e736ca746faaf86f 100644 (file)
@@ -29,7 +29,7 @@ class HTTPInputData
 {
        public static function process()
        {
-               $content_parts = explode(';', $_SERVER['CONTENT_TYPE'] ?? 'application/x-www-form-urlencoded');
+               $content_parts = explode(';', static::getContentType());
 
                $boundary = '';
                $encoding = '';
@@ -60,7 +60,7 @@ class HTTPInputData
                // can be handled by built in PHP functionality
                $content = static::getPhpInputContent();
 
-               $variables = json_decode($content);
+               $variables = json_decode($content, true);
 
                if (empty($variables)) {
                        parse_str($content, $variables);
@@ -135,13 +135,13 @@ class HTTPInputData
                        $files[$name] = self::fetchFileData($stream, $boundary, $headers, $filename);
                        return ['variables' => $variables, 'files' => $files];
                } else {
-                       $variables = self::fetchVariables($stream, $boundary, $name, $variables);
+                       $variables = self::fetchVariables($stream, $boundary, $headers, $name, $variables);
                }
 
                return ['variables' => $variables, 'files' => $files];
        }
 
-       private static function fetchFileData($stream, string $boundary, array $headers, string $filename)
+       protected static function fetchFileData($stream, string $boundary, array $headers, string $filename)
        {
                $error = UPLOAD_ERR_OK;
 
@@ -186,7 +186,7 @@ class HTTPInputData
                ];
        }
 
-       private static function fetchVariables($stream, string $boundary, string $name, array $variables)
+       private static function fetchVariables($stream, string $boundary, array $headers, string $name, array $variables)
        {
                $fullValue = '';
                $lastLine  = null;
@@ -263,6 +263,7 @@ class HTTPInputData
        /**
         * Returns the current PHP input stream
         * Mainly used for test doubling
+        *
         * @return false|resource
         */
        protected static function getPhpInputStream()
@@ -271,12 +272,24 @@ class HTTPInputData
        }
 
        /**
-        * Returns the content of tje current PHP input
+        * Returns the content of the current PHP input
         * Mainly used for test doubling
+        *
         * @return false|string
         */
        protected static function getPhpInputContent()
        {
                return file_get_contents('php://input');
        }
+
+       /**
+        * Returns the content type string of the current call
+        * Mainly used for test doubling
+        *
+        * @return false|string
+        */
+       protected static function getContentType()
+       {
+               return $_SERVER['CONTENT_TYPE'] ?? 'application/x-www-form-urlencoded';
+       }
 }