Ei kuvausta

ServiceProvider.php 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace Barryvdh\DomPDF;
  3. use Exception;
  4. use Illuminate\Support\ServiceProvider as IlluminateServiceProvider;
  5. class ServiceProvider extends IlluminateServiceProvider {
  6. /**
  7. * Indicates if loading of the provider is deferred.
  8. *
  9. * @var bool
  10. */
  11. protected $defer = true;
  12. /**
  13. * Register the service provider.
  14. *
  15. * @throws \Exception
  16. * @return void
  17. */
  18. public function register()
  19. {
  20. $this->app['config']->package('barryvdh/laravel-dompdf', __DIR__ . '/config');
  21. $defines = $this->app['config']->get('laravel-dompdf::defines') ?: array();
  22. foreach ($defines as $key => $value) {
  23. $this->define($key, $value);
  24. }
  25. //Still load these values, in case config is not used.
  26. $this->define("DOMPDF_ENABLE_REMOTE", true);
  27. $this->define("DOMPDF_ENABLE_AUTOLOAD", false);
  28. $this->define("DOMPDF_CHROOT", $this->app['path.base']);
  29. $this->define("DOMPDF_LOG_OUTPUT_FILE", $this->app['path.storage'] . '/logs/dompdf.html');
  30. $config_file = $this->app['config']->get(
  31. 'laravel-dompdf::config_file'
  32. ) ?: $this->app['path.base'] . '/vendor/dompdf/dompdf/dompdf_config.inc.php';
  33. if (file_exists($config_file)) {
  34. require_once $config_file;
  35. } else {
  36. throw new Exception(
  37. "$config_file cannot be loaded, please configure correct config file (config.php: config_file)"
  38. );
  39. }
  40. $this->app->bind('dompdf', function ($app) {
  41. return new PDF($app['config'], $app['files'], $app['view'], $app['path.public']);
  42. });
  43. }
  44. /**
  45. * Get the services provided by the provider.
  46. *
  47. * @return array
  48. */
  49. public function provides()
  50. {
  51. return array('dompdf');
  52. }
  53. /**
  54. * Define a value, if not already defined
  55. *
  56. * @param string $name
  57. * @param string $value
  58. */
  59. protected function define($name, $value)
  60. {
  61. if (!defined($name)) {
  62. define($name, $value);
  63. }
  64. }
  65. }