當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。