REFACTORING #1880 @4h30m: another ugly refactoring commit

This commit is contained in:
Michal Kváček
2016-10-25 16:50:04 +02:00
parent 28f67ffe3c
commit cc999dd24e
71 changed files with 827 additions and 608 deletions
+72 -7
View File
@@ -1,12 +1,13 @@
<?php
namespace App\CMS\Helpers;
use App\CMS\Contracts\Modules\TemplateHandler;
use App\Models\Content\Content;
use App\Models\Module;
use DebugBar\Bridge\MonologCollector;
use App\Models\User;
use Illuminate\Database\QueryException;
use Monolog\Logger;
class CurrentTemplate
class CurrentTemplate implements TemplateHandler
{
protected static $template;
protected static $initialized = false;
@@ -20,14 +21,14 @@ class CurrentTemplate
{
if (!self::$initialized) {
try {
self::$template = Module::where('is_template', true)
->where('enabled', true)
->first();
self::$template = Module::where('is_template', true)
->where('enabled', true)
->first();
} catch (QueryException $e) {
throw new \ErrorException('DB not migrated, please, do so!');
}
if (self::$template) {
self::$template->module_settings = json_decode(self::$template->module_settings);
self::$template->moduleSettings = json_decode(self::$template->moduleSettings);
}
self::$initialized = true;
@@ -60,4 +61,68 @@ class CurrentTemplate
{
self::$initialized = false;
}
/**
* Register admin menu (or multiple ones)
*
* This cannot be in ServiceProvider because Session is started at middleware. And ServiceProvider is called before
* starting any middleware..
*
* @param User $user model of logged user
*/
public static function registerAdminMenu(User $user)
{
call_user_func_array([self::handler(), 'registerAdminMenu'], [$user]);
}
/**
* Get list of registered templates and supported modules.
*
* Returned array is expected to be array of arrays with following items: module, namespace and templateName.
* Example:
* return [
* ['module' => 'Article', 'templateName' => 'article::template.name']
* ];
*
* When no "namespace" is specified, value strtolower(module) is used instaed.
*
* @return array
*/
public static function getPublicTemplatePaths()
{
return call_user_func([self::handler(), 'getPublicTemplatePaths']);
}
/**
* Prepare Content object to be rendered using Blade template
*
* @param Content $content
*/
public static function beforeRender(Content & $content)
{
call_user_func_array([self::handler(), 'beforeRender'], [&$content]);
}
/**
* Modify input data into format which can be understood by edit template
*
* @param Content $content
*/
public static function beforePopulatingEditForm(Content & $content)
{
call_user_func_array([self::handler(), 'beforePopulatingEditForm'], [&$content]);
}
/**
* Slightly modify Content object before saving into database.
*
* This way we can do almost whatever we want - even in template
*
* @param Content $content
* @param $request
*/
public static function beforeSave(Content & $content, $request)
{
call_user_func_array([self::handler(), 'beforeSave'], [&$content, $request]);
}
}