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. if (!defined($constKey))
  28. {
  29. $value = $this->container->getParameterBag()->resolveValue($v);
  30. // All K_ constants are required
  31. if (preg_match("/^k_/i", $k))
  32. {
  33. if (($k === 'k_path_cache' || $k === 'k_path_url_cache') && !is_dir($value)) {
  34. $this->createDir($value);
  35. }
  36. if(in_array($constKey, ['K_PATH_URL','K_PATH_MAIN','K_PATH_FONTS','K_PATH_CACHE','K_PATH_URL_CACHE','K_PATH_IMAGES'])) {
  37. $value .= (substr($value, -1) == '/' ? '' : '/');
  38. }
  39. }
  40. define($constKey, $value);
  41. }
  42. }
  43. }
  44. }
  45. /**
  46. * Create a directory
  47. *
  48. * @param string $filePath
  49. *
  50. * @throws \RuntimeException
  51. */
  52. private function createDir($filePath)
  53. {
  54. $filesystem = new Filesystem();
  55. if (false === $filesystem->mkdir($filePath)) {
  56. throw new \RuntimeException(sprintf(
  57. 'Could not create directory %s', $filePath
  58. ));
  59. }
  60. }
  61. }