1
0
mirror of synced 2025-01-08 10:27:09 +03:00
DeliveryModuleBundle/Service/RetailCrmClientFactory.php
2020-08-03 15:56:27 +03:00

37 lines
975 B
PHP

<?php
namespace RetailCrm\DeliveryModuleBundle\Service;
use Psr\Log\LoggerInterface;
use RetailCrm\ApiClient;
use RetailCrm\DeliveryModuleBundle\Model\Entity\Account;
class RetailCrmClientFactory implements RetailCrmClientFactoryInterface
{
public function createRetailCrmClient(Account $account, ?LoggerInterface $logger = null): ApiClient
{
if (null === $account) {
throw new \LogicException('Account is not selected');
}
if (empty($account->getCrmUrl())) {
throw new \LogicException('Crm url is empty');
}
if (empty($account->getCrmApiKey())) {
throw new \LogicException('Crm apiKey is empty');
}
$retailCrmClient = new ApiClient(
$account->getCrmUrl(),
$account->getCrmApiKey(),
ApiClient::V5
);
if ($logger) {
$retailCrmClient->setLogger($logger);
}
return $retailCrmClient;
}
}