mapArray() 공개 메소드

Map an array
public mapArray ( array $json, mixed $array, string $class = null ) : mixed
$json array JSON array structure from json_decode()
$array mixed Array or ArrayObject that gets filled with data from $json
$class string Class name for children objects. All children will get mapped onto this type. Supports class names and simple types like "string" and nullability "string|null". Pass "null" to not convert any values
리턴 mixed Mapped $array is returned
예제 #1
0
 function getMany($path, $entity_name)
 {
     try {
         /**
          * @var $response \GuzzleHttp\Message\AbstractMessage
          */
         $response = $this->client->get($path);
         $data = $response->json();
         $mapper = new \JsonMapper();
         return $mapper->mapArray($data["response"], new \ArrayObject(), $entity_name);
     } catch (ClientException $e) {
         //$e->getMessage();
         $this->throwException($e, $entity_name);
     }
 }
예제 #2
0
 /**
  * Returns the $resultSet from the $response object, or $defaultValue if 
  * the result set is not available
  * @param stdClass $response an API response object
  * @param string $resultSet the name of the result set
  * @param mixed $defaultValue the value to return if the result set is not 
  * available
  * @param mixed an instance of the class the results should be mapped to, or 
  * null to use stdClass
  * @return mixed the normalized response
  */
 private static function normalizeResponse($response, $resultSet, $defaultValue, $targetObject = null)
 {
     if (isset($response->result->{$resultSet})) {
         $result = $response->result->{$resultSet};
         if ($targetObject !== null) {
             $mapper = new JsonMapper();
             if (is_array($result)) {
                 return $mapper->mapArray($result, new ArrayObject(), $targetObject)->getArrayCopy();
             } elseif (is_object($result)) {
                 return $mapper->map($result, $targetObject);
             }
         }
         return $response->result->{$resultSet};
     } else {
         return $defaultValue;
     }
 }
예제 #3
0
 public function addItems(array $items)
 {
     $mapper = new \JsonMapper();
     $this->photo = $mapper->mapArray($items, $this->photo, new Photo());
 }