1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Webwizo\Shortcodes; |
4
|
|
|
|
5
|
|
|
use Webwizo\Shortcodes\View\Factory; |
6
|
|
|
use Illuminate\Support\ServiceProvider; |
7
|
|
|
use Webwizo\Shortcodes\Compilers\ShortcodeCompiler; |
8
|
|
|
|
9
|
|
|
class ShortcodesServiceProvider extends ServiceProvider |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Perform post-registration booting of services. |
13
|
|
|
* |
14
|
|
|
* @return void |
15
|
|
|
*/ |
16
|
|
|
public function boot() |
17
|
|
|
{ |
18
|
|
|
$this->enableCompiler(); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Enable the compiler. |
23
|
|
|
*/ |
24
|
|
|
public function enableCompiler() |
25
|
|
|
{ |
26
|
|
|
// Check if the compiler is auto enabled |
27
|
|
|
$state = $this->app['config']->get('laravel-shortcodes::enabled', false); |
28
|
|
|
|
29
|
|
|
// Enable when needed |
30
|
|
|
if ($state) { |
31
|
|
|
$this->app['shortcode.compiler']->enable(); |
32
|
|
|
} |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Register the service provider. |
37
|
|
|
* |
38
|
|
|
* @return void |
39
|
|
|
*/ |
40
|
|
|
public function register() |
41
|
|
|
{ |
42
|
|
|
$this->registerShortcodeCompiler(); |
43
|
|
|
$this->registerShortcode(); |
44
|
|
|
$this->registerView(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Register short code compiler. |
49
|
|
|
*/ |
50
|
|
|
public function registerShortcodeCompiler() |
51
|
|
|
{ |
52
|
|
|
$this->app->singleton('shortcode.compiler', function ($app) { |
|
|
|
|
53
|
|
|
return new ShortcodeCompiler(); |
54
|
|
|
}); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Register the shortcode. |
59
|
|
|
*/ |
60
|
|
|
public function registerShortcode() |
61
|
|
|
{ |
62
|
|
|
$this->app->singleton('shortcode', function ($app) { |
63
|
|
|
return new Shortcode($app['shortcode.compiler']); |
64
|
|
|
}); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Register Laravel view. |
69
|
|
|
*/ |
70
|
|
|
public function registerView() |
71
|
|
|
{ |
72
|
|
|
$finder = $this->app['view']->getFinder(); |
73
|
|
|
|
74
|
|
|
$this->app->singleton('view', function ($app) use ($finder) { |
75
|
|
|
// Next we need to grab the engine resolver instance that will be used by the |
76
|
|
|
// environment. The resolver will be used by an environment to get each of |
77
|
|
|
// the various engine implementations such as plain PHP or Blade engine. |
78
|
|
|
$resolver = $app['view.engine.resolver']; |
79
|
|
|
$env = new Factory($resolver, $finder, $app['events'], $app['shortcode.compiler']); |
80
|
|
|
|
81
|
|
|
// We will also set the container instance on this view environment since the |
82
|
|
|
// view composers may be classes registered in the container, which allows |
83
|
|
|
// for great testable, flexible composers for the application developer. |
84
|
|
|
$env->setContainer($app); |
85
|
|
|
$env->share('app', $app); |
86
|
|
|
|
87
|
|
|
return $env; |
88
|
|
|
}); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Get the services provided by the provider. |
93
|
|
|
* |
94
|
|
|
* @return array |
95
|
|
|
*/ |
96
|
|
|
public function provides() |
97
|
|
|
{ |
98
|
|
|
return [ |
99
|
|
|
'shortcode', |
100
|
|
|
'shortcode.compiler', |
101
|
|
|
'view' |
102
|
|
|
]; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.