Parses request body into array

@return array
164807
protected function parseBody(): array
    {
        if ($this->getRequest()->headers->get('Content-Type') === 'application/json') {
            $dataCollection = json_decode($this->getRequest()->getContent(), true);
        } else {
            if ($this->getRequest()->isMethod('POST')) {
                $dataCollection = array_merge(
                    $this->getRequest()->request->all(),
                    $this->getRequest()->files->all()
                );
            } else {
                parse_str($this->getRequest()->getContent(), $dataCollection);
            }
        }

        return $dataCollection;
    }
145558
public function toArray($request)
    {
        return [
            'id'            => (int) $this->id,
            'language_code' => $this->language_code,
            'path'          => $this->path,
            'is_active'     => $this->is_active,
            'created_at'    => $this->created_at->toIso8601String(),
            'updated_at'    => $this->updated_at->toIso8601String()
        ];
    }
435223
public function decodeBody()
    {
        $this->decodedBody = json_decode($this->body, true);

        if ($this->decodedBody === null) {
            $this->decodedBody = [];
            parse_str($this->body, $this->decodedBody);
        }

        if (!is_array($this->decodedBody)) {
            $this->decodedBody = [];
        }

        if ($this->isError()) {
            $this->makeException();
        }
    }
73263
private static function parseQuery() : array
    {
        /*
         * Parse the query string. We need to do this ourself, so that we get access
         * to the raw (urlencoded) values. This is required because different software
         * can urlencode to different values.
         */
        $data = [];
        $relayState = '';
        $sigAlg = '';
        $sigQuery = '';
        foreach (explode('&', $_SERVER['QUERY_STRING']) as $e) {
            $tmp = explode('=', $e, 2);
            $name = $tmp[0];
            if (count($tmp) === 2) {
                $value = $tmp[1];
            } else {
                /* No value for this parameter. */
                $value = '';
            }
            $name = urldecode($name);
            $data[$name] = urldecode($value);

            switch ($name) {
                case 'SAMLRequest':
                case 'SAMLResponse':
                    $sigQuery = $name.'='.$value;
                    break;
                case 'RelayState':
                    $relayState = '&RelayState='.$value;
                    break;
                case 'SigAlg':
                    $sigAlg = '&SigAlg='.$value;
                    break;
            }
        }

        $data['SignedQuery'] = $sigQuery.$relayState.$sigAlg;

        return $data;
    }
1330393
public static function getBody()
    {
        $contentType = static::getHeader('Content-Type');
        $body = file_get_contents('php://input');

        if (mb_strpos($contentType,'application/x-www-form-urlencoded') === 0) {
            parse_str($body, $data);
            return $data;
        } else if (mb_strpos($contentType, 'application/json') === 0) {
            return json_decode($body, true);
        } else {
            return $body;
        }
    }
321327
protected function parseBody()
    {
        // Remove the function signature and outer braces
        $start  = strpos($this->code, '{');
        $finish = strrpos($this->code, '}');
        $body   = ltrim(rtrim(substr($this->code, $start + 1, $finish - $start - 1)), "\n");

        return $body;
    }
186257
public function getBodyData()
    {
        if(is_null($this->body_data)) 
        {
            $data = json_decode(file_get_contents("php://input"), true);
            if(!$data)
            {
                $data = array();
            }
            
            $this->body_data = $data;
        }
        
        return $this->body_data;
    }
900194
public function getJsonBody() : array
    {
        $json = json_decode($this->getRawBody(), true);

        if ($json === null) {
            throw new RuntimeException('Body could not be decoded as JSON');
        }

        return $json;
    }
776749
public function getData(): array
    {
        $uploads = [];
        //if the user is trying to upload a image
        if ($this->request->hasFiles()) {
            foreach ($this->request->getUploadedFiles() as $file) {
                $uploads[] = [
                    'name' => $file->getKey(),
                    'filename' => $file->getName(),
                    'contents' => file_get_contents($file->getTempName()),
                ];
            }

            $parseUpload = function ($request) use (&$uploads) {
                foreach ($request as $key => $value) {
                    if (is_array($value)) {
                        foreach ($value as $f => $v) {
                            $uploads[] = ['name' => $key . '[' . $f . ']', 'contents' => $v];
                        }
                    } else {
                        $uploads[] = ['name' => $key, 'contents' => $value];
                    }
                }
            };
        }

        switch ($this->request->getMethod()) {
            case 'GET':
                $queryParams = $this->request->getQuery();
                unset($queryParams['_url']);
                return ['query' => $queryParams];
                break;

            case 'POST':
                if (!$uploads) {
                    //if we dont get post send the raw
                    if (count($this->request->getPost()) > 0) {
                        return ['form_params' => $this->request->getPost()];
                    } elseif ($this->request->getJsonRawBody()) {
                        return ['json' => json_decode($this->request->getRawBody(), true)];
                    }
                    //why did we get here?
                    return ['form_params' => $this->request->getPost()];
                } else {
                    $parseUpload($this->request->getPost());
                    return ['multipart' => $uploads];
                }
                break;

            case 'PUT':
                if (!$uploads) {
                    //if we get put send it with the normal put, else send json
                    if (count($this->request->getPut()) > 0) {
                        return ['form_params' => $this->request->getPut()];
                    } elseif ($this->request->getJsonRawBody()) {
                        return ['json' => json_decode($this->request->getRawBody(), true)];
                    }
                    //why did we get here?
                    return ['form_params' => $this->request->getPut()];
                } else {
                    $parseUpload($this->request->getPut());
                    return ['multipart' => $uploads];
                }

                break;
            default:
                return [];
                break;
        }
    }
453326
public function getBody()
    {
        return [
            'meta' => [
                'type' => 'authentication',
                'paginated' => false,
            ],
            'data' => [
                'user' => $this->user->singleView(),
                'tokenModel' => $this->tokenModel->getBody(),
                'refreshTokenModel' => $this->refreshTokenModel->getBody()
            ]
        ];
    }
1373251
protected function parseBody(array $body)
    {
        $jobs = [];
        if (!empty($body)) {
            if (is_string($body[0])) {
                foreach ($body as $element) {
                    $jobs[] = ['id' => $element];
                }
            } else {
                $keyValueResponse = new KeyValueResponse();
                $keyValueResponse->setCommand($this->command);

                foreach ($body as $element) {
                    $keyValueResponse->setBody($element);
                    $jobs[] = $keyValueResponse->parse();
                }
            }
        }
        return ['jobs' => $jobs];
    }
485209
protected function parseRequest()
    {
        if ($this->customParams === false) {
            // pull various supported inputs from post
            $request = $this->di->get('request');

            // only process if it is a get
            if ($request->isGet() == false) {
                return;
            }
        } else {
            $_REQUEST = $_GET = $this->customParams;
            $request = $this->di->get('request');
        }

        // simple stuff first
        $with = $request->get('with', "string", null);
        $include = $request->get('include', "string", null);
        if (!is_null($with)) {
            $this->suppliedWith = $with;
        } elseif (!is_null($include)) {
            $this->suppliedWith = $include;
        }

        // load possible sort values in the following order
        // be sure to mark this as a paginated result set
        if ($request->get('sort', "string", null) != null) {
            $this->suppliedSort = $request->get('sort', "string", null);
            $this->isPager = true;
        } elseif ($request->get('sort_field', "string", null) != null) {
            $this->suppliedSort = $request->get('sort_field', "string", null);
            $this->isPager = true;
        } elseif ($request->get('sortField', "string", null) != null) {
            $this->suppliedSort = $request->get('sortField', "string", null);
            $this->isPager = true;
        }

        // prep for the harder stuff
        // ?page=1&perPage=25&orderAscending=false

        // load possible limit values in the following order
        // be sure to mark this as a paginated result set
        if ($request->get('limit', "string", null) != null) {
            $this->suppliedLimit = $request->get('limit', "string", null);
            $this->isPager = true;
        } elseif ($request->get('per_page', "string", null) != null) {
            $this->suppliedLimit = $request->get('per_page', "string", null);
            $this->isPager = true;
        } elseif ($request->get('perPage', "string", null) != null) {
            $this->suppliedLimit = $request->get('perPage', "string", null);
            $this->isPager = true;
        }

        // look for string that means to show all records
        if ($this->isPager) {
            if ($this->suppliedLimit == 'all') {
                $this->suppliedLimit = 9999999999;
            }
        }

        // load offset values in the following order
        // Notice that a page is treated differently than offset
        // $this->offset = ($offset != null) ? $offset : $this->offset;
        if ($request->get('offset', "int", null) != null) {
            $this->suppliedOffset = $request->get('offset', "int", null);
            $this->isPager = true;
        } elseif ($request->get('page', "int", null) != null) {
            $this->suppliedOffset = ($request->get('page', "int", null) - 1) * $this->suppliedLimit;
            $this->isPager = true;
        }

        // Check if we pass the count parameter with whatever value
        if ($request->has('count')) {
            $this->isCount = true;
        }

        // http://jsonapi.org/format/#fetching
        $this->parseSearchParameters($request);
    }
805463
public static function getParams(): array
    {
        $body = (array)self::getInstance()->getParsedBody();
        $query = (array)self::getInstance()->getQueryParams();
        return array_merge([], $body, $query);
    }
1349742
public function getParsedBody()
    {
        $content_type = $this->getHeaderLine('content-type');
        $method = $this->getServerParam('REQUEST_METHOD');

        if ('POST' === $method && (false !== \strpos($content_type, 'application/x-www-form-urlencoded') || false !== \strpos($content_type, 'multipart/form-data'))) {
            return $this->post;
        }

        $body = (string) $this->body;

        if ('' === $body) {
            return;
        }

        if (false !== \strpos($content_type, 'application/json')) {
            return \Owl\safe_json_decode($body, true);
        }

        return $body;
    }
157012
protected function parseDataFromResponse()
    {
        $content = $this->rawResponse->body;
        $config = new WebsiteConfig();
        $config->parseFromXml($content);
        return $config;
    }
900995
function parseBody()
    {
        $request = $this->getMessageObject();

        $reqID   = spl_object_hash($request);
        if ( isset(self::$_parsed[$reqID]) )
            // parse from cached
            return self::$_parsed[$reqID];

        if ($request->headers()->has('content-type')) {
            $contentType = \Poirot\Http\Header\renderHeaderValue($request, 'content-type');
            $contentType = strtolower($contentType);

        } else {
            // No Any Data Sent .....
            return array();
        }


        // Content-Type May be in form of:
        // application/x-www-form-urlencoded; charset=utf-8
        // when we call from jquery/ajax in exm.
        if ( false !== $pos = strpos($contentType, ';') )
            $contentType = substr($contentType, 0, $pos);


        switch ( $contentType )
        {
            case 'application/json':
                $parsedData = $this->_parseJsonDataFromRequest($request);
                break;

            case 'application/x-www-form-urlencoded':
                $parsedData = $this->_parseUrlEncodeDataFromRequest($request);
                break;
            case strpos($contentType, 'multipart') !== false:
                $parsedData = $this->_parseMultipartDataFromRequest($request);
                break;

            default:
                throw new \Exception(sprintf(
                    'Request Body Contains No Data or Unknown Content-Type (%s).'
                    , $contentType
                ));
        }


        return self::$_parsed[$reqID] = $parsedData;
    }
190620
public function parse()
    {
        if ($this->body === false) {
            return null;
        }

        $result = [];
        $key = null;
        foreach ($this->body as $value) {
            if (!is_null($key)) {
                $result[$key] = $value;
                $key = null;
            } else {
                $key = $value;
            }
        }

        return $result;
    }