mirror of
https://github.com/Bigherollc/wticreatorstudio.git
synced 2026-10-11 21:13:03 -04:00
130 lines
3.4 KiB
PHP
130 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace Modules\LaraBuilder\Providers;
|
|
|
|
use Illuminate\Support\Facades\Blade;
|
|
use Illuminate\Support\ServiceProvider;
|
|
use Illuminate\Support\Str;
|
|
|
|
class LaraBuilderServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* @var string
|
|
*/
|
|
protected $moduleName = 'LaraBuilder';
|
|
|
|
/**
|
|
* @var string
|
|
*/
|
|
protected $moduleNameLower = 'larabuilder';
|
|
|
|
/**
|
|
* Boot the application events.
|
|
*/
|
|
public function boot(): void
|
|
{
|
|
$this->registerTranslations();
|
|
$this->registerConfig();
|
|
$this->registerViews();
|
|
$this->registerBladeDirectives();
|
|
$this->loadMigrationsFrom(module_path($this->moduleName, 'Database/Migrations'));
|
|
}
|
|
|
|
/**
|
|
* Register translations.
|
|
*/
|
|
public function registerTranslations(): void
|
|
{
|
|
$langPath = resource_path('lang/modules/'.$this->moduleNameLower);
|
|
|
|
if (is_dir($langPath)) {
|
|
$this->loadTranslationsFrom($langPath, $this->moduleNameLower);
|
|
$this->loadJsonTranslationsFrom($langPath);
|
|
} else {
|
|
$this->loadTranslationsFrom(module_path($this->moduleName, 'Resources/lang'), $this->moduleNameLower);
|
|
$this->loadJsonTranslationsFrom(module_path($this->moduleName, 'Resources/lang'));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Register config.
|
|
*/
|
|
protected function registerConfig(): void
|
|
{
|
|
$this->publishes([
|
|
module_path($this->moduleName, 'Config/config.php') => config_path($this->moduleNameLower.'.php'),
|
|
], 'config');
|
|
$this->mergeConfigFrom(
|
|
module_path($this->moduleName, 'Config/config.php'), $this->moduleNameLower
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Register views.
|
|
*/
|
|
public function registerViews(): void
|
|
{
|
|
$viewPath = resource_path('views/modules/'.$this->moduleNameLower);
|
|
|
|
$sourcePath = module_path($this->moduleName, 'Resources/views');
|
|
|
|
$this->publishes([
|
|
$sourcePath => $viewPath,
|
|
], ['views', $this->moduleNameLower.'-module-views']);
|
|
|
|
$this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower);
|
|
}
|
|
|
|
private function getPublishableViewPaths(): array
|
|
{
|
|
$paths = [];
|
|
foreach (\Config::get('view.paths') as $path) {
|
|
if (is_dir($path.'/modules/'.$this->moduleNameLower)) {
|
|
$paths[] = $path.'/modules/'.$this->moduleNameLower;
|
|
}
|
|
}
|
|
|
|
return $paths;
|
|
}
|
|
|
|
/**
|
|
* Register the service provider.
|
|
*/
|
|
public function register(): void
|
|
{
|
|
$this->app->register(RouteServiceProvider::class);
|
|
|
|
$this->app->bind('settings', function ($app) {
|
|
return new Settings();
|
|
});
|
|
|
|
$this->app->bind('page_settings', function () {
|
|
return new PageSettings;
|
|
});
|
|
|
|
$this->app->bind('revision', function () {
|
|
return new Revision;
|
|
});
|
|
|
|
require_once 'OptionBuilderHelpers.php';
|
|
require_once 'PageBuilderHelpers.php';
|
|
}
|
|
|
|
/**
|
|
* Get the services provided by the provider.
|
|
*/
|
|
public function provides(): array
|
|
{
|
|
return [];
|
|
}
|
|
|
|
protected function registerBladeDirectives()
|
|
{
|
|
Blade::directive('style', function ($expression) {
|
|
$expression = is_null($expression) ? '[]' : $expression;
|
|
|
|
return "style=\"<?php echo \Modules\LaraBuilder\Support\Arr::toCssStyles({$expression}) ?>\"";
|
|
});
|
|
}
|
|
}
|