1 <?php
2
3 namespace Skimia\Assets\Scanner;
4
5 use Illuminate\Support\ServiceProvider;
6
7 class ScannerServiceProvider extends ServiceProvider
8 {
9 10 11 12 13
14 protected $scanWhenLocal = false;
15
16 17 18
19 public function register()
20 {
21 $this->registerScanner();
22 }
23
24 public function boot()
25 {
26 $this->loadScanned();
27 }
28
29 protected function getDirectories()
30 {
31 return $this->app['config']->get('assets.directories', []);
32 }
33
34 35 36 37 38
39 protected function scanDirectories()
40 {
41 $directories = $this->getDirectories();
42 if (empty($directories)) {
43 return;
44 }
45
46
47 $scanner = $this->getScanner();
48
49 $scanner->setDirectoriesToScan($directories);
50
51 $scanner->scan();
52 }
53
54 55 56 57 58
59 public function loadScanned()
60 {
61 if ($this->app->environment('local') && $this->app['config']->get('assets.generate_when_local', false)) {
62 $this->scanDirectories();
63 }
64
65 $scans = $this->getDirectories();
66
67 if (! empty($scans) && $this->getScanner()->isScanned()) {
68 $this->getScanner()->loadScanned();
69 }
70 }
71
72 protected function registerScanner()
73 {
74 $this->app->bindShared('skimia.assets.scanner', function ($app) {
75 $scanner = new Scanner($app, []);
76
77 return $scanner;
78 });
79 }
80
81 82 83
84 protected function getScanner()
85 {
86 return $this->app->make('skimia.assets.scanner');
87 }
88 }
89