src/Rest/SdkTrait.php
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;
        }
    }
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;
        }
    }
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 ; } }
Function that obtains the data as per the request type.

@return array
Function that obtains the data as per the request type .