vendor/whiteoctober/tcpdf-bundle/WhiteOctoberTCPDFBundle.php line 8

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