|
1
|
|
|
<?php namespace Arcanedev\Support\Providers; |
|
2
|
|
|
|
|
3
|
|
|
use Arcanedev\Support\ServiceProvider; |
|
4
|
|
|
use Illuminate\Contracts\View\Factory as ViewFactory; |
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* Class ViewComposerServiceProvider |
|
8
|
|
|
* |
|
9
|
|
|
* @package Arcanedev\Support\Providers |
|
10
|
|
|
* @author ARCANEDEV <[email protected]> |
|
11
|
|
|
*/ |
|
12
|
|
|
class ViewComposerServiceProvider extends ServiceProvider |
|
13
|
|
|
{ |
|
14
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
15
|
|
|
| Properties |
|
16
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
17
|
|
|
*/ |
|
18
|
|
|
/** |
|
19
|
|
|
* Register the composer classes. |
|
20
|
|
|
* |
|
21
|
|
|
* @var array |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $composerClasses = [ |
|
24
|
|
|
// 'view-name' => 'class' |
|
25
|
|
|
]; |
|
26
|
|
|
|
|
27
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
28
|
|
|
| Main Functions |
|
29
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
30
|
|
|
*/ |
|
31
|
|
|
/** |
|
32
|
|
|
* Boot the view composer service provider. |
|
33
|
|
|
*/ |
|
34
|
|
|
public function boot() |
|
35
|
|
|
{ |
|
36
|
|
|
$this->registerComposerClasses(); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Register the view composer classes. |
|
41
|
|
|
*/ |
|
42
|
|
|
protected function registerComposerClasses() |
|
43
|
|
|
{ |
|
44
|
|
|
foreach ($this->composerClasses as $view => $class) { |
|
45
|
|
|
$this->composer($view, $class); |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
50
|
|
|
| Other Functions |
|
51
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
52
|
|
|
*/ |
|
53
|
|
|
/** |
|
54
|
|
|
* Get the view factory instance. |
|
55
|
|
|
* |
|
56
|
|
|
* @return \Illuminate\Contracts\View\Factory |
|
57
|
|
|
*/ |
|
58
|
|
|
protected function view() |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->app->make(ViewFactory::class); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Register a view composer event. |
|
65
|
|
|
* |
|
66
|
|
|
* @param array|string $views |
|
67
|
|
|
* @param \Closure|string $callback |
|
68
|
|
|
* |
|
69
|
|
|
* @return array |
|
70
|
|
|
*/ |
|
71
|
|
|
public function composer($views, $callback) |
|
72
|
|
|
{ |
|
73
|
|
|
return $this->view()->composer($views, $callback); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|