1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Spatie\Export; |
4
|
|
|
|
5
|
|
|
use Illuminate\Contracts\Filesystem\Filesystem; |
6
|
|
|
use Illuminate\Support\Facades\Storage; |
7
|
|
|
use Illuminate\Support\ServiceProvider; |
8
|
|
|
use Spatie\Export\Console\ExportCommand; |
9
|
|
|
use Spatie\Export\Destinations\FilesystemDestination; |
10
|
|
|
|
11
|
|
|
class ExportServiceProvider extends ServiceProvider |
12
|
|
|
{ |
13
|
|
|
public function register(): void |
14
|
|
|
{ |
15
|
|
|
$this->mergeConfigFrom(__DIR__.'/../config/export.php', 'export'); |
16
|
|
|
|
17
|
|
|
$this->app->singleton(Destination::class, function () { |
18
|
|
|
return new FilesystemDestination($this->getDisk()); |
19
|
|
|
}); |
20
|
|
|
|
21
|
|
|
$this->app->singleton(Exporter::class); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function boot(): void |
25
|
|
|
{ |
26
|
|
|
if ($this->app->runningInConsole()) { |
27
|
|
|
$this->publishes([ |
28
|
|
|
__DIR__.'/../config/export.php' => config_path('export.php'), |
29
|
|
|
], 'config'); |
30
|
|
|
|
31
|
|
|
$this->commands([ |
32
|
|
|
ExportCommand::class, |
33
|
|
|
]); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
$this->app->make(Exporter::class) |
37
|
|
|
->cleanBeforeExport(config('export.clean_before_export', false)) |
38
|
|
|
->crawl(config('export.crawl', false)) |
39
|
|
|
->paths(config('export.paths', [])) |
40
|
|
|
->includeFiles(config('export.include_files', [])) |
41
|
|
|
->excludeFilePatterns(config('export.exclude_file_patterns', [])); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
protected function getDisk(): Filesystem |
45
|
|
|
{ |
46
|
|
|
if (! config('export.disk')) { |
47
|
|
|
config([ |
48
|
|
|
'filesystems.disks.laravel_export' => [ |
49
|
|
|
'driver' => 'local', |
50
|
|
|
'root' => base_path('dist'), |
51
|
|
|
], |
52
|
|
|
]); |
53
|
|
|
|
54
|
|
|
return Storage::disk('laravel_export'); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
return Storage::disk(config('export.disk')); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|