<?php
namespace Diplix\KMGBundle\Helper;
use Diplix\KMGBundle\Entity\Customer;
use Diplix\KMGBundle\Entity\Endpoint;
use Diplix\KMGBundle\Entity\Platform\PlatformClient;
use Diplix\KMGBundle\Repository\FileRepository;
use Diplix\KMGBundle\Service\Endpoints\EndpointFactory;
use Diplix\KMGBundle\Service\Endpoints\StripeEndpoint;
use Doctrine\ORM\EntityManagerInterface;
/**
* @method getStripeApiKey()
*/
class ClientConfigProvider
{
/** @var PlatformClient */
protected $platformClient;
public function __construct(
protected EntityManagerInterface $em,
protected FileRepository $fileRepo,
protected EndpointFactory $endpointFactory)
{
}
protected function initialize()
{
if ($this->platformClient!==null) return;
$repo = $this->em->getRepository(PlatformClient::class);
$this->platformClient = $repo->fetch();
}
public function getStripe(): StripeEndpoint
{
return $this->endpointFactory->createFromShortcode(Endpoint::TYPE_STRIPE,[
'api_key' => $this->getStripeApiKey(),
]);
}
/**
* @return string|null
*/
public function getPdfLogoContents(?Customer $customer)
{
if ($customer !== null && $customer->getPdfLogo()!==null)
{
return '@' . stream_get_contents( $this->fileRepo->getStream($customer->getPdfLogo()) );
}
return $this->getPdfLogo()!== null ? '@' . stream_get_contents( $this->fileRepo->getStream($this->getPdfLogo()) ) : null;
}
public function __call($method, $arguments)
{
$this->initialize();
if (
(0 === strpos($method, 'get'))
||
(0 === strpos($method, 'is'))
)
{
return $this->platformClient->$method();
}
throw new \BadMethodCallException('Undefined method '.$method);
}
}