FluentDOM\Loader\Supports\Json::getJson PHP Method

getJson() private method

private getJson ( mixed $source, string $contentType ) : mixed
$source mixed
$contentType string
return mixed
    private function getJson($source, $contentType)
    {
        if ($this->supports($contentType)) {
            if (is_string($source)) {
                $json = FALSE;
                if (!$this->startsWith($source, '{') && !$this->startsWith($source, '[')) {
                    $source = file_get_contents($source);
                }
                if ($this->startsWith($source, '{') || $this->startsWith($source, '[')) {
                    $json = json_decode($source);
                    if (!($json || is_array($json))) {
                        throw new JsonError(is_callable('json_last_error') ? json_last_error() : -1);
                    }
                }
            } else {
                $json = $source;
            }
            return $json || is_array($json) ? $json : FALSE;
        }
        return FALSE;
    }