1
0
mirror of synced 2024-11-22 04:56:04 +03:00
atol-online-client/src/AtolOnlineClient/AtolOnline.php
2018-06-20 11:27:16 +03:00

80 lines
1.8 KiB
PHP

<?php
namespace AtolOnlineClient;
use AtolOnlineClient\Configuration\Connection;
use AtolOnlineClient\Response\OperationResponse;
use Guzzle\Http\Client;
use JMS\Serializer\DeserializationContext;
use JMS\Serializer\SerializationContext;
use JMS\Serializer\SerializerBuilder;
class AtolOnline
{
private $serializer;
/** @var AtolOnlineApi */
private $api;
public function __construct()
{
$this->serializer = SerializerBuilder::create()->build();
}
public function createConfiguration()
{
return new Configuration();
}
public function deserializeOperationResponse($response)
{
return $this->serializer->deserialize(
$response,
OperationResponse::class,
'json',
DeserializationContext::create()->setGroups(['post'])
);
}
public function deserializeCheckStatusResponse($response)
{
return $this->serializer->deserialize(
$response,
OperationResponse::class,
'json',
DeserializationContext::create()->setGroups(['get'])
);
}
public function serializeOperationRequest($request)
{
return $this->serializer->serialize(
$request,
'json',
SerializationContext::create()->setGroups(['set'])
);
}
/**
* @param $client
* @param Connection $connection
* @return AtolOnlineApi
*/
public function createApi(Client $client, Connection $connection)
{
if (!$this->api) {
$this->api = new AtolOnlineApi($client, $connection);
}
return $this->api;
}
/**
* @return AtolOnlineApi
*/
public function getApi()
{
return $this->api;
}
}