当前位置: 首页>>代码示例>>PHP>>正文


PHP Assertion::isJsonString方法代码示例

本文整理汇总了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();
 }
开发者ID:gingerwfms,项目名称:ginger-workflow-engine,代码行数:15,代码来源:ItemCollection.php

示例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);
 }
开发者ID:gingerwfms,项目名称:ginger-workflow-engine,代码行数:16,代码来源:LazyItemsLoader.php

示例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;
 }
开发者ID:rostmefpoter,项目名称:bh,代码行数:20,代码来源:put.php

示例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');
     }
 }
开发者ID:simplyadmire,项目名称:zaaksysteem,代码行数:29,代码来源:AbstractClient.php

示例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;
 }
开发者ID:rostmefpoter,项目名称:bh,代码行数:23,代码来源:post.php

示例6: testIsJsonStringExpectingException

 /**
  * @dataProvider isJsonStringInvalidStringDataprovider
  */
 public function testIsJsonStringExpectingException($invalidString)
 {
     $this->setExpectedException('Assert\\AssertionFailedException', null, Assertion::INVALID_JSON_STRING);
     Assertion::isJsonString($invalidString);
 }
开发者ID:GerDner,项目名称:luck-docker,代码行数:8,代码来源:AssertTest.php

示例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));
 }
开发者ID:gingerwfms,项目名称:ginger-workflow-engine,代码行数:10,代码来源:Item.php

示例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));
 }
开发者ID:gingerwfms,项目名称:ginger-workflow-engine,代码行数:9,代码来源:Arguments.php


注:本文中的Assert\Assertion::isJsonString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。