1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Yaro\Jarboe; |
4
|
|
|
|
5
|
|
|
use Illuminate\Foundation\Application; |
6
|
|
|
use Illuminate\Support\Arr; |
7
|
|
|
use Illuminate\Support\Facades\Blade; |
8
|
|
|
use Illuminate\Support\Facades\View; |
9
|
|
|
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider; |
10
|
|
|
use Yaro\Jarboe\Console\Commands\Install; |
11
|
|
|
use Yaro\Jarboe\Console\Commands\Make\Tool as MakeTool; |
12
|
|
|
use Yaro\Jarboe\Helpers\Locale; |
13
|
|
|
use Yaro\Jarboe\Helpers\System; |
14
|
|
|
use Yaro\Jarboe\Table\Repositories\EloquentModelRepository; |
15
|
|
|
use Yaro\Jarboe\Table\Repositories\ModelRepositoryInterface; |
16
|
|
|
use Yaro\Jarboe\ViewComponents\Breadcrumbs\Breadcrumbs; |
17
|
|
|
use Yaro\Jarboe\ViewComponents\Breadcrumbs\BreadcrumbsInterface; |
18
|
|
|
|
19
|
|
|
class ServiceProvider extends IlluminateServiceProvider |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* A list of artisan commands |
23
|
|
|
* |
24
|
|
|
* @var array |
25
|
|
|
*/ |
26
|
|
|
protected $commands = [ |
27
|
|
|
Install::class, |
28
|
|
|
MakeTool::class, |
29
|
|
|
]; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Bootstrap the application services. |
33
|
|
|
* |
34
|
|
|
* @return void |
35
|
|
|
*/ |
36
|
1134 |
|
public function boot() |
37
|
|
|
{ |
38
|
1134 |
|
$this->publishes([ |
39
|
1134 |
|
__DIR__.'/../config/admin_panel.php' => config_path('jarboe/admin_panel.php'), |
40
|
1134 |
|
__DIR__.'/../config/crud.php' => config_path('jarboe/crud.php'), |
41
|
1134 |
|
__DIR__.'/../config/locales.php' => config_path('jarboe/locales.php'), |
42
|
1134 |
|
__DIR__.'/../config/versionable.php' => config_path('jarboe/versionable.php'), |
43
|
1134 |
|
], 'config'); |
44
|
|
|
|
45
|
1134 |
|
if ($this->app->runningInConsole()) { |
46
|
1134 |
|
$this->commands($this->commands); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
//$this->loadMigrationsFrom(__DIR__.'/../database/migrations'); |
50
|
1134 |
|
$this->loadRoutesFrom(__DIR__.'/../routes/common.php'); |
51
|
1134 |
|
$this->loadRoutesFrom(__DIR__.'/../routes/auth.php'); |
52
|
1134 |
|
if (config('jarboe.admin_panel.default_routes_enabled')) { |
53
|
1134 |
|
$this->loadRoutesFrom(__DIR__.'/../routes/admins.php'); |
54
|
|
|
} |
55
|
1134 |
|
$this->loadViewsFrom(__DIR__.'/../resources/views', 'jarboe'); |
56
|
1134 |
|
$this->publishes([ |
57
|
1134 |
|
__DIR__.'/../resources/assets' => public_path('vendor/jarboe'), |
58
|
1134 |
|
], 'public'); |
59
|
|
|
|
60
|
1134 |
|
$this->loadTranslationsFrom(__DIR__ . '/../resources/lang', 'jarboe'); |
61
|
|
|
|
62
|
1134 |
|
$this->registerViewComposer(); |
63
|
1134 |
|
$this->registerBladeDirectives(); |
64
|
1134 |
|
$this->registerMiddlewareGroup(); |
65
|
1134 |
|
$this->registerBindings(); |
66
|
1134 |
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Register the application services. |
70
|
|
|
* |
71
|
|
|
* @return void |
72
|
|
|
*/ |
73
|
1134 |
|
public function register() |
74
|
|
|
{ |
75
|
1134 |
|
$this->mergeConfigFrom(__DIR__.'/../config/admin_panel.php', 'jarboe.admin_panel'); |
76
|
1134 |
|
$this->mergeConfigFrom(__DIR__.'/../config/crud.php', 'jarboe.crud'); |
77
|
1134 |
|
$this->mergeConfigFrom(__DIR__.'/../config/locales.php', 'jarboe.locales'); |
78
|
1134 |
|
$this->mergeConfigFrom(__DIR__.'/../config/versionable.php', 'jarboe.versionable'); |
79
|
|
|
|
80
|
|
|
$this->app->singleton('jarboe', function ($app) { |
81
|
1134 |
|
return new Jarboe(); |
82
|
1134 |
|
}); |
83
|
|
|
|
84
|
1134 |
|
$this->initFallbackRoute(); |
85
|
1134 |
|
} |
86
|
|
|
|
87
|
1134 |
|
private function registerBladeDirectives() |
88
|
|
|
{ |
89
|
|
|
Blade::directive('pushonce', function ($expression) { |
90
|
|
|
$params = collect(explode(',', $expression))->map(function ($item) { |
91
|
|
|
return trim($item); |
92
|
|
|
}); |
93
|
|
|
$stack = $params->shift(); |
94
|
|
|
$content = $params->implode(','); |
95
|
|
|
|
96
|
|
|
$isDisplayed = '__pushonce_'.md5($content); |
97
|
|
|
return "<?php if(!isset(\$__env->{$isDisplayed})): \$__env->{$isDisplayed} = true; \$__env->startPush({$stack}); ?>" |
98
|
|
|
. $content |
99
|
|
|
. '<?php $__env->stopPush(); endif; ?>'; |
100
|
1134 |
|
}); |
101
|
1134 |
|
} |
102
|
|
|
|
103
|
1134 |
|
private function registerMiddlewareGroup() |
104
|
|
|
{ |
105
|
1134 |
|
foreach ($this->app->config->get('jarboe.admin_panel.middleware_groups', []) as $group => $middlewares) { |
|
|
|
|
106
|
1134 |
|
$this->app->router->middlewareGroup($group, $middlewares); |
|
|
|
|
107
|
|
|
} |
108
|
1134 |
|
} |
109
|
|
|
|
110
|
1134 |
|
private function registerViewComposer() |
111
|
|
|
{ |
112
|
|
|
View::composer('jarboe::layouts.main', function ($view) { |
113
|
|
|
$themes = [ |
114
|
|
|
'brown' => 'smart-style-0', |
115
|
|
|
'dark' => 'smart-style-1', |
116
|
|
|
'light' => 'smart-style-2', |
117
|
|
|
'google-skin' => 'smart-style-3', |
118
|
|
|
'pixel-smash' => 'smart-style-4', |
119
|
|
|
'glass' => 'smart-style-5', |
120
|
|
|
'material' => 'smart-style-6', |
121
|
|
|
]; |
122
|
|
|
$selectedTheme = $this->app->config->get('jarboe.admin_panel.theme', 'light'); |
|
|
|
|
123
|
|
|
|
124
|
|
|
$view->themeClass = Arr::get($themes, $selectedTheme, $selectedTheme); |
125
|
|
|
$view->menuOnTop = $this->app->config->get('jarboe.admin_panel.menu_on_top'); |
|
|
|
|
126
|
|
|
|
127
|
|
|
$localeHelper = new Locale(); |
128
|
|
|
$currentLocale = $localeHelper->current(); |
129
|
|
|
if ($currentLocale == 'en' || $currentLocale == 'en-US') { |
130
|
|
|
$currentLocale = false; |
131
|
|
|
} |
132
|
|
|
$view->currentLocale = $currentLocale; |
133
|
1134 |
|
}); |
134
|
|
|
|
135
|
|
|
View::composer('jarboe::inc.locale_selector', function ($view) { |
136
|
|
|
$view->localeHelper = new Locale(); |
137
|
1134 |
|
}); |
138
|
|
|
|
139
|
|
|
View::composer('jarboe::inc.footer', function ($view) { |
140
|
|
|
$view->jarboeVersion = Jarboe::VERSION; |
141
|
|
|
$view->laravelVersion = Application::VERSION; |
142
|
|
|
$view->system = new System(); |
143
|
1134 |
|
}); |
144
|
1134 |
|
} |
145
|
|
|
|
146
|
1134 |
|
private function initFallbackRoute() |
147
|
|
|
{ |
148
|
|
|
$this->app->booted(function () { |
149
|
1134 |
|
$router = $this->app->router; |
|
|
|
|
150
|
|
|
$router->group(app('jarboe')->routeGroupOptions(), function () use ($router) { |
151
|
1134 |
|
$router->get('{any}', '\\Yaro\\Jarboe\\Http\\Controllers\\CommonController@notFoundPage')->where('any', '.*'); |
152
|
1134 |
|
}); |
153
|
1134 |
|
}); |
154
|
1134 |
|
} |
155
|
|
|
|
156
|
1134 |
|
private function registerBindings() |
157
|
|
|
{ |
158
|
|
|
$this->app->bind(BreadcrumbsInterface::class, function ($app) { |
159
|
79 |
|
return new Breadcrumbs(); |
160
|
1134 |
|
}); |
161
|
|
|
$this->app->bind(ModelRepositoryInterface::class, function ($app) { |
162
|
115 |
|
return new EloquentModelRepository(); |
163
|
1134 |
|
}); |
164
|
1134 |
|
} |
165
|
|
|
} |
166
|
|
|
|
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: