vendor/qipsius/tcpdf-bundle/src/QipsiusTCPDFBundle.php line 11

Open in your IDE?
  1. <?php
  2. namespace Qipsius\TCPDFBundle;
  3. use Qipsius\TCPDFBundle\DependencyInjection\QipsiusTCPDFExtension;
  4. use RuntimeException;
  5. use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
  6. use Symfony\Component\Filesystem\Filesystem;
  7. use Symfony\Component\HttpKernel\Bundle\AbstractBundle;
  8. class QipsiusTCPDFBundle extends AbstractBundle
  9. {
  10.     public function getPath(): string
  11.     {
  12.         return dirname(__DIR__);
  13.     }
  14.     public function getContainerExtension(): ?ExtensionInterface
  15.     {
  16.         return new QipsiusTCPDFExtension();
  17.     }
  18.     /**
  19.      * Ran on bundle boot, our TCPDF configuration constants get defined here if required.
  20.      */
  21.     public function boot(): void
  22.     {
  23.         if (!$this->container->hasParameter('qipsius_tcpdf.tcpdf')) {
  24.             return;
  25.         }
  26.         // Define our TCPDF variables
  27.         $config $this->container->getParameter('qipsius_tcpdf.tcpdf');
  28.         // TCPDF needs some constants defining if our configuration determines we should do so (default true)
  29.         // Set tcpdf.k_tcpdf_external_config to false to use the TCPDF core defaults
  30.         if ($config['k_tcpdf_external_config']) {
  31.             foreach ($config as $k => $v) {
  32.                 $constKey strtoupper($k);
  33.                 if (!defined($constKey)) {
  34.                     $value $this->container->getParameterBag()->resolveValue($v);
  35.                     // All K_ constants are required
  36.                     if (=== stripos($k'k_')) {
  37.                         if (('k_path_cache' === $k || 'k_path_url_cache' === $k) && !is_dir($value)) {
  38.                             $this->createDirectory($value);
  39.                         }
  40.                         if (in_array($constKey, [
  41.                             'K_PATH_URL',
  42.                             'K_PATH_MAIN',
  43.                             'K_PATH_FONTS',
  44.                             'K_PATH_CACHE',
  45.                             'K_PATH_URL_CACHE',
  46.                             'K_PATH_IMAGES',
  47.                         ])) {
  48.                             $value .= (str_ends_with($value'/') ? '' '/');
  49.                         }
  50.                     }
  51.                     define($constKey$value);
  52.                 }
  53.             }
  54.         }
  55.     }
  56.     /**
  57.      * @throws RuntimeException
  58.      */
  59.     private function createDirectory(string $filePath): void
  60.     {
  61.         $filesystem = new Filesystem();
  62.         if (false === $filesystem->mkdir($filePath)) {
  63.             throw new RuntimeException(sprintf('Could not create directory %s'$filePath));
  64.         }
  65.     }
  66. }