Skip to content

Commit f4bc772

Browse files
add lumen support
1 parent 6acded2 commit f4bc772

File tree

3 files changed

+48
-13
lines changed

3 files changed

+48
-13
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/vendor
22
composer.phar
33
composer.lock
4-
.DS_Store
4+
.DS_Store
5+
/.idea

readme.md

+20
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ Require this package in your composer.json and update composer. This will downlo
66

77
"barryvdh/laravel-dompdf": "0.6.*"
88

9+
## Installation
10+
11+
### Laravel 5.x:
12+
913
After updating composer, add the ServiceProvider to the providers array in config/app.php
1014

1115
'Barryvdh\DomPDF\ServiceProvider',
@@ -14,6 +18,22 @@ You can optionally use the facade for shorter code. Add this to your facades:
1418

1519
'PDF' => 'Barryvdh\DomPDF\Facade',
1620

21+
### Lumen:
22+
23+
After updating composer add the following lines to register provider in `bootstrap/app.php`
24+
25+
```
26+
$app->register(\Barryvdh\DomPDF\ServiceProvider::class);
27+
```
28+
29+
To change the configuration, copy the config file to your config folder and enable it in `bootstrap/app.php`:
30+
31+
```
32+
$app->configure('dompdf');
33+
```
34+
35+
## Using
36+
1737
You can create a new DOMPDF instance and load a HTML string, file or view name. You can save it to a file, or stream (show in browser) or download.
1838

1939
$pdf = App::make('dompdf.wrapper');

src/ServiceProvider.php

+26-12
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
use Exception;
55
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider;
66

7-
class ServiceProvider extends IlluminateServiceProvider {
7+
class ServiceProvider extends IlluminateServiceProvider
8+
{
89

910
/**
1011
* Indicates if loading of the provider is deferred.
@@ -21,12 +22,13 @@ class ServiceProvider extends IlluminateServiceProvider {
2122
*/
2223
public function register()
2324
{
24-
$configPath = __DIR__ . '/../config/dompdf.php';
25+
$configPath = __DIR__.'/../config/dompdf.php';
2526
$this->mergeConfigFrom($configPath, 'dompdf');
2627

2728
$this->app->bind('dompdf', function ($app) {
2829
$dompdf = new \DOMPDF();
29-
$dompdf->set_base_path(realpath($app['path.public']));
30+
$dompdf->set_base_path(realpath(base_path('public')));
31+
3032
return $dompdf;
3133
});
3234
$this->app->alias('dompdf', 'DOMPDF');
@@ -37,11 +39,23 @@ public function register()
3739

3840
}
3941

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+
4052
public function boot()
4153
{
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+
4559
$defines = $this->app['config']->get('dompdf.defines') ?: array();
4660
foreach ($defines as $key => $value) {
4761
$this->define($key, $value);
@@ -50,12 +64,12 @@ public function boot()
5064
//Still load these values, in case config is not used.
5165
$this->define("DOMPDF_ENABLE_REMOTE", true);
5266
$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'));
5569

5670
$config_file = $this->app['config']->get(
5771
'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');
5973

6074
if (file_exists($config_file)) {
6175
require_once $config_file;
@@ -75,16 +89,16 @@ public function provides()
7589
{
7690
return array('dompdf', 'dompdf.wrapper');
7791
}
78-
92+
7993
/**
8094
* Define a value, if not already defined
81-
*
95+
*
8296
* @param string $name
8397
* @param string $value
8498
*/
8599
protected function define($name, $value)
86100
{
87-
if (!defined($name)) {
101+
if (! defined($name)) {
88102
define($name, $value);
89103
}
90104
}

0 commit comments

Comments
 (0)