Parses request body

@param string $resource Resource name
@param string $type Content-Type header
@param string $body Request Body

@return array

@throws RouterException If $type is not supported
@throws RouterException If $body could not be parsed
545627
protected function parseBody(string $resource, string $type, string $body)
    {
        $content_type = static::parseContentType($type);
        $mime = $content_type['mime'] ?? $content_type;

        if (($content_type['charset'] ?? null) !== null) {
            $body = mb_convert_encoding(
                $body,
                'UTF-8',
                $content_type['charset']
            );
        }

        if ($mime === '') {
            if ($body === '') {
                return [];
            }
        } elseif ($mime === 'application/json') {
            $data = json_decode($body, true);
            if (!empty($data)) {
                return [
                    'mime' => $mime,
                    'data' => $data,
                ];
            }
        } else {
            if (!$this->safe_method) {
                $handlers = $this->resources[$resource]['handlers'] ?? [];
                if (!empty($handlers)) {
                    $handlers = $handlers[$this->method] ?? null;
                    if (is_array($handlers)
                        && array_key_exists($mime, $handlers)
                    ) {
                        return [
                            'mime' => $mime,
                            'body' => $body,
                        ];
                    }
                }
            }

            $this->sendError(
                static::ERROR_UNSUPPORTED_MEDIA_TYPE,
                "Media-Type '$mime' is not supported"
            );
        }

        $this->sendError(
            static::ERROR_INVALID_PAYLOAD,
            "Body payload could not be parsed"
        );
    }
281755
public function resolve(string $resource, string $type = ''): string
    {
        if (! $this->hasLocalPath()) {
            return $resource;
        }
        if ('' === $type) {
            $type = $this->obtainTypeFromUrl($resource);
        } else {
            $type = strtoupper($type);
        }
        $retriever = $this->newRetriever($type);
        if (null === $retriever) {
            throw new \RuntimeException("Unable to handle the resource (Type: $type) $resource");
        }
        $local = $retriever->buildPath($resource);
        if (! file_exists($local)) {
            $retriever->retrieve($resource);
        }
        return $local;
    }
1034663
public function supports($resource, $type = null): bool
    {
        \assert('is_string($resource) && ($type === null || is_string($type))');
        return $this->parser->supports(pathinfo($resource, PATHINFO_EXTENSION));
    }
991688
protected function readBody($type, $size)
    {
        $data = unpack($type, substr($this->body, $this->position, $size));
        $this->position += $size;
        return $data[1];
    }
947966
public function parse($resource) {

        $result = array();
        $fieldcnt = mysqli_num_fields($resource);


        $fields_transform = array();

        for($i=0;$i<$fieldcnt;$i++) {
            $finfo = mysqli_fetch_field_direct($resource, $i);

            if(isset(self::$mysqli_type[$finfo->type])) {
                $fields_transform[$finfo->name] = self::$mysqli_to_php[self::$mysqli_type[$finfo->type]];
            }
        }

        while($row = mysqli_fetch_assoc($resource)) {
            foreach($fields_transform as $fieldname => $fieldtype) {
               settype($row[$fieldname], $fieldtype);
            }
            $result[] = $row;
        }
        return $result;
    }
989847
public function load($resource, $type = null)
    {
        $config = include $resource;

        if (!is_array($config)) {
            throw new \InvalidArgumentException(
                sprintf('The file "%s" did not return a valid PHP array when included', $resource)
            );
        }

        return $config;
    }
331097
public function load($resource, $type = null)
    {
        if ($this->loaded) {
            throw new \RuntimeException('Do not add this loader twice');
        }

        $routes = new RouteCollection();

        $routes->addCollection(
            $this->addPluginsRoutesCollection()
        );

        $this->loaded = true;

        return $routes;
    }
1086796
public function load($resource, $type = null)
    {
        if ($this->loaded) {
            throw new RuntimeException('Do not add this loader twice');
        }

        $routes = new RouteCollection();

        $routes->add($this->inputControllerRouteName, new Route($this->inputResizeControllerRoute, [
            '_controller' => 'elcodi.controller.metric_input:addEntryAction',
        ]));

        $this->loaded = true;

        return $routes;
    }
3501
public function load($resource, $type = null)
    {
        if (true === $this->loaded) {
            throw new \RuntimeException('Do not add the "graviton.rest.routing.loader" loader twice');
        }

        foreach ($this->services as $service => $serviceConfig) {
            $this->loadService($service, $serviceConfig);
        }

        $this->loaded = true;

        return $this->routes;
    }
1088042
public function parse( Request $request, Response $response )
    {
        $error = parent::parse( $request, $response );

        if ( $error )
        {
            return $error;
        }

        $body = json_decode( $request->getContent() );

        if ( empty( $body ) )
        {
            return self::PARSE;
        }

        if ( empty( $body->method ) || ! isset( $body->params ) )
        {
            return self::INVALID_REQUEST;
        }

        $this->id       = $body->id;
        $this->method   = $body->method;
        $this->params   = $body->params;

        return null;
    }
452154
private function parse($body)
    {
        $result = array();
        $data = json_decode($body);

        $response = is_array($data->response) ? new \stdClass : $data->response;
        if (null == $response) {
            $response = $data;
        }
        $response->errors = $data->errors;
        $response->test = isset($data->test) ? $data->test : $response->test;

        if ($data->successful == true) {
            if ((isset($response->authorized)
                && $response->authorized == true)
                || (isset($response->id)
                && $response->id !== null)
            ) {
                $response->authorization_id = isset($response->id)
                    ? $response->id
                    : $response->token;
            } else {
                $response->authorization_id = null;
            }

            $response->success = true;
        } else {
            $response->success = false;
            $response->authorization_id = null;
        }

        $response->message = isset($response->message) ? $response->message : $data->errors;

        return (array) $response;

    }
202306
public function load(string $resource, string $type = null) : RepositoryInterface
    {
        if (class_exists('Yosymfony\Toml\Toml') === false) {
            throw new \RuntimeException('"Yosymfony Toml" is required to read TOML files.');
        }

        $resourceContent = $resource;
        
        if (empty($type)) {
            $file = $this->getLocation($resource);
            $resourceContent = $this->readFile($file);
        }

        $parsedResource = Toml::parse($resourceContent);
        $repository = new Repository($parsedResource ?? []);

        return $this->parseImports($repository, $resource);
    }
470286
public function load($resource, $type = null)
    {
        if ($this->loaded) {

            throw new \RuntimeException('Do not add this loader twice');
        }

        $routes = new RouteCollection();
        $routes->add($this->controllerRouteName, new Route($this->controllerRoute, array(
            '_controller'   =>  'PaymillBundle:Paymill:execute',
        ), array(), array(), '', array(), array(
            'POST'
        )));

        $this->loaded = true;

        return $routes;
    }
295307
private function getParsedBody(Request $request): array
    {
        $contentType = \explode(';', (string) $request->headers->get('content-type'), 2)[0];

        // JSON object
        switch ($contentType) {
            case static::CONTENT_TYPE_JSON:
                $parsedBody = \json_decode($request->getContent(), true);

                if (\JSON_ERROR_NONE !== \json_last_error()) {
                    throw new BadRequestHttpException('POST body sent invalid JSON');
                }
                break;

            case static::CONTENT_TYPE_FORM_DATA:
                $parsedBody = $this->handleUploadedFiles($request->request->all(), $request->files->all());
                break;

            default:
                throw new BadRequestHttpException(\sprintf(
                    'Batching parser only accepts "%s" or "%s" content-type but got %s.',
                    static::CONTENT_TYPE_JSON,
                    static::CONTENT_TYPE_FORM_DATA,
                    \json_encode($contentType)
                ));
        }

        return $parsedBody;
    }
37606
protected function httpPostJson($uri, $body)
    {
        $this->log[] = [
                        'request' => [
                                    'method' => 'POST',
                                    'uri'    => $uri,
                                    'body'   => $body,
                                    ],
                        ];
        $response = \Httpful\Request::post($uri)
                                                ->basicAuth($this->username, $this->password)
                                                ->sendsAndExpects(\Httpful\Mime::JSON)
                                                ->parseWith(function ($body) {
                                                   return $body;
                                                   //return \Metaclassing\Utility::decodeJson($body);
                                                })
                                                ->body($body)
                                                ->send()
                                                ->body;
        $this->log[count($this->log) - 1]['response'] = $response;
        //if ($response['success'] != true) {
        //    throw new \Exception("post to {$uri} unsuccessful");
        //}

        return $response;
    }
83346
function post($path, $body, $contentType = null)
    {
        return $this->dispatchRequest(
            $this->buildRequest('POST', $path, $body, $contentType)
        );
    }
1255597
public function _parse($body)
    {
        // If the user decided to forgo the automatic
        // smart parsing, short circuit.
        if (!$this->request->auto_parse) {
            return $body;
        }

        // If provided, use custom parsing callback
        if (isset($this->request->parse_callback)) {
            return call_user_func($this->request->parse_callback, $body);
        }

        // Decide how to parse the body of the response in the following order
        //  1. If provided, use the mime type specifically set as part of the `Request`
        //  2. If a MimeHandler is registered for the content type, use it
        //  3. If provided, use the "parent type" of the mime type from the response
        //  4. Default to the content-type provided in the response
        $parse_with = $this->request->expected_type;
        if (empty($this->request->expected_type)) {
            $parse_with = Httpful::hasParserRegistered($this->content_type)
                ? $this->content_type
                : $this->parent_type;
        }

       return Httpful::get($parse_with)->parse($body);
    }