本文整理汇总了PHP中Assert\Assertion::isJsonString方法的典型用法代码示例。如果您正苦于以下问题:PHP Assertion::isJsonString方法的具体用法?PHP Assertion::isJsonString怎么用?PHP Assertion::isJsonString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Assert\Assertion
的用法示例。
在下文中一共展示了Assertion::isJsonString方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fromJSON
/**
* @param string $jsonString
* @return Result
*/
public static function fromJSON($jsonString)
{
Assertion::isJsonString($jsonString);
$itemJsonStrings = json_decode($jsonString, true);
$items = array();
foreach ($itemJsonStrings as $anItemJsonString) {
$items[] = Item::fromJSON($anItemJsonString);
}
return new ItemCollection($items);
$p = new Paginator();
}
示例2: fromJSON
/**
* @param string $jsonString
* @return LazyItemsLoader
* @throws \RuntimeException
*/
public static function fromJSON($jsonString)
{
if (is_null(static::$itemsLoaderManager)) {
throw new \RuntimeException('ItemsLoaderManager is missing');
}
Assertion::isJsonString($jsonString);
$anItemsLoaderName = json_decode($jsonString);
Assertion::string($anItemsLoaderName);
$anItemsLoader = static::$itemsLoaderManager->get($anItemsLoaderName);
return new LazyItemsLoader($anItemsLoader);
}
示例3: execute
public function execute(Request $request, Response $response, callable $next = null)
{
$pathParams = $request->getAttribute('pathParams');
$params = $request->getQueryParams();
$body = $request->getBody();
\Assert\Assertion::keyExists($pathParams, 'name');
\Assert\Assertion::keyExists($pathParams, 'id');
\Assert\Assertion::isJsonString($body);
$collection = $pathParams['name'];
$id = $pathParams['id'];
$data = json_decode($body, true);
$this->boot()->db->table($collection)->update($data, "`id` = {$id}");
$item = $this->boot()->db->table($collection)->fetchRow("`id` = {$id}");
$hal = new Hal("/collection/{$collection}/{$id}", $item->toArray());
$response = $response->withBody($this->toStream($hal->asJson()));
if ($next) {
$response = $next($request, $response);
}
return $response;
}
示例4: request
/**
* @param string $requestMethod
* @param string $path
* @param array $options
* @return array
* @throws RequestException If the request fails
* @throws ResponseException If the response does not contain valid json / the expected structure
*/
public function request($requestMethod, $path, array $options = [])
{
$url = $this->buildRequestUrl($path);
$options = $this->buildRequestConfiguration($options);
try {
$response = $this->client->request($requestMethod, $url, $options);
if (!$response instanceof Response) {
throw new \Exception('An error occurred while calling the API');
}
$content = $response->getBody()->getContents();
Assertion::isJsonString($content);
$content = json_decode($content, true);
return $this->getResult($content);
} catch (GuzzleException $exception) {
throw new RequestException('An error occurred while calling the API');
} catch (InvalidArgumentException $exception) {
throw new ResponseException('The response did not contain valid JSON');
} catch (\Exception $exception) {
throw new RequestException('An error occurred while calling the API');
}
}
示例5: execute
public function execute(Request $request, Response $response, callable $next = null)
{
try {
$pathParams = $request->getAttribute('pathParams');
\Assert\Assertion::keyExists($pathParams, 'name');
$body = $request->getBody();
\Assert\Assertion::isJsonString($body);
$collection = $pathParams['name'];
$data = json_decode($body, true);
$id = $this->boot()->db->table($collection)->insert($data);
$item = $this->boot()->db->table($collection)->fetchRow("`id` = {$id}");
$hal = new Hal("/collection/{$collection}/{$id}", $item->toArray());
$response = $response->withBody($this->toStream($hal->asJson()));
} catch (\Exception $ex) {
$problem = new \Crell\ApiProblem\ApiProblem($ex->getMessage(), $request->getUri()->getPath());
$problem->setDetail($ex->getTraceAsString())->setStatus($ex->getCode());
return $response->withStatus(500)->withBody($this->toStream($problem->asJson()));
}
if ($next) {
$response = $next($request, $response);
}
return $response;
}
示例6: testIsJsonStringExpectingException
/**
* @dataProvider isJsonStringInvalidStringDataprovider
*/
public function testIsJsonStringExpectingException($invalidString)
{
$this->setExpectedException('Assert\\AssertionFailedException', null, Assertion::INVALID_JSON_STRING);
Assertion::isJsonString($invalidString);
}
示例7: fromJSON
/**
* @param string $jsonString
* @return Item
* @throws \Assert\AssertionFailedException
*/
public static function fromJSON($jsonString)
{
Assertion::isJsonString($jsonString);
return new Item(json_decode($jsonString, true));
}
示例8: fromString
/**
* @param $argumentsString
* @return Arguments
*/
public function fromString($argumentsString)
{
Assertion::isJsonString($argumentsString, "ArgumentsString must be valid JSON Format");
return new Arguments(json_decode($argumentsString, true));
}