75 lines
2.2 KiB
PHP
75 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Handlers\Registrators\TemplateRegistrator;
|
|
use App\Models\Module;
|
|
use Illuminate\Support\Facades\App;
|
|
use Illuminate\Support\ServiceProvider;
|
|
use InvalidArgumentException;
|
|
|
|
class TemplateServiceProvider extends ServiceProvider
|
|
{
|
|
public function boot()
|
|
{
|
|
if (App::runningInConsole())
|
|
return;
|
|
|
|
parent::boot();
|
|
|
|
// select template
|
|
$template = Module::where('is_template', true)
|
|
->first();
|
|
|
|
if (!$template) {
|
|
throw new \ErrorException('Template is not set, cannot continue');
|
|
}
|
|
|
|
$templateSettings = json_decode($template->module_settings);
|
|
|
|
// include files
|
|
$files = isset($templateSettings->files) ? $templateSettings->files : [];
|
|
|
|
foreach ($files as $file) {
|
|
include_once app_path('../templates/' . $templateSettings->staticName . '/' . $file);
|
|
}
|
|
|
|
// register templates
|
|
$publicTemplates = call_user_func([$template->handler, 'getPublicTemplatePaths']);
|
|
|
|
if (!is_array($publicTemplates)) {
|
|
throw new \ErrorException($template->handler . '::getPublicTemplatePaths() must return array!');
|
|
}
|
|
|
|
if (empty($publicTemplates)) {
|
|
return;
|
|
}
|
|
|
|
/**
|
|
* @var $registrator TemplateRegistrator
|
|
*/
|
|
$registrator = $this->app->make('registerTemplateDir');
|
|
foreach ($publicTemplates as $template) {
|
|
// setup some global variables
|
|
// try {
|
|
// $registrator->setBaseDirectory('resources/views/modules/gallery/visitor');
|
|
// $registrator->setNamespace('gallery');
|
|
// $registrator->setModuleId(call_user_func([config('gallery.handler'), 'getModuleId']));
|
|
//
|
|
// // register path with current template name
|
|
// $registrator->register(config('app.theme'), 'gallery::admin/adminMenu.templatePath');
|
|
// } catch (InvalidArgumentException $e) {
|
|
// // ignore this exception
|
|
// }
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Register the service provider.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function register()
|
|
{
|
|
}
|
|
} |