vendor/qipsius/tcpdf-bundle/QipsiusTCPDFBundle.php line 9

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