165 lines
4.8 KiB
PHP
165 lines
4.8 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Handlers\Registrators\SearchEngineRegistrator;
|
|
use App\Handlers\Registrators\SettingsExtensionRegistrator;
|
|
use App\Handlers\Registrators\TemplateRegistrator;
|
|
use App\Handlers\Registrators\WidgetRegistrator;
|
|
use App\Handlers\Search\Content;
|
|
use App\Handlers\Search\Files;
|
|
use App\Handlers\Search\Presenters\AdminContent as AdminContentPresenter;
|
|
use App\Handlers\Search\Presenters\AdminFiles;
|
|
use App\Models\Template;
|
|
use App\Widgets\HtmlCode\HtmlCode;
|
|
use Illuminate\Support\Facades\App;
|
|
use Illuminate\Support\Facades\File;
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* Bootstrap any application services.
|
|
* @return void
|
|
*/
|
|
public function boot()
|
|
{
|
|
// ignore running from artisan
|
|
if (App::runningInConsole()) {
|
|
$this->publishViewResources();
|
|
|
|
return;
|
|
}
|
|
|
|
$this->registerWidgets();
|
|
$this->registerTemplates();
|
|
$this->registerSettings();
|
|
$this->registerSearch();
|
|
}
|
|
|
|
/**
|
|
* Register any application services.
|
|
* @return void
|
|
*/
|
|
public function register()
|
|
{
|
|
if ($this->app->environment() == 'local') {
|
|
$this->app->register('Iber\Generator\ModelGeneratorProvider');
|
|
$this->app->register('Barryvdh\Debugbar\ServiceProvider');
|
|
}
|
|
|
|
// register PingPong module extension
|
|
$this->app->register('Pingpong\Modules\ModulesServiceProvider');
|
|
$this->app->register('Pingpong\Menus\MenusServiceProvider');
|
|
|
|
// create singletons for registering widgets
|
|
$this->app->singleton('registerWidget', function ($app) {
|
|
return new WidgetRegistrator($app);
|
|
});
|
|
|
|
// create registrator for template directories
|
|
$this->app->singleton('registerTemplateDir', function ($app) {
|
|
return new TemplateRegistrator($app);
|
|
});
|
|
|
|
$this->app->singleton('registerSettingsExtension', function ($app) {
|
|
return new SettingsExtensionRegistrator($app);
|
|
});
|
|
|
|
$this->app->singleton('registerSearchEngine', function ($app) {
|
|
return new SearchEngineRegistrator($app);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Method for registering widgets.
|
|
*/
|
|
private function registerWidgets()
|
|
{
|
|
/**
|
|
* @var $registrator WidgetRegistrator
|
|
*/
|
|
$registrator = $this->app->make('registerWidget');
|
|
|
|
// register all available widgets
|
|
$registrator->register(HtmlCode::class);
|
|
}
|
|
|
|
/**
|
|
* Register path with editable contents
|
|
*/
|
|
private function registerTemplates()
|
|
{
|
|
/**
|
|
* @var $registrator TemplateRegistrator
|
|
*/
|
|
$registrator = $this->app->make('registerTemplateDir');
|
|
$registrator->setBaseDirectory('resources/views/visitor');
|
|
|
|
$registrator->register(config('app.theme'), 'admin/templates.core');
|
|
}
|
|
|
|
/**
|
|
* Register setting sections
|
|
*/
|
|
private function registerSettings()
|
|
{
|
|
$registrator = $this->app->make('registerSettingsExtension');
|
|
|
|
$registrator->register('basic', 'admin/settings.basic', 'admin.settings.parts.basic');
|
|
$registrator->register('meta', 'admin/settings.meta', 'admin.settings.parts.meta');
|
|
}
|
|
|
|
/**
|
|
* Register callbacks used for searching
|
|
*/
|
|
private function registerSearch()
|
|
{
|
|
$registrator = $this->app->make('registerSearchEngine');
|
|
|
|
$registrator->register(new Content(), new AdminContentPresenter());
|
|
$registrator->register(new Files(), new AdminFiles());
|
|
}
|
|
|
|
/**
|
|
* Publish all public assets from all themes
|
|
*/
|
|
private function publishViewResources()
|
|
{
|
|
$themes = File::directories(resource_path('views/visitor'));
|
|
|
|
$assets = [];
|
|
foreach ($themes as $theme) {
|
|
$themeName = basename($theme);
|
|
|
|
if (is_dir($theme . '/'.Template::ASSETS_DIRECTORY)) {
|
|
$assets[$theme . '/'.Template::ASSETS_DIRECTORY] = public_path('assets/' . $themeName);
|
|
}
|
|
|
|
if (is_dir($theme . '/'.Template::MODULES_DIRECTORY)) {
|
|
$this->publishModuleViews($theme . '/'.Template::MODULES_DIRECTORY, $themeName);
|
|
}
|
|
}
|
|
|
|
if (!empty($assets)) {
|
|
$this->publishes($assets, 'public-assets');
|
|
}
|
|
}
|
|
|
|
private function publishModuleViews($themeModules, $themeName)
|
|
{
|
|
$modules = File::directories($themeModules);
|
|
|
|
$moduleViews = [];
|
|
foreach ($modules as $module) {
|
|
$moduleName = strtolower(basename($module));
|
|
|
|
$moduleViews[$module] = resource_path('views/modules/' . $moduleName . '/visitor/' . $themeName);
|
|
}
|
|
|
|
if (!empty($moduleViews)) {
|
|
$this->publishes($moduleViews, 'module-views');
|
|
}
|
|
}
|
|
}
|