FIX: fix registering service providers in templates

This commit is contained in:
Michal Kváček
2017-08-26 22:34:40 +02:00
parent 6468c8f49c
commit c92ba41def
4 changed files with 26 additions and 48 deletions
-37
View File
@@ -1,37 +0,0 @@
<?php
namespace App\CMS\Helpers;
use App\CMS\Handlers\Contracts\AppHandler;
use App\Models\Content\Content;
use Webwizo\Shortcodes\Facades\Shortcode;
/**
* Class PageRenderer
*
* Simple class for rendering page for visitor
*
* @package App\CMS\Helpers
*/
class PageRenderer
{
/**
* Render page
*
* @param Content $page
*
* @return mixed
*/
public static function render(Content $page)
{
// do something template-specific
$parameters = call_user_func_array([CurrentTemplate::handler(), 'beforeRender'], [&$page]);
/**
* @var $handler AppHandler
*/
$handler = new $page->moduleHandler;
// render page
return $handler->render($page, $parameters);
}
}
@@ -16,7 +16,7 @@ class ModuleManager extends ServiceProvider
{ {
// this service provider needs published config - config is merged right after this service provider // this service provider needs published config - config is merged right after this service provider
try { try {
$modules = app(ModuleRepository::class)->getOnlyModules(); $modules = app(ModuleRepository::class)->all();
} catch (QueryException $e) { } catch (QueryException $e) {
return; return;
} }
@@ -32,7 +32,13 @@ class ModuleManager extends ServiceProvider
// include files (if any) // include files (if any)
if (isset($module->module_settings['files']) && !empty($module->module_settings['files'])) { if (isset($module->module_settings['files']) && !empty($module->module_settings['files'])) {
foreach ($module->module_settings['files'] as $file) { foreach ($module->module_settings['files'] as $file) {
include config('modules.paths.modules') . '/' . $module->static_name . '/' . $file; $path = config('modules.paths.modules') . '/' . $module->static_name . '/' . $file;
if (!file_exists($path)) {
$path = base_path($file);
}
@include_once $path;
} }
} }
} }
+17 -3
View File
@@ -14,7 +14,6 @@ class Controller extends BaseController
/** /**
* Custom wrapper for generating view. * Custom wrapper for generating view.
*
* This method will be used for switching among templates. * This method will be used for switching among templates.
* *
* @param $template * @param $template
@@ -25,8 +24,23 @@ class Controller extends BaseController
*/ */
public static function visitorsView($template, $data = [], $mergeData = []) public static function visitorsView($template, $data = [], $mergeData = [])
{ {
$view = Template::name($template); $view = self::getView($template, $data, $mergeData);
return response(view($view, $data, $mergeData))->header('X-Powered-By', strrev('zc.ytiranib.www//:sptth | .o.r.s ytiranib | SMCiniM')); return response($view)->header('X-Powered-By', strrev('zc.ytiranib.www//:sptth | .o.r.s ytiranib | SMCiniM'));
}
/**
* Get instance of view for passing into response
*
* @param $template
* @param $data
* @param $mergeData
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public static function getView($template, $data = [], $mergeData = [])
{
$view = Template::name($template);
return view($view, $data, $mergeData);
} }
} }
+1 -6
View File
@@ -27,12 +27,7 @@ class TemplateServiceProvider extends ServiceProvider
return; return;
} }
// include files // service providers and files already registered in ModuleManager
$files = isset($template->moduleSettings->files) ? $template->moduleSettings->files : [];
foreach ($files as $file) {
include_once $file;
}
// register templates // register templates
$publicTemplates = CurrentTemplate::getPublicTemplatePaths(); $publicTemplates = CurrentTemplate::getPublicTemplatePaths();