Server : Apache System : Linux 145.162.205.92.host.secureserver.net 5.14.0-611.45.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Apr 1 05:56:53 EDT 2026 x86_64 User : tradze ( 1001) PHP Version : 8.1.34 Disable Function : NONE Directory : /home/tradze/www/vendor/braintree/braintree_php/lib/Braintree/ |
<?php
namespace Braintree;
/**
* Braintree GraphQL Client
* process GraphQL requests using curl
*/
class GraphQLClient
{
protected $_service = null;
// phpcs:ignore PEAR.Commenting.FunctionComment.Missing
public function __construct($config)
{
$this->_service = new GraphQL($config);
}
/*
* Make a GraphQL API request
*
* @param object $definition of the query
* @param object $variables optional
*
* @return object result
*/
public function query($definition, $variables = null)
{
return $this->_service->request($definition, $variables);
}
/**
* Extract validation errors from the GraphQL response
*
* @param array $response The GraphQL response
*
* @return array|null validation errors or null
*/
public static function getValidationErrors($response)
{
if (!isset($response['errors']) || !is_array($response['errors'])) {
return null;
}
$validationErrors = array_map(function ($error) {
return ['attribute' => '', 'code' => GraphQLClient::getValidationErrorCode($error), 'message' => $error["message"]];
}, $response['errors']);
return ['errors' => $validationErrors];
}
private static function getValidationErrorCode($error)
{
if (!isset($error['extensions'])) {
return null;
}
$extensions = $error['extensions'];
if (!isset($extensions['legacyCode'])) {
return null;
}
return $extensions['legacyCode'];
}
}