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