Create a collection from the JSON data returned by the rokka.io API.

@param string $jsonString JSON as a string

@return SourceImageCollection
553902
public static function createFromJsonResponse($jsonString)
    {
        $data = json_decode($jsonString, true);

        $sourceImages = array_map(function ($sourceImage) {
            return SourceImage::createFromDecodedJsonResponse($sourceImage);
        }, $data['items']);

        $total = isset($data['total']) ? $data['total'] : 0;
        $links = isset($data['links']) ? $data['links'] : [];
        $cursor = isset($data['cursor']) ? $data['cursor'] : null;

        return new self($sourceImages, $total, $links, $cursor);
    }
242066
private function createToken($jsonData)
    {
        $content = json_decode($jsonData, true);

        if (!is_array($content)) {
            throw new TokenException(sprintf('Could not decode JSON string: "%s"', $jsonData));
        }

        return Token::create($content);
    }
1198510
public static function jsonValidate($jsonString, $asArray)
    {
        $json = json_decode($jsonString, $asArray);

        if (json_last_error() != JSON_ERROR_NONE) {
            throw new InvalidJsonException(json_last_error_msg(), json_last_error());
        }

        return $json;
    }
276811
public function handleJSONRequest( $jsonString ) {
		//Decode JSON string
		$jsonArray = json_decode($jsonString,true);
		if (!$jsonArray) return $this->resp(null,null,-32700,'Cannot Parse JSON');
		if (!isset($jsonArray['jsonrpc'])) return $this->resp(null,null,-32600,'No RPC version');
		if (($jsonArray['jsonrpc']!='2.0')) return $this->resp(null,null,-32600,'Incompatible RPC Version');
		//DO we have an ID to identify this request?
		if (!isset($jsonArray['id'])) return $this->resp(null,null,-32600,'No ID');
		//Fetch the request Identification String.
		$id = $jsonArray['id'];
		//Do we have a method?
		if (!isset($jsonArray['method'])) return $this->resp(null,$id,-32600,'No method');
		//Do we have params?
		if (!isset($jsonArray['params'])) {
			$data = array();
		}
		else {
			$data = $jsonArray['params'];
		}
		//Check method signature
		$method = explode(':',trim($jsonArray['method']));
		if (count($method)!=2) {
			return $this->resp(null, $id, -32600,'Invalid method signature. Use: BEAN:ACTION');
		}
		//Collect Bean and Action
		$beanType = $method[0];
		$action = $method[1];
		//May not contain anything other than ALPHA NUMERIC chars and _
		if (preg_match('/\W/',$beanType)) return $this->resp(null, $id, -32600,'Invalid Bean Type String');
		if (preg_match('/\W/',$action)) return $this->resp(null, $id, -32600,'Invalid Action String');

		try {
			switch($action) {
				case 'store':
					if (!isset($data[0])) return $this->resp(null, $id, -32602,'First param needs to be Bean Object');
					$data = $data[0];
					if (!isset($data['id'])) $bean = RedBean_Facade::dispense($beanType); else
						$bean = RedBean_Facade::load($beanType,$data['id']);
					$bean->import( $data );
					$rid = RedBean_Facade::store($bean);
					return $this->resp($rid, $id);
				case 'load':
					if (!isset($data[0])) return $this->resp(null, $id, -32602,'First param needs to be Bean ID');
					$bean = RedBean_Facade::load($beanType,$data[0]);
					return $this->resp($bean->export(),$id);
				case 'trash':
					if (!isset($data[0])) return $this->resp(null, $id, -32602,'First param needs to be Bean ID');
					$bean = RedBean_Facade::load($beanType,$data[0]);
					RedBean_Facade::trash($bean);
					return $this->resp('OK',$id);
				case 'export':
					if (!isset($data[0])) return $this->resp(null, $id, -32602,'First param needs to be Bean ID');
					$bean = RedBean_Facade::load($beanType,$data[0]);
					$array = RedBean_Facade::exportAll(array($bean),true);
					return $this->resp($array,$id);
				default:
					$modelName = $this->modelHelper->getModelName( $beanType );
					if (!class_exists($modelName)) return $this->resp(null, $id, -32601,'No such bean in the can!');
					$beanModel = new $modelName;
					if (!method_exists($beanModel,$action)) return $this->resp(null, $id, -32601,"Method not found in Bean: $beanType ");
					return $this->resp( call_user_func_array(array($beanModel,$action), $data), $id);
			}
		}
		catch(Exception $exception) {
			return $this->resp(null, $id, -32099,$exception->getCode().'-'.$exception->getMessage());
		}
	}
885494
public function getJson($jsonFile, $jsonSchema = null)
    {
        if (isset($jsonSchema) && array_key_exists($jsonSchema, $this->validation)) {
            $validation = $this->validation[$jsonSchema];
        } elseif ($jsonSchema === null) {
            $validation = $jsonSchema;
        } else {
            throw new Exception('Invalid jsonSchema validation key');
        }

        try {
            return $this->decodeFile($jsonFile, $validation);
        } catch (\RuntimeException $e) {
            // Runtime errors such as file not found
            $this->errors[] = $e->getMessage();
        } catch (ValidationFailedException $e) {
            // Schema validation errors
            $this->errors[] = $e->getMessage();
        } catch (\Exception $e) {
            // Anything else we did not anticipate
            $this->errors[] = 'Unknown Exception in getPageDefinition()';
            $this->errors[] = $e->getMessage();
        }

        return null;
    }
633594
public Map<String, Object> jsonStringToMap(String jsonString) {
        if (StringUtils.isEmpty(jsonString)) {
            return null;
        }
        JSONObject jsonObject;
        try {
            jsonObject = new JSONObject(jsonString);
            return jsonObjectToMap(jsonObject);
        } catch (JSONException e) {
            throw new RuntimeException("Unable to convert string to map: " + jsonString, e);
        }
    }
838789
public static Expression decodeJson(String jsonString) {
        try {
            JsonObject jsonObject = CouchbaseAsyncBucket.JSON_OBJECT_TRANSCODER.stringToJsonObject(jsonString);
            return decodeJson(jsonObject);
        } catch (Exception e) {
            throw new IllegalArgumentException("String is not representing JSON object: " + jsonString);
        }
    }
1245095
public function collection($data, $transformer = null, $resourceKey = null): Collection
    {
        return new Collection($data, $transformer, $resourceKey);
    }
697918
public function parseJwtHeaderContent($jwtHeaderString)
    {

        $tokenJsonHeader = json_decode($jwtHeaderString, true);

        $alg = $tokenJsonHeader['alg'];
        $kid = $tokenJsonHeader['kid'];

        return new JwtHeaderContent($alg, $kid);
    }
1115199
public function jsonPageIsActive($jsonString)
    {
        $page = json_decode($jsonString, true);

        $now = new \DateTime();

        $activeStart = array_key_exists('active_from', $page) ? new \DateTime($page['active_from']) : new \DateTime();
        $activeEnd = array_key_exists('active_to', $page) ? new \DateTime($page['active_to']) : new \DateTime();

        if ($now->getTimestamp() >= $activeStart->getTimestamp() &&
            $now->getTimestamp() <= $activeEnd->getTimestamp()
        ) {
            return $page['status'] == PageInterface::STATUS_PUBLISHED;
        }

        return false;
    }
177045
public function createServiceManagementService($connectionString)
    {
        $settings = ServiceManagementSettings::createFromConnectionString(
            $connectionString
        );

        $certificatePath = $settings->getCertificatePath();
        $httpClient = new HttpClient($certificatePath);
        $serializer = $this->serializer();
        $uri = Utilities::tryAddUrlScheme(
            $settings->getEndpointUri(),
            Resources::HTTPS_SCHEME
        );

        $serviceManagementWrapper = new ServiceManagementRestProxy(
            $httpClient,
            $settings->getSubscriptionId(),
            $uri,
            $serializer
        );

        // Adding headers filter
        $headers = [];

        $headers[Resources::X_MS_VERSION] = Resources::SM_API_LATEST_VERSION;

        $headersFilter = new HeadersFilter($headers);
        $serviceManagementWrapper = $serviceManagementWrapper->withFilter(
            $headersFilter
        );

        return $serviceManagementWrapper;
    }
976745
@SuppressWarnings("unchecked")
    public BaseBo fromJson(String jsonString) {
        Map<String, Object> dataMap = null;
        try {
            dataMap = jsonString != null ? SerializationUtils.fromJsonString(jsonString, Map.class)
                    : null;
        } catch (Exception e) {
            dataMap = null;
        }
        return fromMap(dataMap);
    }
459701
public T parse(String jsonString) throws IOException {
        JsonParser jsonParser = LoganSquare.JSON_FACTORY.createParser(jsonString);
        jsonParser.nextToken();
        return parse(jsonParser);
    }
1282710
public static function fromJson($json)
    {
        $data = json_decode($json);

        $expireDate = is_null($data->expire) ? null : new \DateTime($data->expire, new \DateTimeZone('UTC'));

        // Recreate the object.
        return new static($data->token, $expireDate);
    }
970954
protected function logCollectedSourceFiles(JsonFile $jsonFile)
    {
        $sourceFiles = $jsonFile->getSourceFiles();
        $numFiles = count($sourceFiles);

        $this->logger->info(sprintf('Found <info>%s</info> source file%s:', number_format($numFiles), $numFiles > 1 ? 's' : ''));

        foreach ($sourceFiles as $sourceFile) {
            /* @var $sourceFile \PhpCoveralls\Bundle\CoverallsBundle\Entity\SourceFile */
            $coverage = $sourceFile->reportLineCoverage();
            $template = '  - ' . $this->colorizeCoverage($coverage, '%6.2f%%') . ' %s';

            $this->logger->info(sprintf($template, $coverage, $sourceFile->getName()));
        }

        $coverage = $jsonFile->reportLineCoverage();
        $template = 'Coverage: ' . $this->colorizeCoverage($coverage, '%6.2f%% (%d/%d)');
        $metrics = $jsonFile->getMetrics();

        $this->logger->info(sprintf($template, $coverage, $metrics->getCoveredStatements(), $metrics->getStatements()));
    }
911641
public static function create($connectionString)
    {
        if (!$connectionString instanceof Uri) {
            $uri = new Uri($connectionString);
        } else {
            $uri = $connectionString;
        }

        $scheme = ucfirst($uri->getScheme());

        $class = explode('\\', get_class());
        array_pop($class);
        $class[] = strpos($scheme, 'Pdo') === 0 ? 'Pdo' : $scheme;
        $class[] = $scheme;
        $class = implode('\\', $class);

        $db = new $class();
        $db->uri = $uri;

        return $db;
    }
409732
protected function decodeJson($jsonString)
    {
        $jsonErrors = [
            \JSON_ERROR_DEPTH => 'JSON_ERROR_DEPTH - Maximum stack depth exceeded',
            \JSON_ERROR_STATE_MISMATCH => 'JSON_ERROR_STATE_MISMATCH - Underflow or the modes mismatch',
            \JSON_ERROR_CTRL_CHAR => 'JSON_ERROR_CTRL_CHAR - Unexpected control character found',
            \JSON_ERROR_SYNTAX => 'JSON_ERROR_SYNTAX - Syntax error, malformed JSON',
            \JSON_ERROR_UTF8 => 'JSON_ERROR_UTF8 - Malformed UTF-8 characters, possibly incorrectly encoded'
        ];

        // Can we use JSON_BIGINT_AS_STRING?
        $options = (version_compare(\PHP_VERSION, '5.4.0', '>=') and ! (defined('JSON_C_VERSION') and \PHP_INT_SIZE > 4)) ? \JSON_BIGINT_AS_STRING : 0;
        $data = json_decode($jsonString, false, 512, $options);

        if (json_last_error() !== \JSON_ERROR_NONE) {
            $last = json_last_error();

            $error = 'Unknown error';

            if (isset($jsonErrors[$last])) {
                $error = $jsonErrors[$last];
            }

            throw new InputException('Unable to parse JSON data: ' . $error);
        }

        return $data;
    }