@param $response
@param string $indexAttribute
@param array $existsAttributes
@param array $postAttributes

@return array|null
429520
protected function parseGetPosts($response, $indexAttribute = null, $existsAttributes = [], $postAttributes = []) {

		$posts = $indexAttribute === null ? $response : ArrayHelper::getValue($response, $indexAttribute);

		if (empty($posts)) {
			return null;
		}

		$list = [];
		foreach ($posts as $post) {
			if ($this->isArrayHasKeys($post, $existsAttributes)) {

				$time_created = ArrayHelper::getValue($post, $postAttributes['time_created']);

				array_push($list, [
					'service_id_author' => ArrayHelper::getValue($post, $postAttributes['service_id_author']),
					'service_id_post' => ArrayHelper::getValue($post, $postAttributes['service_id_post']),
					'time_created' => is_integer($time_created) ? $time_created : strtotime($time_created),
					'content' => ArrayHelper::getValue($post, $postAttributes['content']),
				]);
			}
		}

		return $list;
	}
87041
protected function handleMultiBulkResponse(string $response): ?array
	{
		if($response === '*-1')
		{
			return null;
		}

		$data = [];

		$count = (int) substr($response, 1);

		for($i = 0; $i < $count; $i++)
		{
			$data[] = $this->getResponse();
		}

		return $data;
	}
174833
protected function CastResponseToEntity($response, $entityClassName, $asDependentObject = false)
    {
        if (is_array($response)) {
            $list = array();
            foreach ($response as $responseObject) {
                array_push($list, $this->CastResponseToEntity($responseObject, $entityClassName));
            }

            return $list;
        }

        if (is_string($entityClassName)) {
            $entity = new $entityClassName();
        } else {
            throw new Exception('Cannot cast response to entity object. Wrong entity class name');
        }

        $responseReflection = new \ReflectionObject($response);
        $entityReflection = new \ReflectionObject($entity);
        $responseProperties = $responseReflection->getProperties();

        $subObjects = $entity->GetSubObjects();
        $dependsObjects = $entity->GetDependsObjects();

        foreach ($responseProperties as $responseProperty) {
            $responseProperty->setAccessible(true);

            $name = $responseProperty->getName();
            $value = $responseProperty->getValue($response);

            if ($entityReflection->hasProperty($name)) {
                $entityProperty = $entityReflection->getProperty($name);
                $entityProperty->setAccessible(true);

                if ($entityProperty->getName() == "DeclaredUBOs") {
                    $declaredUbos = [];
                    foreach ($value as $declaredUboRaw) {
                        $declaredUbo = new \MangoPay\DeclaredUbo();
                        $declaredUbo->UserId = $declaredUboRaw->UserId;
                        $declaredUbo->Status = $declaredUboRaw->Status;
                        $declaredUbo->RefusedReasonType = $declaredUboRaw->RefusedReasonMessage;
                        $declaredUbo->RefusedReasonMessage = $declaredUboRaw->RefusedReasonMessage;
                        array_push($declaredUbos, $declaredUbo);
                    }
                    $value = $declaredUbos;
                }

                // is sub object?
                if (isset($subObjects[$name])) {
                    if (is_null($value)) {
                        $object = null;
                    } else {
                        $object = $this->CastResponseToEntity($value, $subObjects[$name]);
                    }

                    $entityProperty->setValue($entity, $object);
                } else {
                    $entityProperty->setValue($entity, $value);
                }

                // has dependent object?
                if (isset($dependsObjects[$name])) {
                    $dependsObject = $dependsObjects[$name];
                    $entityDependProperty = $entityReflection->getProperty($dependsObject['_property_name']);
                    $entityDependProperty->setAccessible(true);
                    $entityDependProperty->setValue($entity, $this->CastResponseToEntity($response, $dependsObject[$value], true));
                }
            } else {
                if ($asDependentObject || !empty($dependsObjects)) {
                    continue;
                } else {
                    /* UNCOMMENT THE LINE BELOW TO ENABLE RESTRICTIVE REFLECTION MODE */
                    //throw new Exception('Cannot cast response to entity object. Missing property ' . $name .' in entity ' . $entityClassName);

                    continue;
                }
            }
        }

        return $entity;
    }
25279
protected function checkOAuthTokenResponse($response)
    {
        if (property_exists($response, 'error') && property_exists($response, 'error_description')) {
            throw new Error($response->error, $response->error_description);
        }
    }
399724
def posts_from(response)
      response.fetch('posts', EMPTY_ARRAY).map do |post_hash|
        Post.from_hash(post_hash)
      end
    end
941579
public function checkElementKey(ServerRequest $request, Response $response): Response
    {
        $elementKey = $request->getQueryParams()['key'];

        $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
        $storageRepository = $objectManager->get(StorageRepository::class);

        $isAvailable = true;
        if ($storageRepository->loadElement('tt_content', $elementKey)) {
            $isAvailable = false;
        }

        return new JsonResponse(['isAvailable' => $isAvailable]);
    }
715709
private function collectResponse(
        HttpAdapterInterface $httpAdapter,
        InternalRequestInterface $request,
        ResponseInterface $response
    ) {
        $request = $this->getTimer()->stop($request);

        $this->datas['responses'][] = [
            'adapter'  => $httpAdapter->getName(),
            'request'  => $this->getFormatter()->formatRequest($request),
            'response' => $this->getFormatter()->formatResponse($response),
        ];

        return $request;
    }
214046
private function handleResponse($response)
    {
        if ($response instanceof PagedListResponse || $response instanceof GaxPagedListResponse) {
            $response = $response->getPage()->getResponseObject();
        }

        if ($response instanceof Message) {
            return $this->serializer->encodeMessage($response);
        }

        if ($response instanceof OperationResponse || $response instanceof GaxOperationResponse) {
            return $response;
        }

        if ($response instanceof ServerStream || $response instanceof GaxServerStream) {
            return $this->handleStream($response);
        }

        return null;
    }
372774
public function respond($response, $status, $headers, $options)
    {
        switch ($this->getRequestFormat()) {
            case 'html' :
            case 'text/html' :
                return Response::make($response, $status, $headers, $options)
                    ->header('Content-Type', 'text/html');
            default :
                // whether 'Content-Type' is NULL or equal to anything such as 'application/json' response will be JSON
                return Response::json($response, $status, $headers, $options);
        }
    }
1322969
protected function _httpAuthenticate(Varien_Object $response)
    {
        $result = array(
            'authentication' => false,
            'message' => ''
        );

        $this->fixCgiHttpAuthentication(); //add cgi support
        $internalMerchantAccount = $this->_getConfigData('merchantAccount');
        $username = $this->_getConfigData('notification_username');
        $password = Mage::helper('core')->decrypt($this->_getConfigData('notification_password'));
        $submitedMerchantAccount = $response->getData('merchantAccountCode');

        if (empty($submitedMerchantAccount) && empty($internalMerchantAccount)) {
            if (strtolower(
                substr(
                    $response->getData('pspReference'), 0,
                    17
                )
            ) == "testnotification_" || strtolower(
                substr(
                    $response->getData('pspReference'), 0,
                    5
                )
            ) == "test_") {
                Mage::log(
                    'Notification test failed: merchantAccountCode is empty in magento settings', Zend_Log::DEBUG,
                    "adyen_notification.log", true
                );
                $result['message'] = 'merchantAccountCode is empty in magento settings';
            }

            return $result;
        }

        // validate username and password
        if ((!isset($_SERVER['PHP_AUTH_USER']) && !isset($_SERVER['PHP_AUTH_PW']))) {
            if (strtolower(
                substr(
                    $response->getData('pspReference'), 0,
                    17
                )
            ) == "testnotification_" || strtolower(
                substr(
                    $response->getData('pspReference'), 0,
                    5
                )
            ) == "test_") {
                Mage::log(
                    'Authentication failed: PHP_AUTH_USER and PHP_AUTH_PW are empty. See Adyen Magento manual CGI mode',
                    Zend_Log::DEBUG, "adyen_notification.log", true
                );
                $result['message'] = 'Authentication failed: PHP_AUTH_USER and PHP_AUTH_PW are empty. See Adyen Magento manual CGI mode';
            }

            return $result;
        }

        $accountCmp = !$this->_getConfigData('multiple_merchants')
            ? strcmp($submitedMerchantAccount, $internalMerchantAccount)
            : 0;
        $usernameCmp = strcmp($_SERVER['PHP_AUTH_USER'], $username);
        $passwordCmp = strcmp($_SERVER['PHP_AUTH_PW'], $password);
        if ($accountCmp === 0 && $usernameCmp === 0 && $passwordCmp === 0) {
            $result['authentication'] = true;
            return $result;
        }

        // If notification is test check if fields are correct if not return error
        if (strtolower(
            substr(
                $response->getData('pspReference'), 0,
                17
            )
        ) == "testnotification_" || strtolower(
            substr(
                $response->getData('pspReference'), 0,
                5
            )
        ) == "test_") {
            if ($accountCmp != 0) {
                $result['message'] = "MerchantAccount in notification is not the same as in Magento settings and Allow multiple merchants option is not enabled";
            } elseif ($usernameCmp != 0 || $passwordCmp != 0) {
                $result['message'] = "username (PHP_AUTH_USER) and/or password (PHP_AUTH_PW) are not the same as Magento settings";
            }

            Mage::log($result['message'], Zend_Log::DEBUG, "adyen_notification.log", true);
        }

        return $result;
    }
1339409
public function normalize(JsonRpcResponse $response) : ?array
    {
        // Notifications must not have a response, even if they are on error
        if ($response->isNotification()) {
            return null;
        }

        $data = [
            self::KEY_JSON_RPC => $response->getJsonRpc(),
            self::KEY_ID => $response->getId()
        ];

        if ($response->getError()) {
            $data[self::KEY_ERROR] = $this->normalizeError(
                $response->getError()
            );
        } else {
            $data[self::KEY_RESULT] = $response->getResult();
        }

        return $data;
    }
340605
protected function getResultFromResponse(Response $response)
    {
        $included     = $this->getIncludedArray($response->getIncluded());
        $includedFull = $this->getIncludedArray($response->getIncluded(), false);

        $result = [];
        foreach ($response->getData() as $element) {
            $type   = $element['attributes']['type'];
            $entity = $includedFull[$type][$element['attributes'][substr($type, 0, -1) . 'Id']];

            if (is_null($mapperClass = $this->getMapperClass($type))) {
                throw new EntityNotFoundException("Entity mapper class for $type was not found");
            }

            $result[] = $this->createObject($mapperClass, $entity, $included);
        }

        return $result;
    }
837991
public function existsType($indexName, $type)
	{
		$index = $this->getRegistered($indexName);

		$params = [
			'index' => $index->getInternalName(),
			'type'  => $type
		];

		return $this->elasticSearcher->getClient()->indices()->existsType($params);
	}
775996
public function prepare_response_for_collection( $response ) {
		if ( ! ( $response instanceof WP_REST_Response ) ) {
			return $response;
		}

		$data = (array) $response->get_data();
		$server = rest_get_server();

		if ( method_exists( $server, 'get_compact_response_links' ) ) {
			$links = call_user_func( array( $server, 'get_compact_response_links' ), $response );
		} else {
			$links = call_user_func( array( $server, 'get_response_links' ), $response );
		}

		if ( ! empty( $links ) ) {
			$data['_links'] = $links;
		}

		return $data;
	}
613255
public function indexExists(IndexEvent $event)
    {
        $request = new Exists();
        $request->index($event->getIndexCode());

        /** @var \OpenSearchServer\Response\Response $response */
        $response = $this->getClient()->submit($request);

        if (true !== $response->isSuccess()) {
            throw new IndexNotFoundException(sprintf("The index '%s' doesn't exists with the current configuration", $event->getIndexCode()));
        }
    }
661811
public function updateResponseMsisdn($data_response = [])
    {
        try {
            if (isset($this->config[self::DETECTION_IS_SDP]) && $this->config[self::DETECTION_IS_SDP] === TRUE) {
                $inputParams = ['data_response' => $data_response,];
                $this->debug->info(__FUNCTION__, 'Input Params: ' . json_encode($inputParams));
                // Sử dụng API: /api/v2/sdp/detection/update
                $updateResponseUrl       = $this->hostname . $this->config[self::API_UPDATE_SDP_DETECTION]['path'];
                $updateResponseSignature = md5($data_response['requestId'] . $this->config[self::API_UPDATE_SDP_DETECTION]['prefix'] . $data_response['responseData'] . $this->config[self::API_UPDATE_SDP_DETECTION]['prefix'] . $this->config[self::API_UPDATE_SDP_DETECTION]['token']);
                $updateResponseParams    = [
                    'requestId'    => $data_response['requestId'],
                    'responseData' => $data_response['responseData'],
                    'signature'    => $updateResponseSignature
                ];
                $this->debug->debug(__FUNCTION__, '$updateResponseUrl: ' . json_encode($updateResponseUrl));
                $this->debug->debug(__FUNCTION__, '$updateResponseSignature: ' . json_encode($updateResponseSignature));
                $this->debug->debug(__FUNCTION__, '$updateResponseParams: ' . json_encode($updateResponseParams));
                // Call API Update Detection
                $sendRequest = $this->requests->sendRequest($updateResponseUrl, $updateResponseParams);
                $this->debug->info(__FUNCTION__, '$sendRequest Result: ' . json_encode($sendRequest));
                if ($sendRequest != NULL) {
                    $resultRequest = json_decode(trim($sendRequest));
                    if (isset($resultRequest->result) && $resultRequest->result == 0) {
                        if (isset($resultRequest->phone_number) && !empty($resultRequest->phone_number)) {
                            $isMsisdn = trim($resultRequest->phone_number);
                            if ($this->nativeSession === TRUE) {
                                $this->debug->debug(__FUNCTION__, 'set native Session');
                                $this->debug->debug(__FUNCTION__, '$isMsisdn: ' . json_encode($isMsisdn));
                                Session::setUserdata(self::SESSION_MSISDN_DEFAULT, $isMsisdn);
                            }
                            $result = [
                                'status'       => 0,
                                'msisdn'       => $isMsisdn,
                                'data'         => isset($resultRequest->data) ? $resultRequest->data : NULL,
                                'session_data' => [
                                    'native_session'     => $this->nativeSession,
                                    'session_msisdn_key' => self::SESSION_MSISDN_DEFAULT
                                ]
                            ];
                        } else {
                            $result = [
                                'status' => 1,
                                'data'   => $resultRequest
                            ];
                        }
                    } else {
                        $result = [
                            'status' => 1,
                            'data'   => $resultRequest
                        ];
                    }
                    $this->debug->info(__FUNCTION__, 'Final Result: ' . json_encode($result));

                    return $result;
                } else {
                    $this->debug->info(__FUNCTION__, '$sendRequest Result is Null');

                    return FALSE;
                }
            } else {
                $inputParams = ['data_response' => $data_response,];
                $this->debug->info(__FUNCTION__, 'Input Params: ' . json_encode($inputParams));
                // Sử dụng API: /services/api/wap/v1/msisdn/update-response.html
                $updateResponseUrl       = $this->hostname . $this->config[self::API_UPDATE_REQUEST_MSISDN]['path'];
                $updateResponseSignature = md5($data_response['requestId'] . $this->config[self::API_UPDATE_REQUEST_MSISDN]['prefix'] . $data_response['responseData'] . $this->config[self::API_UPDATE_REQUEST_MSISDN]['prefix'] . $this->config[self::API_UPDATE_REQUEST_MSISDN]['token']);
                $updateResponseParams    = [
                    'requestId'    => $data_response['requestId'],
                    'responseData' => $data_response['responseData'],
                    'signature'    => $updateResponseSignature
                ];
                $this->debug->debug(__FUNCTION__, '$updateResponseUrl: ' . json_encode($updateResponseUrl));
                $this->debug->debug(__FUNCTION__, '$updateResponseSignature: ' . json_encode($updateResponseSignature));
                $this->debug->debug(__FUNCTION__, '$updateResponseParams: ' . json_encode($updateResponseParams));
                // Call API Update Detection
                $sendRequest = $this->requests->sendRequest($updateResponseUrl, $updateResponseParams);
                $this->debug->info(__FUNCTION__, '$sendRequest Result: ' . json_encode($sendRequest));
                if ($sendRequest != NULL) {
                    $resultRequest = json_decode(trim($sendRequest));
                    if (isset($resultRequest->Result) && $resultRequest->Result == 0) {
                        if (isset($resultRequest->MSISDN) && !empty($resultRequest->MSISDN)) {
                            $isMsisdn = trim($resultRequest->MSISDN);
                            if ($this->nativeSession === TRUE) {
                                $this->debug->debug(__FUNCTION__, 'set native Session');
                                $this->debug->debug(__FUNCTION__, '$isMsisdn: ' . json_encode($isMsisdn));
                                Session::setUserdata(self::SESSION_MSISDN_DEFAULT, $isMsisdn);
                            }
                            $result = [
                                'status'       => 0,
                                'msisdn'       => $isMsisdn,
                                'data'         => $resultRequest->Data,
                                'session_data' => [
                                    'native_session'     => $this->nativeSession,
                                    'session_msisdn_key' => self::SESSION_MSISDN_DEFAULT
                                ]
                            ];
                        } else {
                            $result = [
                                'status' => 1,
                                'data'   => $resultRequest
                            ];
                        }
                    } else {
                        $result = [
                            'status' => 1,
                            'data'   => $resultRequest
                        ];
                    }
                    $this->debug->info(__FUNCTION__, 'Final Result: ' . json_encode($result));

                    return $result;
                } else {
                    $this->debug->info(__FUNCTION__, '$sendRequest Result is Null');

                    return FALSE;
                }
            }
        }
        catch (\Exception $e) {
            $message = 'Error File: ' . $e->getFile() . ' - Line: ' . $e->getLine() . ' - Code: ' . $e->getCode() . ' - Message: ' . $e->getMessage();
            $this->debug->error(__FUNCTION__, $message);

            return NULL;
        }
    }
141248
protected function _isValidResponse(array $response) {
        return (
            array_key_exists('results', $response) &&
            array_key_exists(0, $response['results']) &&
            array_key_exists('address_components', $response['results'][0]) &&
            array_key_exists('geometry', $response['results'][0])
        );
    }