src/Diplix/KMGBundle/Helper/ClientConfigProvider.php line 27

Open in your IDE?
  1. <?php
  2. namespace Diplix\KMGBundle\Helper;
  3. use Diplix\KMGBundle\Entity\Customer;
  4. use Diplix\KMGBundle\Entity\Endpoint;
  5. use Diplix\KMGBundle\Entity\Platform\PlatformClient;
  6. use Diplix\KMGBundle\Repository\FileRepository;
  7. use Diplix\KMGBundle\Service\Endpoints\EndpointFactory;
  8. use Diplix\KMGBundle\Service\Endpoints\StripeEndpoint;
  9. use Doctrine\ORM\EntityManagerInterface;
  10. /**
  11.  * @method getStripeApiKey()
  12.  */
  13. class ClientConfigProvider
  14. {
  15.     /** @var PlatformClient */
  16.     protected $platformClient;
  17.     public function __construct(
  18.         protected EntityManagerInterface $em,
  19.         protected FileRepository $fileRepo,
  20.         protected EndpointFactory $endpointFactory)
  21.     {
  22.     }
  23.     protected function initialize()
  24.     {
  25.         if ($this->platformClient!==null) return;
  26.         $repo $this->em->getRepository(PlatformClient::class);
  27.         $this->platformClient $repo->fetch();
  28.     }
  29.     public function getStripe(): StripeEndpoint
  30.     {
  31.         return   $this->endpointFactory->createFromShortcode(Endpoint::TYPE_STRIPE,[
  32.             'api_key' => $this->getStripeApiKey(),
  33.         ]);
  34.     }
  35.     /**
  36.      * @return string|null
  37.      */
  38.     public function getPdfLogoContents(?Customer $customer)
  39.     {
  40.         if ($customer !== null && $customer->getPdfLogo()!==null)
  41.         {
  42.             return '@' stream_get_contents$this->fileRepo->getStream($customer->getPdfLogo()) );
  43.         }
  44.         return $this->getPdfLogo()!== null ?  '@' stream_get_contents$this->fileRepo->getStream($this->getPdfLogo()) ) : null;
  45.     }
  46.     public function __call($method$arguments)
  47.     {
  48.         $this->initialize();
  49.         if (
  50.             (=== strpos($method'get'))
  51.             ||
  52.             (=== strpos($method'is'))
  53.             )
  54.             {
  55.             return $this->platformClient->$method();
  56.         }
  57.         throw new \BadMethodCallException('Undefined method '.$method);
  58.     }
  59. }