Beispiel #1
0
 public function testDecodingToObject()
 {
     /* Given... (Fixture) */
     $coder = new JsonCoder();
     /* When... (Action) */
     $actual = $coder->decode(self::JSON_SIMPLE_SAMPLE, TRUE);
     /* Then... (Assertions) */
     $expected = (object) ['some_key' => "This is so a test."];
     $this->assertEquals($expected, $actual);
 }
Beispiel #2
0
 /**
  * @param Request $request
  * @param Params $params
  * @param RequestAction $action
  * @return boolean
  * @throws ParseException
  */
 private function isPrimaryResourceAList(Request $request, Params $params, RequestAction $action)
 {
     $json = $request->getContent();
     if (RequestAction::TARGET_RESOURCE == $action->target && in_array($action->name, [RequestAction::ACTION_CREATE, RequestAction::ACTION_UPDATE])) {
         $data = $this->jsonCoder->decode($json);
         if (!is_array($data) || !isset($data[$params->primaryType])) {
             throw new ParseException(self::ERROR_RESOURCE_CONTENT_MISSING);
         }
         return !Util\ArrayHelper::isAssociative($data[$params->primaryType]);
     }
     return FALSE;
 }
Beispiel #3
0
 /**
  * @param Params $params
  * @param \stdClass|string $schema
  * @param array &$entityData
  */
 protected function prepareData(Params $params, $schema, array &$entityData)
 {
     foreach ($entityData as &$data) {
         $json = Util\ArrayHelper::toObject($data);
         if (!$this->jsonCoder->matchSchema($json, $schema)) {
             $message = $this->jsonCoder->getSchemaErrorMessage();
             throw new ParseException($message);
         }
         $this->hydrant->hydrate($params, $data);
     }
     return $entityData;
 }
 /**
  * Returns the latest schema matching errors as a text message.
  * @return string
  * @see http://php.net/manual/en/function.json-last-error-msg.php
  */
 public function getSchemaErrorMessage()
 {
     return $this->jsonCoder->getSchemaErrorMessage();
 }