FEATURE #1753: remove pingpong/modules and use custom solution
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace App\CMS\Handlers\Registrators;
|
namespace App\CMS\Handlers\Registrators;
|
||||||
|
|
||||||
use App\CMS\Enumerations\Exceptions\EnumerationExistsException;
|
use App\CMS\Exceptions\Enumerations\EnumerationExistsException;
|
||||||
use App\CMS\Handlers\Contracts\SearchHandler;
|
use App\CMS\Handlers\Contracts\SearchHandler;
|
||||||
use App\CMS\Handlers\Contracts\SearchPresenterHandler;
|
use App\CMS\Handlers\Contracts\SearchPresenterHandler;
|
||||||
use App\CMS\Handlers\Registrators\Items\SearchEngine;
|
use App\CMS\Handlers\Registrators\Items\SearchEngine;
|
||||||
|
|||||||
@@ -22,16 +22,9 @@ class CurrentTemplate implements TemplateHandler
|
|||||||
{
|
{
|
||||||
if (!self::$initialized) {
|
if (!self::$initialized) {
|
||||||
self::$template = Cache::rememberForever('current-template', function () {
|
self::$template = Cache::rememberForever('current-template', function () {
|
||||||
$template = Module::where('is_template', true)
|
return Module::where('is_template', true)
|
||||||
->where('enabled', true)
|
->where('enabled', true)
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
// todo remove after adding $casts into Module model
|
|
||||||
if ($template) {
|
|
||||||
$template->module_settings = json_decode($template->module_settings);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $template;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+4
-8
@@ -1,13 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace App\Providers;
|
|
||||||
|
|
||||||
use Illuminate\Support\ServiceProvider;
|
namespace App\CMS\Modules\ServiceProviders;
|
||||||
|
|
||||||
abstract class ModuleServiceProvider extends ServiceProvider
|
use Illuminate\Support\ServiceProvider as LaravelServiceProvider;
|
||||||
|
|
||||||
|
abstract class ServiceProvider extends LaravelServiceProvider
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Indicates if loading of the provider is deferred.
|
* Indicates if loading of the provider is deferred.
|
||||||
*
|
|
||||||
* @var bool
|
* @var bool
|
||||||
*/
|
*/
|
||||||
protected $defer = false;
|
protected $defer = false;
|
||||||
@@ -20,7 +20,6 @@ abstract class ModuleServiceProvider extends ServiceProvider
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Boot the application events.
|
* Boot the application events.
|
||||||
*
|
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function boot()
|
public function boot()
|
||||||
@@ -35,7 +34,6 @@ abstract class ModuleServiceProvider extends ServiceProvider
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Register config.
|
* Register config.
|
||||||
*
|
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function registerConfig()
|
protected function registerConfig()
|
||||||
@@ -50,7 +48,6 @@ abstract class ModuleServiceProvider extends ServiceProvider
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Register views.
|
* Register views.
|
||||||
*
|
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function registerViews()
|
protected function registerViews()
|
||||||
@@ -69,7 +66,6 @@ abstract class ModuleServiceProvider extends ServiceProvider
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Register translations.
|
* Register translations.
|
||||||
*
|
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function registerTranslations()
|
protected function registerTranslations()
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
'name' => '$Module$',
|
||||||
|
'translatedName' => '$module$::$module$.name',
|
||||||
|
'translatedDescription' => '$module$::$module$.description',
|
||||||
|
'alias' => 'categories',
|
||||||
|
'handler' => \Modules\$Module$\Handlers\$Module$Handler::class,
|
||||||
|
'providers' => [\Modules\$Module$\Providers\$Module$ServiceProvider::class],
|
||||||
|
'files' => ['Http/routes.php'],
|
||||||
|
'order' => 0,
|
||||||
|
];
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
namespace Modules\$ModuleNamespace$\Entities;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class $Entity$ extends Model {
|
||||||
|
// ...
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\$ModuleNamespace$\Handlers;
|
||||||
|
|
||||||
|
use App\CMS\Contracts\Content\ContentTitles;
|
||||||
|
use App\Models\Content\Content;
|
||||||
|
|
||||||
|
class $Module$ContentHandler extends $Module$Handler implements ContentTitles
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get translated title for pages overview of given type.
|
||||||
|
* This value is used for rendering list of all content pages of given type in administration.
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function getOverviewTitle()
|
||||||
|
{
|
||||||
|
// TODO: Implement getOverviewTitle() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Title displayed above for for creating new content page
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function getCreateNewTitle()
|
||||||
|
{
|
||||||
|
// TODO: Implement getCreateNewTitle() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Title for form displayed for editin content page
|
||||||
|
*
|
||||||
|
* @param Content $content
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public static function getEditTitle(Content $content)
|
||||||
|
{
|
||||||
|
// TODO: Implement getEditTitle() method.
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\$ModuleNamespace$\Handlers;
|
||||||
|
|
||||||
|
use App\CMS\Handlers\Handler;
|
||||||
|
use App\Models\User;
|
||||||
|
|
||||||
|
class $Module$Handler extends Handler
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Register admin menu
|
||||||
|
*
|
||||||
|
* @param User $user
|
||||||
|
*/
|
||||||
|
public static function registerAdminMenu(User $user)
|
||||||
|
{
|
||||||
|
// register links in admin menu
|
||||||
|
$menu = \Menu::instance('mainMenu');
|
||||||
|
|
||||||
|
$menu->dropdown(trans('$module$::$module$.name'), function ($submenu) use ($user) {
|
||||||
|
$submenu->route('$module$.overview', trans('$module$::$module$.overview'), [], 20, ['icon' => 'fa fa-fw fa-list']);
|
||||||
|
$submenu->route('$module$.new', trans('$module$::$module$.new'), [], 21, ['icon' => 'fa fa-fw fa-plus']);
|
||||||
|
}, 15, ['icon' => 'fa fa-fw']);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: add admin menu entries
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does this module support categories?
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public static function supportCategories()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\$ModuleNamespace$\Http\Controllers\Admin;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Admin\Controller;
|
||||||
|
use Modules\$ModuleNamespace$\Http\Requests\Update$Entity$;
|
||||||
|
use Modules\$ModuleNamespace$\Http\Requests\Create$Entity$;
|
||||||
|
use Modules\$ModuleNamespace$\Repositories\$Module$Repository;
|
||||||
|
use $EntityNamespace$\$Entity$ as $Entity$Entity;
|
||||||
|
|
||||||
|
class $Module$ extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var $Module$Repository
|
||||||
|
*/
|
||||||
|
private $$module$Repository;
|
||||||
|
|
||||||
|
public function __construct($Module$Repository $$module$Repository)
|
||||||
|
{
|
||||||
|
$this->$module$Repository = $$module$Repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||||
|
*/
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$items = $Entity$Entity::all();
|
||||||
|
|
||||||
|
return view('$module$::admin/index', compact('items'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display form for updating entity
|
||||||
|
*
|
||||||
|
* @param $Entity$Entity $entity
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||||
|
*/
|
||||||
|
public function edit($Entity$Entity $entity)
|
||||||
|
{
|
||||||
|
return view('$module$::admin/update', compact('entity'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update existing entity
|
||||||
|
*
|
||||||
|
* @param Update$Entity$ $request
|
||||||
|
* @param $Entity$Entity $item
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
|
*/
|
||||||
|
public function update(Update$Entity$ $request, $Entity$Entity $entity)
|
||||||
|
{
|
||||||
|
|
||||||
|
// ...
|
||||||
|
|
||||||
|
$this->$module$Repository->update($entity, $request->all());
|
||||||
|
|
||||||
|
return redirect()
|
||||||
|
->back()
|
||||||
|
->with('success', trans('$module$.$module.successfullyUpdated'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display form for creating new entity
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||||
|
*/
|
||||||
|
public function create() {
|
||||||
|
$entity = new $Entity$Entity();
|
||||||
|
|
||||||
|
return view('$module$::admin/create', compact('entity'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create new instance of entity
|
||||||
|
*/
|
||||||
|
public function store(Create$Entity$ $request) {
|
||||||
|
// ...
|
||||||
|
|
||||||
|
$this->$module$Repository->create($request->all());
|
||||||
|
|
||||||
|
return redirect()
|
||||||
|
->back()
|
||||||
|
->with('success', trans('$module$.$module.successfullyUpdated'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete entity
|
||||||
|
*
|
||||||
|
* @param $Entity$ $entity
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
|
*/
|
||||||
|
public function destroy($Entity$ $entity) {
|
||||||
|
$entity->delete();
|
||||||
|
|
||||||
|
return redirect()
|
||||||
|
->back()
|
||||||
|
->with('success', trans('$module$.$module.successfullyDeleted'));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
namespace Modules\$ModuleNamespace$\Http\Requests;
|
||||||
|
|
||||||
|
use App\Http\Requests\Request;
|
||||||
|
|
||||||
|
class Create$Entity$ extends Request {
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return parent::rules();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
namespace Modules\$ModuleNamespace$\Http\Requests;
|
||||||
|
|
||||||
|
use App\Http\Requests\Request;
|
||||||
|
|
||||||
|
class Update$Entity$ extends Request {
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return parent::rules();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
\Route::group([
|
||||||
|
'prefix' => \LaravelLocalization::setLocale() . '/admin/$module$',
|
||||||
|
'middleware' => ['admin'],
|
||||||
|
'namespace' => 'Modules\$Module$\Http\Controllers\Admin'
|
||||||
|
], function () {
|
||||||
|
Route::get('/', '$Module$@index')
|
||||||
|
->name('$module$.overview');
|
||||||
|
|
||||||
|
Route::get('/new', '$Module$@create')
|
||||||
|
->name('$module$.new');
|
||||||
|
|
||||||
|
Route::post('/new', '$Module$@store')
|
||||||
|
->name('$module$.postNew');
|
||||||
|
|
||||||
|
Route::get('/edit/{id}', '$Module$@edit')
|
||||||
|
->name('$module$.edit');
|
||||||
|
|
||||||
|
Route::post('/edit/{id}', '$Module$@update')
|
||||||
|
->name('$module$.postEdit');
|
||||||
|
|
||||||
|
Route::get('/delete/{id}', '$Module$@delete')
|
||||||
|
->name('$module$.delete');
|
||||||
|
});
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\$Module$\Providers;
|
||||||
|
|
||||||
|
use App\CMS\Contracts\Modules\ServiceProvider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class $Module$ServiceProvider
|
||||||
|
*
|
||||||
|
* Service provider for module $Module$
|
||||||
|
*
|
||||||
|
* @package Modules\$Module$\Providers
|
||||||
|
*/
|
||||||
|
class $Module$ServiceProvider extends ServiceProvider
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Set module Alias
|
||||||
|
*/
|
||||||
|
protected function setModuleAlias()
|
||||||
|
{
|
||||||
|
$this->alias = strtolower('$module$');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set path to module
|
||||||
|
*/
|
||||||
|
protected function setModulePath()
|
||||||
|
{
|
||||||
|
$this->path = __DIR__;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
namespace Modules\$ModuleNamespace$\Repositories;
|
||||||
|
|
||||||
|
use $EntityNamespace$\$Entity$ as $Entity$Entity;
|
||||||
|
|
||||||
|
class $Module$Repository {
|
||||||
|
/**
|
||||||
|
* Create new instance of entity
|
||||||
|
*
|
||||||
|
* @param $data
|
||||||
|
*/
|
||||||
|
public function create($data) {
|
||||||
|
$Entity$Entity::create($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update entity
|
||||||
|
*
|
||||||
|
* @param $Entity$Entity $entity
|
||||||
|
*/
|
||||||
|
public function update($Entity$Entity $entity, $data) {
|
||||||
|
$entity->update($data);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
'name' => '$Module$',
|
||||||
|
'new' => 'Vytvořit nový',
|
||||||
|
'description' => '',
|
||||||
|
'successfullyUpdated' => 'Úspěšně upraveno.',
|
||||||
|
'successfullyCreated' => 'Úspěšně vytvořeno.',
|
||||||
|
'successfullyDeleted' => 'Úspěšně smazáno.',
|
||||||
|
'overview' => 'Přehled',
|
||||||
|
'noItems' => 'Žádná data.',
|
||||||
|
'save' => 'Uložit'
|
||||||
|
];
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
@extends('admin.layoutWithNavigation')
|
||||||
|
|
||||||
|
@section('pageHeading', @trans('$module$::$module$.name'))
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
@include('$module$::admin/form', ['action' => route('$module$.new')])
|
||||||
|
@endsection
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
@extends('admin.layoutWithNavigation')
|
||||||
|
|
||||||
|
@section('pageHeading', @trans('$module$::$module$.name'))
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
@include('$module$::admin/form', ['action' => route('$module$.update')])
|
||||||
|
@endsection
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<form action="{{$action}}" method="post">
|
||||||
|
|
||||||
|
{{--...--}}
|
||||||
|
|
||||||
|
<input type="submit" class="btn btn-primary" value="@lang('$module$::$module$.save')">
|
||||||
|
</form>
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
@extends('admin.layoutWithNavigation')
|
||||||
|
|
||||||
|
@section('pageHeading', @trans('$module$::$module$.overview'))
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
@if (!empty($items))
|
||||||
|
<table>
|
||||||
|
@foreach($items as $item)
|
||||||
|
|
||||||
|
@endforeach
|
||||||
|
</table>
|
||||||
|
@else
|
||||||
|
<div class="alert alert-info">
|
||||||
|
<em>@trans('$module$::$module$.noItems')</em>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
@endsection
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands\Modules;
|
||||||
|
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
class CreateNew extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'module:new
|
||||||
|
{name : module name}
|
||||||
|
{parentModule? : name of parent module}
|
||||||
|
{--entity= : entity}';
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Create new CMS module.';
|
||||||
|
protected $moduleName;
|
||||||
|
protected $moduleNamespace;
|
||||||
|
protected $entity;
|
||||||
|
protected $entityNamespace;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
$defaultEntityNamespace = $this->loadArguments();
|
||||||
|
$path = preg_replace('|/{2,}|i', '/', config('modules.paths.modules') . '/' . $this->moduleNamespace);
|
||||||
|
|
||||||
|
if (is_dir($path)) {
|
||||||
|
$this->error('Module already exists in ' . $path);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// copy stub files
|
||||||
|
\File::copyDirectory(config('modules.paths.stubs'), $path);
|
||||||
|
|
||||||
|
$files = \File::allFiles($path);
|
||||||
|
foreach ($files as $file) {
|
||||||
|
$newName = str_replace('stub', 'php', $this->replacePlaceholders($file->getPathname()));
|
||||||
|
|
||||||
|
// ignore new entity when using existing entity
|
||||||
|
if ($this->entityNamespace != $defaultEntityNamespace && Str::contains('Entities', $file)) {
|
||||||
|
\File::delete($file);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// rename file
|
||||||
|
\File::move($file, $newName);
|
||||||
|
|
||||||
|
// change its content
|
||||||
|
$content = file_get_contents($newName);
|
||||||
|
$content = $this->replacePlaceholders($content);
|
||||||
|
file_put_contents($newName, $content);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->info('Module successfully created.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find and replace all placeholders in given content
|
||||||
|
*
|
||||||
|
* @param $content
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
private function replacePlaceholders($content)
|
||||||
|
{
|
||||||
|
$replace = [
|
||||||
|
'$Module$' => $this->moduleName,
|
||||||
|
'$ModuleNamespace$' => str_replace('/', '\\', $this->moduleNamespace),
|
||||||
|
'$module$' => strtolower($this->moduleName),
|
||||||
|
'$EntityNamespace$' => $this->entityNamespace,
|
||||||
|
'$Entity$' => $this->entity
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($replace as $what => $for) {
|
||||||
|
$content = str_replace($what, $for, $content);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load command arguments
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function loadArguments()
|
||||||
|
{
|
||||||
|
$parent = $this->argument('parentModule');
|
||||||
|
$this->moduleName = $moduleName = $this->argument('name');
|
||||||
|
$this->moduleNamespace = trim($parent . '/' . $moduleName, '/');
|
||||||
|
|
||||||
|
$entity = $this->option('entity');
|
||||||
|
|
||||||
|
$defaultEntityNamespace = '\\Modules\\' . str_replace('/', '\\', $this->moduleNamespace) . '\Entities\\';
|
||||||
|
|
||||||
|
if (!empty($entity)) {
|
||||||
|
$parts = explode('\\', $entity);
|
||||||
|
$this->entity = $parts[count($parts) - 1];
|
||||||
|
unset($parts[count($parts) - 1]);
|
||||||
|
$this->entityNamespace = implode('\\', $parts);
|
||||||
|
} else {
|
||||||
|
$this->entityNamespace = $defaultEntityNamespace;
|
||||||
|
$this->entity = $this->moduleName;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $defaultEntityNamespace;
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
-13
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands\Modules;
|
||||||
|
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Support\Facades\File;
|
use Illuminate\Support\Facades\File;
|
||||||
@@ -12,7 +12,7 @@ class InstallAllModules extends Command
|
|||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'install-all-modules';
|
protected $signature = 'module:install-all';
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
*
|
*
|
||||||
@@ -20,16 +20,6 @@ class InstallAllModules extends Command
|
|||||||
*/
|
*/
|
||||||
protected $description = 'Crawl /modules directory and install all modules';
|
protected $description = 'Crawl /modules directory and install all modules';
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new command instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the console command.
|
* Execute the console command.
|
||||||
*
|
*
|
||||||
@@ -45,7 +35,7 @@ class InstallAllModules extends Command
|
|||||||
|
|
||||||
// try to install each module
|
// try to install each module
|
||||||
try {
|
try {
|
||||||
$this->call('install-module', ['name' => $moduleName]);
|
$this->call('module:install', ['name' => $moduleName]);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->line('Module ' . $moduleName . ' already installed.');
|
$this->line('Module ' . $moduleName . ' already installed.');
|
||||||
}
|
}
|
||||||
+5
-5
@@ -1,8 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands\Modules;
|
||||||
|
|
||||||
use App\Models\Module;
|
use App\Models\Module;
|
||||||
|
use App\ModuleManager\Installer;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Contracts\Filesystem\FileNotFoundException;
|
use Illuminate\Contracts\Filesystem\FileNotFoundException;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
@@ -17,7 +18,7 @@ class InstallModule extends Command
|
|||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'install-module {name} {parentModuleId?}';
|
protected $signature = 'module:install {name} {parentModuleId?}';
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
*
|
*
|
||||||
@@ -156,12 +157,11 @@ class InstallModule extends Command
|
|||||||
$settings = [
|
$settings = [
|
||||||
'staticName' => $this->moduleName,
|
'staticName' => $this->moduleName,
|
||||||
'providers' => $providers,
|
'providers' => $providers,
|
||||||
'aliases' => isset($config['aliases']) ? $config['aliases'] : [],
|
|
||||||
'order' => isset($config['order']) ? $config['order'] : 0,
|
'order' => isset($config['order']) ? $config['order'] : 0,
|
||||||
'files' => isset($config['files']) ? $config['files'] : []
|
'files' => isset($config['files']) ? $config['files'] : []
|
||||||
];
|
];
|
||||||
|
|
||||||
$module = Module::install($name, $alias, $description, $handler, $this->parentModuleId, $settings);
|
$module = Installer::install($name, $alias, $description, $handler, $this->parentModuleId, $settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
// try to install submodules
|
// try to install submodules
|
||||||
@@ -184,7 +184,7 @@ class InstallModule extends Command
|
|||||||
$submodule = str_replace($this->modulesPath . DIRECTORY_SEPARATOR, '', $submodulePath);
|
$submodule = str_replace($this->modulesPath . DIRECTORY_SEPARATOR, '', $submodulePath);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->call('install-module', ['name' => $submodule, 'parentModuleId' => $parentModule->id]);
|
$this->call('module:install', ['name' => $submodule, 'parentModuleId' => $parentModule->id]);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->error($e->getMessage());
|
$this->error($e->getMessage());
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,8 @@
|
|||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
use App\Models\Module;
|
use App\Models\Module;
|
||||||
|
use App\ModuleManager\Installer;
|
||||||
|
use App\ModuleManager\Uninstaller;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
@@ -43,14 +45,13 @@ class SetTemplate extends Command
|
|||||||
$config['staticName'] = $template;
|
$config['staticName'] = $template;
|
||||||
|
|
||||||
if ($current) {
|
if ($current) {
|
||||||
$info = json_decode($current->module_settings);
|
$this->line('Template is already installed. Currently using template ' . trans($current->name) . ' located in /templates/' . $current->module_settings['staticName'] . '.');
|
||||||
|
|
||||||
$this->line('Template is already installed. Currently using template ' . trans($current->name) . ' located in /templates/' . $info->staticName . '.');
|
|
||||||
$confirm = $this->confirm('Uninstall it and install *' . trans($config['name']) . '*? All data associated with installed template will be lost!');
|
$confirm = $this->confirm('Uninstall it and install *' . trans($config['name']) . '*? All data associated with installed template will be lost!');
|
||||||
|
|
||||||
if ($confirm) {
|
if ($confirm) {
|
||||||
$this->line('Uninstalling ' . $current->name . '.');
|
$this->line('Uninstalling ' . $current->name . '.');
|
||||||
$current->uninstall();
|
|
||||||
|
Uninstaller::uninstall($current);
|
||||||
} else {
|
} else {
|
||||||
$this->line('Aborting installation.');
|
$this->line('Aborting installation.');
|
||||||
return;
|
return;
|
||||||
@@ -58,7 +59,7 @@ class SetTemplate extends Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Module::install($config['name'], $config['alias'], $config['description'], $config['handler'], false, $config);
|
Installer::install($config['name'], $config['alias'], $config['description'], $config['handler'], false, $config);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->error('Cannot install template ' . $template . '. Message: ' . $e->getMessage());
|
$this->error('Cannot install template ' . $template . '. Message: ' . $e->getMessage());
|
||||||
return;
|
return;
|
||||||
@@ -72,6 +73,8 @@ class SetTemplate extends Command
|
|||||||
|
|
||||||
// run again artisan for publishing resources
|
// run again artisan for publishing resources
|
||||||
// it cannot be done using $this->call, because we need to load different template into service providers
|
// it cannot be done using $this->call, because we need to load different template into service providers
|
||||||
exec('php artisan vendor:publish');
|
if ($publish) {
|
||||||
|
exec('php artisan vendor:publish');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Console;
|
namespace App\Console;
|
||||||
|
|
||||||
|
use App\Console\Commands\Modules\CreateNew;
|
||||||
use App\Console\Commands\PublishTemplateResources;
|
use App\Console\Commands\PublishTemplateResources;
|
||||||
use App\Console\Commands\TemplateInfo;
|
use App\Console\Commands\TemplateInfo;
|
||||||
use Illuminate\Console\Scheduling\Schedule;
|
use Illuminate\Console\Scheduling\Schedule;
|
||||||
@@ -17,8 +18,9 @@ class Kernel extends ConsoleKernel
|
|||||||
protected $commands = [
|
protected $commands = [
|
||||||
Commands\NewUser::class,
|
Commands\NewUser::class,
|
||||||
Commands\ChangePassword::class,
|
Commands\ChangePassword::class,
|
||||||
Commands\InstallModule::class,
|
CreateNew::class,
|
||||||
Commands\InstallAllModules::class,
|
Commands\Modules\InstallModule::class,
|
||||||
|
Commands\Modules\InstallAllModules::class,
|
||||||
Commands\TranslateDirectory::class,
|
Commands\TranslateDirectory::class,
|
||||||
Commands\TranslateAll::class,
|
Commands\TranslateAll::class,
|
||||||
Commands\InitDatabaseSchema::class,
|
Commands\InitDatabaseSchema::class,
|
||||||
@@ -37,7 +39,5 @@ class Kernel extends ConsoleKernel
|
|||||||
*/
|
*/
|
||||||
protected function schedule(Schedule $schedule)
|
protected function schedule(Schedule $schedule)
|
||||||
{
|
{
|
||||||
// $schedule->command('inspire')
|
|
||||||
// ->hourly();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ class Controller extends BaseController
|
|||||||
*
|
*
|
||||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||||
*/
|
*/
|
||||||
public static function VisitorsView($template, $data = [], $mergeData = [])
|
public static function visitorsView($template, $data = [], $mergeData = [])
|
||||||
{
|
{
|
||||||
$view = Template::name($template);
|
$view = Template::name($template);
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ class ContentPage extends Controller
|
|||||||
$displayPipeline = app('displayPipeline');
|
$displayPipeline = app('displayPipeline');
|
||||||
$page = $displayPipeline->run($page);
|
$page = $displayPipeline->run($page);
|
||||||
|
|
||||||
return Controller::VisitorsView($page->template, ['page' => $page]);
|
return Controller::visitorsView($page->template, ['page' => $page]);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ use Illuminate\Database\Eloquent\Model;
|
|||||||
*/
|
*/
|
||||||
class Module extends Model
|
class Module extends Model
|
||||||
{
|
{
|
||||||
use ModelTraits\Module;
|
|
||||||
public $timestamps = false;
|
public $timestamps = false;
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'handler',
|
'handler',
|
||||||
@@ -23,4 +22,9 @@ class Module extends Model
|
|||||||
'manages_content',
|
'manages_content',
|
||||||
'is_template'
|
'is_template'
|
||||||
];
|
];
|
||||||
|
protected $casts = [
|
||||||
|
'module_settings' => 'array',
|
||||||
|
'is_template' => 'boolean',
|
||||||
|
'has_submodules' => 'boolean'
|
||||||
|
];
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
'namespace' => 'Modules',
|
||||||
|
'paths' => [
|
||||||
|
'modules' => base_path('modules'),
|
||||||
|
'assets' => public_path('modules'),
|
||||||
|
'stubs' => base_path('app/CMS/Modules/Stubs'),
|
||||||
|
]
|
||||||
|
];
|
||||||
@@ -1,14 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace App\Models\ModelTraits;
|
namespace App\ModuleManager;
|
||||||
|
|
||||||
use App\CMS\Contracts\Modules\AppHandler;
|
use App\CMS\Contracts\Modules\AppHandler;
|
||||||
use App\CMS\Contracts\Modules\TemplateHandler;
|
use App\CMS\Contracts\Modules\TemplateHandler;
|
||||||
use App\Models\Module as ModuleModel;
|
use App\Models\Module;
|
||||||
use App\Models\Templates\TemplatePath;
|
|
||||||
use Illuminate\Support\Facades\App;
|
use Illuminate\Support\Facades\App;
|
||||||
|
|
||||||
trait Module
|
class Installer {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Create new module in database
|
* Create new module in database
|
||||||
*
|
*
|
||||||
@@ -34,20 +32,20 @@ trait Module
|
|||||||
$supportCategories = $managesContent ? call_user_func([$handler, 'supportCategories']) : false;
|
$supportCategories = $managesContent ? call_user_func([$handler, 'supportCategories']) : false;
|
||||||
|
|
||||||
if ($parentModuleId) {
|
if ($parentModuleId) {
|
||||||
$parentModule = ModuleModel::findOrFail($parentModuleId);
|
$parentModule = Module::findOrFail($parentModuleId);
|
||||||
$parentModule->has_submodules = true;
|
$parentModule->has_submodules = true;
|
||||||
$parentModule->save();
|
$parentModule->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
// insert module into database
|
// insert module into database
|
||||||
$module = ModuleModel::create([
|
$module = Module::create([
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'description' => $description,
|
'description' => $description,
|
||||||
'handler' => $handler,
|
'handler' => $handler,
|
||||||
'manages_content' => $managesContent,
|
'manages_content' => $managesContent,
|
||||||
'support_categories' => $supportCategories,
|
'support_categories' => $supportCategories,
|
||||||
'alias' => $alias,
|
'alias' => $alias,
|
||||||
'module_settings' => json_encode($settings),
|
'module_settings' => $settings,
|
||||||
'parent_id' => $parentModuleId ? $parentModuleId : null,
|
'parent_id' => $parentModuleId ? $parentModuleId : null,
|
||||||
'enabled' => 1,
|
'enabled' => 1,
|
||||||
'is_template' => $isTemplate
|
'is_template' => $isTemplate
|
||||||
@@ -60,54 +58,4 @@ trait Module
|
|||||||
|
|
||||||
return $module;
|
return $module;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete module from database and uninstall its dependencies
|
|
||||||
*
|
|
||||||
* @throws \ErrorException
|
|
||||||
*/
|
|
||||||
public function uninstall()
|
|
||||||
{
|
|
||||||
// check if user does not want to install module in runtime
|
|
||||||
if (!App::runningInConsole()) {
|
|
||||||
throw new \ErrorException('Modules can be uninstalled only via Artisan!');
|
|
||||||
}
|
|
||||||
|
|
||||||
// delete everything in /resources/views/visitor
|
|
||||||
if ($this->is_template) {
|
|
||||||
$this->deleteDirectory(resource_path('views/visitor'));
|
|
||||||
$this->deleteDirectory(resource_path('views/modules'));
|
|
||||||
$this->deleteDirectory(public_path('assets'));
|
|
||||||
|
|
||||||
// delete all template paths
|
|
||||||
TemplatePath::getQuery()
|
|
||||||
->delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->handler && is_callable([$this->handler, 'uninstall'])) {
|
|
||||||
call_user_func([$this->handler, 'uninstall'], $this);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete directory when uninstalling module.
|
|
||||||
*
|
|
||||||
* @param $directory
|
|
||||||
*
|
|
||||||
* @throws \ErrorException
|
|
||||||
*/
|
|
||||||
private function deleteDirectory($directory)
|
|
||||||
{
|
|
||||||
if (!is_dir($directory)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$success = \File::deleteDirectory($directory, true);
|
|
||||||
|
|
||||||
if (!$success) {
|
|
||||||
throw new \ErrorException('Cannot delete ' . $directory);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\ModuleManager\Providers;
|
||||||
|
|
||||||
|
use App\Models\Module;
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
|
||||||
|
class ModuleManager extends ServiceProvider
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Bootstrap the application services.
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function boot()
|
||||||
|
{
|
||||||
|
// this service provider needs published config - config is merged right after this service provider
|
||||||
|
$modules = Cache::rememberForever('enabled-modules', function () {
|
||||||
|
return Module::where('enabled', true)
|
||||||
|
->where('is_template', false)
|
||||||
|
->get();
|
||||||
|
});
|
||||||
|
|
||||||
|
// iterate over all modules and enable or disable them
|
||||||
|
foreach ($modules as $module) {
|
||||||
|
if (isset($module->module_settings['providers']) && !empty($module->module_settings['providers'])) {
|
||||||
|
foreach ($module->module_settings['providers'] as $provider) {
|
||||||
|
$this->app->register($provider);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// include files (if any)
|
||||||
|
if (isset($module->module_settings['files']) && !empty($module->module_settings['files'])) {
|
||||||
|
foreach ($module->module_settings['files'] as $file) {
|
||||||
|
include config('modules.paths.modules') . '/' . $module->module_settings['staticName'] . '/' . $file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register the application services.
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function register()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\ModuleManager;
|
||||||
|
|
||||||
|
use App\Models\Module;
|
||||||
|
use App\Models\Templates\TemplatePath;
|
||||||
|
use Illuminate\Support\Facades\App;
|
||||||
|
|
||||||
|
class Uninstaller {
|
||||||
|
/**
|
||||||
|
* Delete module from database and uninstall its dependencies
|
||||||
|
*
|
||||||
|
* @param Module $module
|
||||||
|
*
|
||||||
|
* @throws \ErrorException
|
||||||
|
*/
|
||||||
|
public static function uninstall(Module $module)
|
||||||
|
{
|
||||||
|
// check if user does not want to install module in runtime
|
||||||
|
if (!App::runningInConsole()) {
|
||||||
|
throw new \ErrorException('Modules can be uninstalled only via Artisan!');
|
||||||
|
}
|
||||||
|
|
||||||
|
// delete everything in /resources/views/visitor
|
||||||
|
if ($module->is_template) {
|
||||||
|
self::deleteDirectory(resource_path('views/visitor'));
|
||||||
|
self::deleteDirectory(resource_path('views/modules'));
|
||||||
|
self::deleteDirectory(public_path('assets'));
|
||||||
|
|
||||||
|
// delete all template paths
|
||||||
|
TemplatePath::getQuery()
|
||||||
|
->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($module->handler && is_callable([$module->handler, 'uninstall'])) {
|
||||||
|
call_user_func([$module->handler, 'uninstall'], $module);
|
||||||
|
}
|
||||||
|
|
||||||
|
$module->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete directory when uninstalling module.
|
||||||
|
*
|
||||||
|
* @param $directory
|
||||||
|
*
|
||||||
|
* @throws \ErrorException
|
||||||
|
*/
|
||||||
|
private static function deleteDirectory($directory)
|
||||||
|
{
|
||||||
|
if (!is_dir($directory)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$success = \File::deleteDirectory($directory, true);
|
||||||
|
|
||||||
|
if (!$success) {
|
||||||
|
throw new \ErrorException('Cannot delete ' . $directory);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -64,13 +64,12 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
// register PingPong module extension
|
// register PingPong module extension
|
||||||
$this->app->register(ModulesServiceProvider::class);
|
|
||||||
$this->app->register(MenusServiceProvider::class);
|
$this->app->register(MenusServiceProvider::class);
|
||||||
$this->app->register(LaravelLocalizationServiceProvider::class);
|
$this->app->register(LaravelLocalizationServiceProvider::class);
|
||||||
|
|
||||||
// create singletons for registering widgets
|
// create singletons for registering widgets
|
||||||
$this->app->singleton('registerWidget', function ($app) {
|
$this->app->singleton('registerWidget', function ($app) {
|
||||||
return new WidgetRegistrator($app);
|
return new WidgetRegistrator();
|
||||||
});
|
});
|
||||||
|
|
||||||
// create singleton for display pipeline - pipeline used for displaying visitor pages
|
// create singleton for display pipeline - pipeline used for displaying visitor pages
|
||||||
@@ -85,7 +84,7 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
|
|
||||||
// create registrator for template directories
|
// create registrator for template directories
|
||||||
$this->app->singleton('registerTemplateDir', function ($app) {
|
$this->app->singleton('registerTemplateDir', function ($app) {
|
||||||
return new TemplateRegistrator($app);
|
return new TemplateRegistrator();
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->app->singleton('registerSettingsExtension', function ($app) {
|
$this->app->singleton('registerSettingsExtension', function ($app) {
|
||||||
|
|||||||
@@ -1,93 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Providers;
|
|
||||||
|
|
||||||
use App\Models\Module;
|
|
||||||
use Illuminate\Support\Facades\Cache;
|
|
||||||
use Illuminate\Support\Facades\Log;
|
|
||||||
use Illuminate\Support\ServiceProvider;
|
|
||||||
|
|
||||||
class ModuleManager extends ServiceProvider
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Bootstrap the application services.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function boot()
|
|
||||||
{
|
|
||||||
// this service provider needs published config - config is merged right after this service provider
|
|
||||||
$modules = Cache::rememberForever('enabled-modules', function () {
|
|
||||||
$modules = Module::where('enabled', true)
|
|
||||||
->get();
|
|
||||||
|
|
||||||
foreach ($modules as $module) {
|
|
||||||
$module->module_settings = json_decode($module->module_settings);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $modules;
|
|
||||||
});
|
|
||||||
|
|
||||||
// iterate over all modules and enable or disable them
|
|
||||||
foreach ($modules as $module) {
|
|
||||||
if ($module->is_template) {
|
|
||||||
if (isset($module->module_settings->providers) && !empty($module->module_settings->providers)) {
|
|
||||||
foreach ($module->module_settings->providers as $provider) {
|
|
||||||
$this->app->register($provider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->createModulesJson($module);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register the application services.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function register()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Read config file and merge it with module config in database.
|
|
||||||
* This method REQUIRES published config of given module (otherwise config(modulename) is not available)!
|
|
||||||
*
|
|
||||||
* @param Module $module
|
|
||||||
*
|
|
||||||
* @throws \ErrorException when module.json is not writable
|
|
||||||
*/
|
|
||||||
private function createModulesJson(Module $module)
|
|
||||||
{
|
|
||||||
$config = $module->module_settings;
|
|
||||||
|
|
||||||
if (is_null($config)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// path to module.json
|
|
||||||
$path = config('modules.paths.modules') . DIRECTORY_SEPARATOR . $config->staticName . DIRECTORY_SEPARATOR . 'module.json';
|
|
||||||
|
|
||||||
// check if module config is writable
|
|
||||||
if (!is_writable(dirname($path))) {
|
|
||||||
Log::warning('Cannot write to ' . $path);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// set enabled/disabled status for this module
|
|
||||||
$data = new \stdClass();
|
|
||||||
$data->name = $config->staticName;
|
|
||||||
$data->description = $module->description;
|
|
||||||
$data->alias = $module->alias;
|
|
||||||
$data->providers = $config->providers;
|
|
||||||
$data->aliases = $config->aliases;
|
|
||||||
$data->order = $config->order;
|
|
||||||
$data->files = $config->files;
|
|
||||||
$data->active = $module->enabled;
|
|
||||||
|
|
||||||
// create file
|
|
||||||
file_put_contents($path, json_encode($data));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Providers;
|
|
||||||
|
|
||||||
use Illuminate\Contracts\Filesystem\FileNotFoundException;
|
|
||||||
use Illuminate\Support\ServiceProvider;
|
|
||||||
use Pingpong\Modules\Json;
|
|
||||||
|
|
||||||
class SubmodulesManager extends ServiceProvider
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Boot submodules
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function boot()
|
|
||||||
{
|
|
||||||
$enabledModules = \Module::enabled();
|
|
||||||
|
|
||||||
foreach ($enabledModules as $module) {
|
|
||||||
$modulePath = $module->getPath();
|
|
||||||
$config = new Json($modulePath . DIRECTORY_SEPARATOR . 'module.json');
|
|
||||||
|
|
||||||
// Does this module specify any providers? If not, consider this module with submodules and register them
|
|
||||||
if ($config->get('providers')) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$submodules = \File::directories($modulePath);
|
|
||||||
|
|
||||||
foreach ($submodules as $submodulePath) {
|
|
||||||
try {
|
|
||||||
$config = new Json($submodulePath . DIRECTORY_SEPARATOR . 'module.json');
|
|
||||||
|
|
||||||
if (!$config->get('active')) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$serviceProviders = $config->get('providers', []);
|
|
||||||
foreach ($serviceProviders as $serviceProvider) {
|
|
||||||
$this->app->register($serviceProvider);
|
|
||||||
}
|
|
||||||
|
|
||||||
$initFiles = $config->get('files', []);
|
|
||||||
|
|
||||||
foreach ($initFiles as $file) {
|
|
||||||
require $submodulePath . DIRECTORY_SEPARATOR . $file;
|
|
||||||
}
|
|
||||||
} catch (FileNotFoundException $e) {
|
|
||||||
// ignore missing module and do not register this submodule
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register the service provider.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function register()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -94,7 +94,7 @@ class TemplateServiceProvider extends ServiceProvider
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$templateDir = base_path('templates/' . $template->module_settings->staticName . '/Resources');
|
$templateDir = base_path('templates/' . $template->module_settings['staticName']. '/Resources');
|
||||||
$assetsDir = $templateDir . '/' . TemplateContract::ASSETS_DIRECTORY;
|
$assetsDir = $templateDir . '/' . TemplateContract::ASSETS_DIRECTORY;
|
||||||
$viewsDir = $templateDir . '/views';
|
$viewsDir = $templateDir . '/views';
|
||||||
|
|
||||||
|
|||||||
+1
-3
@@ -8,8 +8,7 @@
|
|||||||
"type": "project",
|
"type": "project",
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.5.9",
|
"php": ">=5.5.9",
|
||||||
"laravel/framework": "5.2.*",
|
"laravel/framework": "5.4.*",
|
||||||
"pingpong/modules": "~2.0",
|
|
||||||
"pingpong/menus": "^2.2",
|
"pingpong/menus": "^2.2",
|
||||||
"watson/sitemap": "^2.0",
|
"watson/sitemap": "^2.0",
|
||||||
"mcamara/laravel-localization": "^1.1",
|
"mcamara/laravel-localization": "^1.1",
|
||||||
@@ -24,7 +23,6 @@
|
|||||||
"phpunit/phpunit": "~4.0",
|
"phpunit/phpunit": "~4.0",
|
||||||
"symfony/css-selector": "2.8.*|3.0.*",
|
"symfony/css-selector": "2.8.*|3.0.*",
|
||||||
"symfony/dom-crawler": "2.8.*|3.0.*",
|
"symfony/dom-crawler": "2.8.*|3.0.*",
|
||||||
"ignasbernotas/laravel-model-generator": "^1.0",
|
|
||||||
"barryvdh/laravel-debugbar": "^2.1"
|
"barryvdh/laravel-debugbar": "^2.1"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
|
|||||||
Generated
+579
-673
File diff suppressed because it is too large
Load Diff
+1
-5
@@ -154,11 +154,8 @@ return [
|
|||||||
Illuminate\Validation\ValidationServiceProvider::class,
|
Illuminate\Validation\ValidationServiceProvider::class,
|
||||||
Illuminate\View\ViewServiceProvider::class,
|
Illuminate\View\ViewServiceProvider::class,
|
||||||
Mcamara\LaravelLocalization\LaravelLocalizationServiceProvider::class,
|
Mcamara\LaravelLocalization\LaravelLocalizationServiceProvider::class,
|
||||||
// this class must be before ModulesServiceProvider from PingPong, because it handles files module.json
|
\App\ModuleManager\Providers\ModuleManager::class,
|
||||||
App\Providers\ModuleManager::class,
|
|
||||||
Pingpong\Modules\ModulesServiceProvider::class,
|
|
||||||
Pingpong\Menus\MenusServiceProvider::class,
|
Pingpong\Menus\MenusServiceProvider::class,
|
||||||
App\Providers\SubmodulesManager::class,
|
|
||||||
Franzose\ClosureTable\ClosureTableServiceProvider::class,
|
Franzose\ClosureTable\ClosureTableServiceProvider::class,
|
||||||
\Watson\Sitemap\SitemapServiceProvider::class,
|
\Watson\Sitemap\SitemapServiceProvider::class,
|
||||||
Intervention\Image\ImageServiceProvider::class,
|
Intervention\Image\ImageServiceProvider::class,
|
||||||
@@ -206,7 +203,6 @@ return [
|
|||||||
'Log' => Illuminate\Support\Facades\Log::class,
|
'Log' => Illuminate\Support\Facades\Log::class,
|
||||||
'Mail' => Illuminate\Support\Facades\Mail::class,
|
'Mail' => Illuminate\Support\Facades\Mail::class,
|
||||||
'Menu' => Pingpong\Menus\MenuFacade::class,
|
'Menu' => Pingpong\Menus\MenuFacade::class,
|
||||||
'Module' => Pingpong\Modules\Facades\Module::class,
|
|
||||||
'Password' => Illuminate\Support\Facades\Password::class,
|
'Password' => Illuminate\Support\Facades\Password::class,
|
||||||
'Queue' => Illuminate\Support\Facades\Queue::class,
|
'Queue' => Illuminate\Support\Facades\Queue::class,
|
||||||
'Redirect' => Illuminate\Support\Facades\Redirect::class,
|
'Redirect' => Illuminate\Support\Facades\Redirect::class,
|
||||||
|
|||||||
+5
-155
@@ -1,160 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| Module Namespace
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
|
|
|
||||||
| Default module namespace.
|
|
||||||
|
|
|
||||||
*/
|
|
||||||
|
|
||||||
'namespace' => 'Modules',
|
'namespace' => 'Modules',
|
||||||
|
'paths' => [
|
||||||
/*
|
'modules' => base_path('modules'),
|
||||||
|--------------------------------------------------------------------------
|
'assets' => public_path('modules'),
|
||||||
| Module Stubs
|
'stubs' => base_path('app/ModuleManager/Stubs'),
|
||||||
|--------------------------------------------------------------------------
|
]
|
||||||
|
|
|
||||||
| Default module stubs.
|
|
||||||
|
|
|
||||||
*/
|
|
||||||
|
|
||||||
'stubs' => [
|
|
||||||
'enabled' => false,
|
|
||||||
'path' => base_path().'/vendor/pingpong/modules/src/Pingpong/Modules/Commands/stubs',
|
|
||||||
'files' => [
|
|
||||||
'start' => 'start.php',
|
|
||||||
'routes' => 'Http/routes.php',
|
|
||||||
'json' => 'module.json',
|
|
||||||
'views/index' => 'Resources/views/index.blade.php',
|
|
||||||
'views/master' => 'Resources/views/layouts/master.blade.php',
|
|
||||||
'scaffold/config' => 'Config/config.php',
|
|
||||||
'composer' => 'composer.json',
|
|
||||||
],
|
|
||||||
'replacements' => [
|
|
||||||
'start' => ['LOWER_NAME'],
|
|
||||||
'routes' => ['LOWER_NAME', 'STUDLY_NAME', 'MODULE_NAMESPACE'],
|
|
||||||
'json' => ['LOWER_NAME', 'STUDLY_NAME', 'MODULE_NAMESPACE'],
|
|
||||||
'views/index' => ['LOWER_NAME'],
|
|
||||||
'views/master' => ['STUDLY_NAME'],
|
|
||||||
'scaffold/config' => ['STUDLY_NAME'],
|
|
||||||
'composer' => [
|
|
||||||
'LOWER_NAME',
|
|
||||||
'STUDLY_NAME',
|
|
||||||
'VENDOR',
|
|
||||||
'AUTHOR_NAME',
|
|
||||||
'AUTHOR_EMAIL',
|
|
||||||
'MODULE_NAMESPACE',
|
|
||||||
],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
'paths' => [
|
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| Modules path
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
|
|
|
||||||
| This path used for save the generated module. This path also will added
|
|
||||||
| automatically to list of scanned folders.
|
|
||||||
|
|
|
||||||
*/
|
|
||||||
|
|
||||||
'modules' => base_path('modules'),
|
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| Modules assets path
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
|
|
|
||||||
| Here you may update the modules assets path.
|
|
||||||
|
|
|
||||||
*/
|
|
||||||
|
|
||||||
'assets' => public_path('modules'),
|
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| The migrations path
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
|
|
|
||||||
| Where you run 'module:publish-migration' command, where do you publish the
|
|
||||||
| the migration files?
|
|
||||||
|
|
|
||||||
*/
|
|
||||||
|
|
||||||
'migration' => base_path('database/migrations'),
|
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| Generator path
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
|
|
|
||||||
| Here you may update the modules generator path.
|
|
||||||
|
|
|
||||||
*/
|
|
||||||
|
|
||||||
'generator' => [
|
|
||||||
'assets' => 'Assets',
|
|
||||||
'config' => 'Config',
|
|
||||||
'command' => 'Console',
|
|
||||||
'migration' => 'Database/Migrations',
|
|
||||||
'model' => 'Entities',
|
|
||||||
'repository' => 'Repositories',
|
|
||||||
'seeder' => 'Database/Seeders',
|
|
||||||
'controller' => 'Http/Controllers',
|
|
||||||
'filter' => 'Http/Middleware',
|
|
||||||
'request' => 'Http/Requests',
|
|
||||||
'provider' => 'Providers',
|
|
||||||
'lang' => 'Resources/lang',
|
|
||||||
'views' => 'Resources/views',
|
|
||||||
'test' => 'Tests',
|
|
||||||
],
|
|
||||||
],
|
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| Scan Path
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
|
|
|
||||||
| Here you define which folder will be scanned. By default will scan vendor
|
|
||||||
| directory. This is useful if you host the package in packagist website.
|
|
||||||
|
|
|
||||||
*/
|
|
||||||
|
|
||||||
'scan' => [
|
|
||||||
'enabled' => false,
|
|
||||||
'paths' => [
|
|
||||||
base_path('vendor/*/*'),
|
|
||||||
],
|
|
||||||
],
|
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| Composer File Template
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
|
|
|
||||||
| Here is the config for composer.json file, generated by this package
|
|
||||||
| in every module since version >= 1.2.0.
|
|
||||||
|
|
|
||||||
*/
|
|
||||||
|
|
||||||
'composer' => [
|
|
||||||
'vendor' => 'pingpong-modules',
|
|
||||||
'author' => [
|
|
||||||
'name' => 'Pingpong Labs',
|
|
||||||
'email' => 'pingpong.labs@gmail.com',
|
|
||||||
],
|
|
||||||
],
|
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| Caching
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
|
|
|
||||||
| Here is the config for setting up caching feature.
|
|
||||||
|
|
|
||||||
*/
|
|
||||||
'cache' => [
|
|
||||||
'enabled' => false,
|
|
||||||
'key' => 'pingpong-modules',
|
|
||||||
'lifetime' => 60,
|
|
||||||
],
|
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
<?php namespace Modules\Blog\Article\Providers;
|
<?php namespace Modules\Blog\Article\Providers;
|
||||||
|
|
||||||
use App\Providers\ModuleServiceProvider;
|
use App\Providers\ModulesServiceProvider;
|
||||||
use Modules\Blog\Article\Pipeline\DisplayContent\LoadCommentsForBlogpost;
|
use Modules\Blog\Article\Pipeline\DisplayContent\LoadCommentsForBlogpost;
|
||||||
use Modules\Blog\Article\Pipeline\SaveContent\TurnCommentsOnOrOff;
|
use Modules\Blog\Article\Pipeline\SaveContent\TurnCommentsOnOrOff;
|
||||||
|
|
||||||
class ArticleServiceProvider extends ModuleServiceProvider
|
class ArticleServiceProvider extends ModulesServiceProvider
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Boot the application events.
|
* Boot the application events.
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
<?php namespace Modules\Blog\ArticleList\Providers;
|
<?php namespace Modules\Blog\ArticleList\Providers;
|
||||||
|
|
||||||
use App\Providers\ModuleServiceProvider;
|
use App\Providers\ModulesServiceProvider;
|
||||||
use Modules\Blog\ArticleList\Pipeline\DisplayContent\LoadArticlesForList;
|
use Modules\Blog\ArticleList\Pipeline\DisplayContent\LoadArticlesForList;
|
||||||
|
|
||||||
class ArticleListServiceProvider extends ModuleServiceProvider
|
class ArticleListServiceProvider extends ModulesServiceProvider
|
||||||
{
|
{
|
||||||
protected function setModuleAlias()
|
protected function setModuleAlias()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Modules\Categories\Providers;
|
namespace Modules\Categories\Providers;
|
||||||
|
|
||||||
use App\Providers\ModuleServiceProvider;
|
use App\Providers\ModulesServiceProvider;
|
||||||
use Modules\Categories\Contracts\Repositories\Category as ICategory;
|
use Modules\Categories\Contracts\Repositories\Category as ICategory;
|
||||||
use Modules\Categories\Repositories\Category as Category;
|
use Modules\Categories\Repositories\Category as Category;
|
||||||
|
|
||||||
class CategoriesServiceProvider extends ModuleServiceProvider
|
class CategoriesServiceProvider extends ModulesServiceProvider
|
||||||
{
|
{
|
||||||
protected function setModuleAlias()
|
protected function setModuleAlias()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
<?php namespace Modules\ContactForm\Providers;
|
<?php namespace Modules\ContactForm\Providers;
|
||||||
|
|
||||||
use App\Providers\ModuleServiceProvider;
|
use App\Providers\ModulesServiceProvider;
|
||||||
use Modules\ContactForm\Handlers\ContactForm;
|
use Modules\ContactForm\Handlers\ContactForm;
|
||||||
use Modules\ContactForm\Pipeline\SavePipeline\SaveContactInformation;
|
use Modules\ContactForm\Pipeline\SavePipeline\SaveContactInformation;
|
||||||
use Modules\ContactForm\Widgets\Address\Address;
|
use Modules\ContactForm\Widgets\Address\Address;
|
||||||
use Modules\ContactForm\Widgets\Form\Form;
|
use Modules\ContactForm\Widgets\Form\Form;
|
||||||
|
|
||||||
class ContactFormServiceProvider extends ModuleServiceProvider
|
class ContactFormServiceProvider extends ModulesServiceProvider
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Boot the application events.
|
* Boot the application events.
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ class Gallery implements AppHandler
|
|||||||
->get();
|
->get();
|
||||||
|
|
||||||
// render content
|
// render content
|
||||||
return Controller::VisitorsView($content->template, [
|
return Controller::visitorsView($content->template, [
|
||||||
'images' => $images,
|
'images' => $images,
|
||||||
'page' => $content,
|
'page' => $content,
|
||||||
'extra' => $parameters
|
'extra' => $parameters
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<?php namespace Modules\Gallery\Providers;
|
<?php namespace Modules\Gallery\Providers;
|
||||||
|
|
||||||
use App\Providers\ModuleServiceProvider;
|
use App\Providers\ModulesServiceProvider;
|
||||||
|
|
||||||
class GalleryServiceProvider extends ModuleServiceProvider
|
class GalleryServiceProvider extends ModulesServiceProvider
|
||||||
{
|
{
|
||||||
protected function setModuleAlias()
|
protected function setModuleAlias()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "pingpong-modules/gallery",
|
|
||||||
"description": "",
|
|
||||||
"authors": [
|
|
||||||
{
|
|
||||||
"name": "Pingpong Labs",
|
|
||||||
"email": "pingpong.labs@gmail.com"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"autoload": {
|
|
||||||
"psr-4": {
|
|
||||||
"Modules\\Gallery\\": ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -54,16 +54,6 @@ class StaticPage extends Handler implements ContentTitles
|
|||||||
return trans('staticpages::module.editPage');
|
return trans('staticpages::module.editPage');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Does given module manage content? Or is it just module with widgets/something internal/something absolutely else?
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public static function managesContent()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Does this module support categories?
|
* Does this module support categories?
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
<?php namespace Modules\Staticpages\Providers;
|
<?php namespace Modules\Staticpages\Providers;
|
||||||
|
|
||||||
use App\Providers\ModuleServiceProvider;
|
|
||||||
|
|
||||||
class StaticPagesServiceProvider extends ModuleServiceProvider
|
use App\CMS\Contracts\Modules\ServiceProvider;
|
||||||
|
|
||||||
|
class StaticPagesServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
protected function setModuleAlias()
|
protected function setModuleAlias()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "pingpong-modules/staticpages",
|
|
||||||
"description": "",
|
|
||||||
"authors": [
|
|
||||||
{
|
|
||||||
"name": "Pingpong Labs",
|
|
||||||
"email": "pingpong.labs@gmail.com"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"autoload": {
|
|
||||||
"psr-4": {
|
|
||||||
"Modules\\StaticPages\\": ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user