|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Schnoop\RemoteTemplate; |
|
4
|
|
|
|
|
5
|
|
|
use GuzzleHttp\Client; |
|
6
|
|
|
use Illuminate\Contracts\Events\Dispatcher; |
|
7
|
|
|
use Illuminate\View\Engines\EngineResolver; |
|
8
|
|
|
use Illuminate\View\ViewFinderInterface; |
|
9
|
|
|
use Illuminate\View\ViewServiceProvider; |
|
10
|
|
|
use Schnoop\RemoteTemplate\View\Factory; |
|
11
|
|
|
use Schnoop\RemoteTemplate\View\FileViewFinder; |
|
12
|
|
|
use Schnoop\RemoteTemplate\View\RemoteTemplateFinder; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class RemoteTemplateServiceProvider. |
|
16
|
|
|
*/ |
|
17
|
|
|
class RemoteTemplateServiceProvider extends ViewServiceProvider |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* Bootstrap the application services. |
|
21
|
|
|
*/ |
|
22
|
|
|
public function boot() |
|
23
|
|
|
{ |
|
24
|
|
|
if ($this->app->runningInConsole()) { |
|
25
|
|
|
$this->publishes([ |
|
26
|
|
|
__DIR__.'/../config/remote-view.php' => config_path('remote-view.php'), |
|
27
|
|
|
], 'config'); |
|
28
|
|
|
} |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Register the service provider. |
|
33
|
|
|
* |
|
34
|
|
|
* @return void |
|
35
|
|
|
*/ |
|
36
|
|
|
public function register() |
|
37
|
|
|
{ |
|
38
|
|
|
$this->registerViewFinder(); |
|
39
|
|
|
|
|
40
|
|
|
$this->registerFactory(); |
|
41
|
|
|
|
|
42
|
|
|
$this->registerBladeCompiler(); |
|
43
|
|
|
|
|
44
|
|
|
$this->registerEngineResolver(); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Register the view finder implementation. |
|
49
|
|
|
* |
|
50
|
|
|
* @return void |
|
51
|
|
|
*/ |
|
52
|
|
|
public function registerViewFinder() |
|
53
|
|
|
{ |
|
54
|
|
|
$this->mergeConfigFrom(__DIR__.'/../config/remote-view.php', 'remote-view'); |
|
55
|
|
|
|
|
56
|
|
|
$this->app->singleton('remoteview.finder', function ($app) { |
|
57
|
|
|
return new RemoteTemplateFinder( |
|
58
|
|
|
$app['files'], |
|
59
|
|
|
$app['config'], |
|
60
|
|
|
new Client($app['config']['remote-view.guzzle-config']) |
|
61
|
|
|
); |
|
62
|
|
|
}); |
|
63
|
|
|
|
|
64
|
|
|
$this->app->bind('view.finder', function ($app) { |
|
65
|
|
|
return new FileViewFinder( |
|
66
|
|
|
$app['files'], |
|
67
|
|
|
$app['config']['view.paths'], |
|
68
|
|
|
$app['remoteview.finder'], |
|
69
|
|
|
null |
|
70
|
|
|
); |
|
71
|
|
|
}); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Create a new Factory Instance. |
|
76
|
|
|
* |
|
77
|
|
|
* @param EngineResolver $resolver |
|
78
|
|
|
* @param ViewFinderInterface $finder |
|
79
|
|
|
* @param Dispatcher $events |
|
80
|
|
|
* |
|
81
|
|
|
* @return Factory |
|
82
|
|
|
*/ |
|
83
|
|
|
protected function createFactory($resolver, $finder, $events): Factory |
|
84
|
|
|
{ |
|
85
|
|
|
return new Factory($resolver, $finder, $events); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|