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

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.         protected string $environment
  22.     )
  23.     {
  24.     }
  25.     protected function initialize()
  26.     {
  27.         if ($this->platformClient!==null) return;
  28.         $repo $this->em->getRepository(PlatformClient::class);
  29.         $this->platformClient $repo->fetch();
  30.     }
  31.     public function getStripe(): StripeEndpoint
  32.     {
  33.         return   $this->endpointFactory->createFromShortcode(Endpoint::TYPE_STRIPE,[
  34.             'api_key' => $this->getStripeApiKey(),
  35.             'environment' => $this->environment
  36.         ]);
  37.     }
  38.     /**
  39.      * @return string|null
  40.      */
  41.     public function getPdfLogoContents(?Customer $customer)
  42.     {
  43.         if ($customer !== null && $customer->getPdfLogo()!==null)
  44.         {
  45.             return '@' stream_get_contents$this->fileRepo->getStream($customer->getPdfLogo()) );
  46.         }
  47.         return $this->getPdfLogo()!== null ?  '@' stream_get_contents$this->fileRepo->getStream($this->getPdfLogo()) ) : null;
  48.     }
  49.     public function __call($method$arguments)
  50.     {
  51.         $this->initialize();
  52.         if (
  53.             (=== strpos($method'get'))
  54.             ||
  55.             (=== strpos($method'is'))
  56.             )
  57.             {
  58.             return $this->platformClient->$method();
  59.         }
  60.         throw new \BadMethodCallException('Undefined method '.$method);
  61.     }
  62. }