4
4
use Exception ;
5
5
use Illuminate \Support \ServiceProvider as IlluminateServiceProvider ;
6
6
7
- class ServiceProvider extends IlluminateServiceProvider {
7
+ class ServiceProvider extends IlluminateServiceProvider
8
+ {
8
9
9
10
/**
10
11
* Indicates if loading of the provider is deferred.
@@ -21,12 +22,13 @@ class ServiceProvider extends IlluminateServiceProvider {
21
22
*/
22
23
public function register ()
23
24
{
24
- $ configPath = __DIR__ . '/../config/dompdf.php ' ;
25
+ $ configPath = __DIR__ . '/../config/dompdf.php ' ;
25
26
$ this ->mergeConfigFrom ($ configPath , 'dompdf ' );
26
27
27
28
$ this ->app ->bind ('dompdf ' , function ($ app ) {
28
29
$ dompdf = new \DOMPDF ();
29
- $ dompdf ->set_base_path (realpath ($ app ['path.public ' ]));
30
+ $ dompdf ->set_base_path (realpath (base_path ('public ' )));
31
+
30
32
return $ dompdf ;
31
33
});
32
34
$ this ->app ->alias ('dompdf ' , 'DOMPDF ' );
@@ -37,11 +39,23 @@ public function register()
37
39
38
40
}
39
41
42
+ /**
43
+ * Check if package is running under Lumen app
44
+ *
45
+ * @return bool
46
+ */
47
+ protected function isLumen ()
48
+ {
49
+ return str_contains ($ this ->app ->version (), 'Lumen ' ) === true ;
50
+ }
51
+
40
52
public function boot ()
41
53
{
42
- $ configPath = __DIR__ . '/../config/dompdf.php ' ;
43
- $ this ->publishes ([$ configPath => config_path ('dompdf.php ' )], 'config ' );
44
-
54
+ if (! $ this ->isLumen ()) {
55
+ $ configPath = __DIR__ .'/../config/dompdf.php ' ;
56
+ $ this ->publishes ([$ configPath => config_path ('dompdf.php ' )], 'config ' );
57
+ }
58
+
45
59
$ defines = $ this ->app ['config ' ]->get ('dompdf.defines ' ) ?: array ();
46
60
foreach ($ defines as $ key => $ value ) {
47
61
$ this ->define ($ key , $ value );
@@ -50,12 +64,12 @@ public function boot()
50
64
//Still load these values, in case config is not used.
51
65
$ this ->define ("DOMPDF_ENABLE_REMOTE " , true );
52
66
$ this ->define ("DOMPDF_ENABLE_AUTOLOAD " , false );
53
- $ this ->define ("DOMPDF_CHROOT " , $ this -> app [ ' path.base ' ] );
54
- $ this ->define ("DOMPDF_LOG_OUTPUT_FILE " , $ this -> app [ ' path.storage ' ] . ' / logs/dompdf.html ' );
67
+ $ this ->define ("DOMPDF_CHROOT " , realpath ( base_path ()) );
68
+ $ this ->define ("DOMPDF_LOG_OUTPUT_FILE " , storage_path ( ' logs/dompdf.html ') );
55
69
56
70
$ config_file = $ this ->app ['config ' ]->get (
57
71
'dompdf.config_file '
58
- ) ?: $ this -> app [ ' path.base ' ] . ' / vendor/dompdf/dompdf/dompdf_config.inc.php ' ;
72
+ ) ?: base_path ( ' vendor/dompdf/dompdf/dompdf_config.inc.php ') ;
59
73
60
74
if (file_exists ($ config_file )) {
61
75
require_once $ config_file ;
@@ -75,16 +89,16 @@ public function provides()
75
89
{
76
90
return array ('dompdf ' , 'dompdf.wrapper ' );
77
91
}
78
-
92
+
79
93
/**
80
94
* Define a value, if not already defined
81
- *
95
+ *
82
96
* @param string $name
83
97
* @param string $value
84
98
*/
85
99
protected function define ($ name , $ value )
86
100
{
87
- if (!defined ($ name )) {
101
+ if (! defined ($ name )) {
88
102
define ($ name , $ value );
89
103
}
90
104
}
0 commit comments