Make an array of specified entity from a Response
@param mixed $entityName
@param Response $response
@return Entity[]
198066
public static function makeFromResponse($entityName, $content)
    {
        $content = $content;
        $output = array();
        if (is_array($content)) {
            foreach ($content as $entityData) {
                $output[] = self::makeFromResponse($entityName, $entityData);
            }
        } elseif (is_object($content)) {
            $output = self::mapDataToEntity($entityName, $content);
        } else {
            $output = $content;
        }

        return $output;
    }
957402
public function toArray(Entity $entity, $depth=0) {
		$res = [];

		foreach($entity->getDefinition()->properties() as $name=>$property) {
			if($entity->getDefinition()->property($name) instanceof Property\EntityProperty) {
				if($depth < 1)
					continue;
				if($entity->getDefinition()->property($name)->get('many')) {
					foreach($entity->get($name, null, false) as $subentity)
						$res[$name][] = $subentity->toArray($depth-1);
				}
				else {
					if($subentity = $entity->get($name, null, false))
						$res[$name] = $subentity->toArray($depth-1);
					else
						$res[$name] = null;
				}
			}
			elseif($property->get('many')) {
				$res[$name] = [];
				foreach($entity->get($name) as $k=>$v)
					$res[$name][$k] = $this->propertyToArray($v, $property);
			}
			else
				$res[$name] = $this->propertyToArray($entity->get($name), $property);
		}

		return $res;
	}
1131970
public static function parseResponse(Response $response)
    {
        $jsonData = \GuzzleHttp\json_decode($response->getBody(), true);
        if ($jsonData && 0 == $jsonData['retcode']) {
            $recentList = [];
            foreach ($jsonData['result'] as $recent) {
                $recentList[] = EntityFactory::createEntity(Recent::class, [
                    'type' => $recent['type'],
                    'uin' => $recent['uin'],
                ]);
            }

            return new EntityCollection($recentList);
        }
        throw new ResponseException($jsonData['retcode'], $response);
    }
868275
public function selfFromResponse(array $response)
    {
        $this->fill($response);

        foreach ($this->getSingleNestedEntities() as $key => $value) {
            if (isset($response[$key])) {
                $entityName = $value;
                $this->$key = new $entityName($this->connection, $response[$key]);
            }
        }

        foreach ($this->getMultipleNestedEntities() as $key => $value) {
            if (isset($response[$key])) {
                $entityName = $value['entity'];
                /** @var self $instantiatedEntity */
                $instantiatedEntity = new $entityName($this->connection);
                $this->$key = $instantiatedEntity->collectionFromResult($response[$key]);
            }
        }

        return $this;
    }
67962
protected function CreateObject($methodKey, $entity, $responseClassName = null, $entityId = null, $subEntityId = null, $idempotencyKey = null)
    {
        if (is_null($entityId)) {
            $urlMethod = $this->GetRequestUrl($methodKey);
        } elseif (is_null($subEntityId)) {
            $urlMethod = sprintf($this->GetRequestUrl($methodKey), $entityId);
        } else {
            $urlMethod = sprintf($this->GetRequestUrl($methodKey), $entityId, $subEntityId);
        }

        $requestData = null;
        if (!is_null($entity)) {
            $requestData = $this->BuildRequestData($entity);
        }

        $rest = new RestTool(true, $this->_root);
        $response = $rest->Request($urlMethod, $this->GetRequestType($methodKey), $requestData, $idempotencyKey);

        if (!is_null($responseClassName)) {
            return $this->CastResponseToEntity($response, $responseClassName);
        }

        return $response;
    }
683289
private function parseDescription($filename, $entityClass)
    {
        $parser = new XmlParser();

        $parser->open($filename);

        /** @var EntityStructure $definition */
        $definition = $parser->parse([
            'onBeforeEntity'   => [$this, 'prepareEntity'],
            'onAfterEntity'    => [$this, 'handleEntity'],
            'onAfterField'     => [$this, 'handleField'],
            'onBeforeOption'   => [$this, 'prepareOption'],
            'onAfterOption'    => [$this, 'handleOption'],
            'onBeforeFieldset' => [$this, 'prepareFieldset'],
            'onAfterFieldset'  => [$this, 'handleFieldset'],
        ], $this->locator);

        return $definition;
    }
37425
protected function load($entityId)
    {
        $table = $this->getEntityDescriptor()->getTableName();
        $primaryKey = $this->getEntityDescriptor()
            ->getPrimaryKey()
            ->getField();

        return $this->find()
            ->where([
                "{$table}.{$primaryKey} = :id" => [':id' => $entityId]
            ])
            ->first();
    }
908900
public function getMappedFirstEntitiesByEntityType($entityName)
    {
        $entities = [];
        foreach ($this->data as $data) {
            $entity = $this->createAndReturnNewFirstEntity($data, $entityName);
            if ($entity) {
                $entities[] = $entity;
            }
        }
        return $entities;
    }
1205864
public function serialize(EntityContract $entity, Collection $select = null)
    {
        $bag = parent::serialize($entity, $select);

        $bag->set('files', $entity->files->map(function ($file) {
            return [
                'url' => $file->media->first()->getFullUrl(),
            ];
        }));

        return $bag;
    }
853772
public function handleResponse($response) {

        // No filter has been applied to this request.
        // Standard request, instantiate a single object.
        if(empty($this->filter)) {
            return $this->instantiateEntity($response);
        }

        // Filter applied.
        // Instantiate an object for each result returned.
        else {
            return array_map(function ($object) {
                return $this->instantiateEntity($object);
            }, $response->data);
        }

    }
1076700
protected function parseResponse( Response$response ):array
	{
		$headers= $response->headers;
		$body= $this->achieveSerializer( $this->response_content_type )->decode( $response->body );

		return $this->response_transformer->transform(
			[
				'headers'=> $headers,
				'body'=> $body,
			]
		);
	}
1256160
public static function parseResponse(Response $response)
    {
        $jsonData = \GuzzleHttp\json_decode($response->getBody(), true);
        if ($jsonData && 0 == $jsonData['retcode'] && !empty($jsonData['result'])) {
            $messages = [];
            foreach ($jsonData['result'] as $messageData) {
                $messages[] = static::makeResponseMessage($messageData['poll_type'], $messageData);
            }

            return $messages;
        } elseif (103 == $jsonData['retcode']) {
            throw new Code103ResponseException($response);
        }
        throw new ResponseException($jsonData['retcode'], $response);
    }
68952
public static function entityList()
    {
        $files = File::files(config_path('panel'));

        $list = [];
        foreach ($files as $file) {
            $list[] = new self($file);
        }

        return collect($list)->sortBy(function ($entity) {
            return $entity->name();
        });
    }
515696
protected function parseResponse($response)
    {
        if ($response instanceof ResponseInterface) {
            $response = $response->getBody();
        }

        return new Collection((array) XML::parse($response));
    }
1042000
private function getPropertyNamesForEntity(array $entityConfig, string $entityName): array
    {
        $entityClass = $entityConfig['class'] ?: $entityName;
        $entityReflectionClass = new ReflectionClass($entityClass);

        return \array_map(function (ReflectionProperty $reflectionProperty) {
            return $reflectionProperty->getName();
        }, $entityReflectionClass->getProperties());
    }
1328024
protected static function createListFromResponseArray(
        array $responseArray,
        string $wrapper = null
    ): array {
        $list = [];

        foreach ($responseArray as $className => $element) {
            $list[] = static::createFromResponseArray($element, $wrapper);
        }

        return $list;
    }
1199205
public function getFromEntityByIds(string $entityFrom, array $entityIds, array $filterParams = [])
    {
        $uriAppend = "from/{$entityFrom}";
        $params    = ['entityIds' => implode(",", $entityIds)];
        if ($filterParams) {
            $params['params'] = json_encode([$filterParams]);
        }

        $response = $this->handler->handle('GET', false, $uriAppend, $params)->getData();
        if (!$response) {
            return [];
        }

        $functionalNames = [];
        if (isset($filterParams['functionalNames']) && $filterParams['functionalNames']) {
            $functionalNames = $filterParams['functionalNames'];
        }

        return $this->client->elastic()
                            ->search($this->prepareElasticSearchBody($response, ['functionalNameId' => $functionalNames]))
                            ->all();
    }