Passed
Push — master ( a23672...3dee81 )
by Iman
08:02
created

src/WidgetsServiceProvider.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace Imanghafoori\Widgets;
4
5
use Illuminate\Support\Facades\Blade;
6
use Illuminate\Support\ServiceProvider;
7
use DebugBar\DataCollector\MessagesCollector;
0 ignored issues
show
The type DebugBar\DataCollector\MessagesCollector was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
9
class WidgetsServiceProvider extends ServiceProvider
10
{
11
    /**
12
     * Bootstrap any application services.
13
     *
14
     * @return void
15
     */
16
    public function boot()
17
    {
18
        $this->_registerDebugbar();
19
        $this->publishes([
20
            __DIR__.'/config/config.php' => config_path('widgetize.php'),
21
        ]);
22
23
        $this->defineDirectives();
24
        $this->loadViewsFrom($this->app->basePath().'/app/Widgets/', 'Widgets');
25
    }
26
27
    /**
28
     * | ------------------------------------------ |
29
     * |         Define Blade Directive             |
30
     * | ------------------------------------------ |
31
     * | When you call @ widget from your views     |
32
     * | The only thing that happens is that the    |
33
     * | `renderWidget` method Gets called on the   |
34
     * | `Utils\WidgetRenderer` class               |
35
     * | ------------------------------------------ |.
36
     */
37
    private function defineDirectives()
38
    {
39
        $omitParenthesis = version_compare($this->app->version(), '5.3', '<');
40
41
        Blade::directive('widget', function ($expression) use ($omitParenthesis) {
42
            $expression = $omitParenthesis ? $expression : "($expression)";
43
44
            return "<?php echo app(\\Imanghafoori\\Widgets\\Utils\\WidgetRenderer::class)->renderWidget{$expression}; ?>";
45
        });
46
    }
47
48
    /**
49
     * Register any application services.
50
     *
51
     * @return void
52
     */
53
    public function register()
54
    {
55
        $this->mergeConfigFrom(__DIR__.'/config/config.php', 'widgetize');
56
        $this->commands('command.imanghafoori.widget');
57
        app(RouteMacros::class)->registerMacros();
58
        app(SingletonServices::class)->registerSingletons($this->app);
59
    }
60
61
    private function _registerDebugbar()
62
    {
63
        if (! $this->app->offsetExists('debugbar')) {
64
            return;
65
        }
66
67
        $this->app->singleton('widgetize.debugger', function () {
68
            return new MessagesCollector('Widgets');
69
        });
70
71
        $this->app->make('debugbar')->addCollector(app('widgetize.debugger'));
72
    }
73
}
74