Commit 058949f8 authored by Nicolas Widart's avatar Nicolas Widart

Squashed 'Modules/Setting/' content from commit 1b17401

git-subtree-dir: Modules/Setting
git-subtree-split: 1b17401372deb66e19cfc0ed503ae20598f58605
parents
.idea/
.php_cs.cache
vendor/
composer.lock
Modules/
<?php
$finder = Symfony\CS\Finder\DefaultFinder::create()
->exclude('Modules')
->exclude('vendor')
->in(__DIR__)
;
return Symfony\CS\Config\Config::create()
->setUsingCache(true)
->level(Symfony\CS\FixerInterface::PSR2_LEVEL)
->fixers(array(
// Concatenation should be used with at least one whitespace around.
'concat_with_spaces',
// Unused use statements must be removed.
'ordered_use',
// Removes extra empty lines.
'extra_empty_lines',
// Removes line breaks between use statements.
'remove_lines_between_uses',
// An empty line feed should precede a return statement.
'return',
// Unused use statements must be removed.
'unused_use',
// Remove trailing whitespace at the end of blank lines.
'whitespacy_lines',
// There MUST be one blank line after the namespace declaration.
'line_after_namespace',
// There should be exactly one blank line before a namespace declaration.
'single_blank_line_before_namespace',
// Each namespace use MUST go on its own line and there MUST be one blank line after the use statements block.
'single_line_after_imports',
// Ensure there is no code on the same line as the PHP open tag and it is followed by a blankline.
'blankline_after_open_tag',
// Remove duplicated semicolons.
'duplicate_semicolon',
// PHP multi-line arrays should have a trailing comma.
'multiline_array_trailing_comma',
// There should be no empty lines after class opening brace.
'no_blank_lines_after_class_opening',
// There should not be blank lines between docblock and the documented element.
'no_empty_lines_after_phpdocs',
// Phpdocs should start and end with content, excluding the very first and last line of the docblocks.
'phpdoc_trim',
// Removes line breaks between use statements.
'remove_lines_between_uses',
))
->finder($finder);
rules:
php.interface_has_no_interface_suffix:
enabled: false
language: php
php:
- 7
- 5.6
- hhvm
env:
- LARAVEL_VERSION="~5.1" TESTBENCH_VERSION="~3.1"
before_script:
- travis_retry composer install --no-interaction --prefer-source
script: phpunit
sudo: false
notifications:
slack: asgardcms:85rIXCjkamzxitmc0opndGga
email:
- n.widart@gmail.com
- josh@joshbrown.me
matrix:
allow_failures:
- php: hhvm
<?php
namespace Modules\Setting\Blade\Facades;
use Illuminate\Support\Facades\Facade;
final class SettingDirective extends Facade
{
protected static function getFacadeAccessor()
{
return 'setting.setting.directive';
}
}
<?php
namespace Modules\Setting\Blade;
final class SettingDirective
{
/**
* @var string
*/
private $settingName;
/**
* @var string
*/
private $locale;
/**
* @var string Default value
*/
private $default;
/**
* @param $arguments
*/
public function show($arguments)
{
$this->extractArguments($arguments);
return setting($this->settingName, $this->locale, $this->default);
}
/**
* @param array $arguments
*/
private function extractArguments(array $arguments)
{
$this->settingName = array_get($arguments, 0);
$this->locale = array_get($arguments, 1);
$this->default = array_get($arguments, 2);
}
}
<?php
return [
/*
|--------------------------------------------------------------------------
| Custom Sidebar Class
|--------------------------------------------------------------------------
| If you want to customise the admin sidebar ordering or grouping
| You can define your own sidebar class for this module.
| No custom sidebar: null
*/
'custom-sidebar' => null,
];
<?php
return [
'setting.settings' => [
'index' => 'setting::settings.list resource',
'edit' => 'setting::settings.edit resource',
],
];
<?php
namespace Modules\Setting\Contracts;
interface Setting
{
/**
* Determine if the given configuration value exists.
*
* @param string $key
* @return bool
*/
public function has($key);
/**
* Get the specified configuration value in the given language
*
* @param string $key
* @param string $locale
* @param mixed $default
* @return string
*/
public function get($key, $locale = null, $default = null);
/**
* Set a given configuration value.
*
* @param string $key
* @param mixed $value
* @return \Modules\Setting\Entities\Setting
*/
public function set($key, $value);
}
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateSettingsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('setting__settings', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->increments('id');
$table->string('name');
$table->string('plainValue')->nullable();
$table->boolean('isTranslatable');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('setting__settings');
}
}
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateSettingTranslationsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('setting__setting_translations', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->increments('id');
$table->integer('setting_id')->unsigned();
$table->string('locale')->index();
$table->string('value');
$table->text('description')->nullable();
$table->unique(['setting_id', 'locale']);
$table->foreign('setting_id')->references('id')->on('setting__settings')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('setting__setting_translations');
}
}
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class MakeSettingsValueTextField extends Migration
{
/**
* Run the migrations.
* @return void
*/
public function up()
{
Schema::table('setting__settings', function (Blueprint $table) {
$table->text('plainValue')->string('plainValue')->change();
});
Schema::table('setting__setting_translations', function (Blueprint $table) {
$table->text('value')->string('value')->change();
});
}
/**
* Reverse the migrations.
* @return void
*/
public function down()
{
Schema::table('setting__settings', function (Blueprint $table) {
$table->string('plainValue')->text('plainValue')->change();
});
Schema::table('setting__setting_translations', function (Blueprint $table) {
$table->string('value')->text('value')->change();
});
}
}
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class MakeSettingsNameUnique extends Migration
{
/**
* Run the migrations.
* @return void
*/
public function up()
{
Schema::table('setting__settings', function (Blueprint $table) {
$table->unique('name', 'setting__settings_name_unique');
$table->index('name', 'setting__settings_name_index');
});
}
/**
* Reverse the migrations.
* @return void
*/
public function down()
{
Schema::table('setting__settings', function (Blueprint $table) {
$table->dropUnique('setting__settings_name_unique');
$table->dropIndex('setting__settings_name_index');
});
}
}
<?php
namespace Modules\Setting\Database\Seeders;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Seeder;
use Modules\Setting\Repositories\SettingRepository;
class SettingDatabaseSeeder extends Seeder
{
/**
* @var SettingRepository
*/
private $setting;
public function __construct(SettingRepository $setting)
{
$this->setting = $setting;
}
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Model::unguard();
$data = [
'core::template' => 'Flatly',
'core::locales' => ['en'],
];
$this->setting->createOrUpdate($data);
}
}
<?php
namespace Modules\Setting\Entities;
use Dimsav\Translatable\Translatable;
use Illuminate\Database\Eloquent\Model;
class Setting extends Model
{
use Translatable;
public $translatedAttributes = ['value', 'description'];
protected $fillable = ['name', 'value', 'description', 'isTranslatable', 'plainValue'];
protected $table = 'setting__settings';
}
<?php
namespace Modules\Setting\Entities;
use Illuminate\Database\Eloquent\Model;
class SettingTranslation extends Model
{
public $timestamps = false;
protected $fillable = ['value', 'description'];
protected $table = 'setting__setting_translations';
}
<?php
namespace Modules\Setting\Events\Handlers;
use Illuminate\Contracts\Cache\Repository;
class ClearSettingsCache
{
/**
* @var Repository
*/
private $cache;
public function __construct(Repository $cache)
{
$this->cache = $cache;
}
public function handle()
{
$this->cache->tags('setting.settings')->flush();
}
}
<?php
namespace Modules\Setting\Events;
class SettingWasCreated
{
/**
* @var bool
*/
public $isTranslatable;
/**
* @var string Setting name
*/
public $name;
/**
* @var string|array
*/
public $values;
/**
* @param $name
* @param $isTranslatable
* @param $values
*/
public function __construct($name, $isTranslatable, $values)
{
$this->isTranslatable = $isTranslatable;
$this->name = $name;
$this->values = $values;
}
}
<?php
namespace Modules\Setting\Events;
class SettingWasUpdated
{
/**
* @var string The setting name
*/
public $name;
/**
* @var string|array
*/
public $values;
/**
* @var string|array Containing the old values
*/
public $oldValues;
/**
* @var bool
*/
public $isTranslatable;
public function __construct($name, $isTranslatable, $values, $oldValues = null)
{
$this->name = $name;
$this->isTranslatable = $isTranslatable;
$this->values = $values;
$this->oldValues = $oldValues;
}
}
<?php
namespace Modules\Setting\Facades;
use Illuminate\Support\Facades\Facade;
class Settings extends Facade
{
protected static function getFacadeAccessor()
{
return 'setting.settings';
}
}
<?php
namespace Modules\Setting\Http\Controllers\Admin;
use Illuminate\Session\Store;
use Modules\Core\Http\Controllers\Admin\AdminBaseController;
use Modules\Core\Traits\CanRequireAssets;
use Modules\Setting\Http\Requests\SettingRequest;
use Modules\Setting\Repositories\SettingRepository;
use Nwidart\Modules\Module;
class SettingController extends AdminBaseController
{
use CanRequireAssets;
/**
* @var SettingRepository
*/
private $setting;
/**
* @var Module
*/
private $module;
/**
* @var Store
*/
private $session;
public function __construct(SettingRepository $setting, Store $session)
{
parent::__construct();
$this->setting = $setting;
$this->module = app('modules');
$this->session = $session;
}
public function index()
{
return redirect()->route('dashboard.module.settings', ['core']);
}
public function store(SettingRequest $request)
{
$this->setting->createOrUpdate($request->all());
return redirect()->route('dashboard.module.settings', [$this->session->get('module', 'Core')])
->withSuccess(trans('setting::messages.settings saved'));
}
public function getModuleSettings(Module $currentModule)
{
$this->session->set('module', $currentModule->getLowerName());
$modulesWithSettings = $this->setting->moduleSettings($this->module->enabled());
$translatableSettings = $this->setting->translatableModuleSettings($currentModule->getLowerName());
$plainSettings = $this->setting->plainModuleSettings($currentModule->getLowerName());
$dbSettings = $this->setting->savedModuleSettings($currentModule->getLowerName());
return view('setting::admin.module-settings',
compact('currentModule', 'translatableSettings', 'plainSettings', 'dbSettings', 'modulesWithSettings'));
}
}
<?php
namespace Modules\Setting\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class SettingRequest extends FormRequest
{
public function rules()
{
return [];
}
public function authorize()
{
return true;
}
public function messages()
{
return [];
}
}
<?php
use Illuminate\Routing\Router;
/** @var Router $router */
$router->group(['prefix' => '/setting'], function (Router $router) {
$router->get('settings/{module}', [
'as' => 'dashboard.module.settings',
'uses' => 'SettingController@getModuleSettings',
'middleware' => 'can:setting.settings.index',
]);
$router->get('settings', [
'as' => 'admin.setting.settings.index',
'uses' => 'SettingController@index',
'middleware' => 'can:setting.settings.index',
]);
$router->post('settings', [
'as' => 'admin.setting.settings.store',
'uses' => 'SettingController@store',
'middleware' => 'can:setting.settings.edit',
]);
});
# License (MIT)
Copyright (c) 2016 Nicolas Widart , n.widart@gmail.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
<?php
namespace Modules\Setting\Providers;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Modules\Setting\Events\Handlers\ClearSettingsCache;
use Modules\Setting\Events\SettingWasCreated;
use Modules\Setting\Events\SettingWasUpdated;
class EventServiceProvider extends ServiceProvider
{
protected $listen = [
SettingWasCreated::class => [
ClearSettingsCache::class,
],
SettingWasUpdated::class => [
ClearSettingsCache::class,
],
];
}
<?php
namespace Modules\Setting\Providers;
use Modules\Core\Providers\RoutingServiceProvider as CoreRoutingServiceProvider;
class RouteServiceProvider extends CoreRoutingServiceProvider
{
/**
* The root namespace to assume when generating URLs to actions.
* @var string
*/
protected $namespace = 'Modules\Setting\Http\Controllers';
/**
* @return string
*/
protected function getFrontendRoute()
{
return false;
}
/**
* @return string
*/
protected function getBackendRoute()
{
return __DIR__ . '/../Http/backendRoutes.php';
}
/**
* @return string
*/
protected function getApiRoute()
{
return false;
}
}
<?php
namespace Modules\Setting\Providers;
use Illuminate\Foundation\AliasLoader;
use Illuminate\Support\ServiceProvider;
use Modules\Core\Traits\CanPublishConfiguration;
use Modules\Setting\Blade\SettingDirective;
use Modules\Setting\Entities\Setting;
use Modules\Setting\Facades\Settings as SettingsFacade;
use Modules\Setting\Repositories\Cache\CacheSettingDecorator;
use Modules\Setting\Repositories\Eloquent\EloquentSettingRepository;
use Modules\Setting\Repositories\SettingRepository;
use Modules\Setting\Support\Settings;
class SettingServiceProvider extends ServiceProvider
{
use CanPublishConfiguration;
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = false;
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->registerBindings();
$this->app['setting.settings'] = $this->app->share(function ($app) {
return new Settings($app[SettingRepository::class]);
});
$this->app->booting(function () {
$loader = AliasLoader::getInstance();
$loader->alias('Settings', SettingsFacade::class);
});
$this->app->bind('setting.setting.directive', function () {
return new SettingDirective();
});
}
public function boot()
{
$this->publishConfig('setting', 'permissions');
$this->publishConfig('setting', 'config');
$this->registerBladeTags();
$this->loadMigrationsFrom(__DIR__.'/../Database/Migrations');
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return array();
}
private function registerBindings()
{
$this->app->bind(SettingRepository::class, function () {
$repository = new EloquentSettingRepository(new Setting());
if (! config('app.cache')) {
return $repository;
}
return new CacheSettingDecorator($repository);
});
$this->app->bind(
\Modules\Setting\Contracts\Setting::class,
Settings::class
);
}
private function registerBladeTags()
{
if (app()->environment() === 'testing') {
return;
}
$this->app['blade.compiler']->directive('setting', function ($value) {
return "<?php echo SettingDirective::show([$value]); ?>";
});
}
}
<?php
namespace Modules\Setting\Providers;
use Illuminate\Support\ServiceProvider;
class ThemeServiceProvider extends ServiceProvider
{
/**
* Register the service provider.
* @return void
*/
public function register()
{
$this->app->booted(function () {
$this->registerAllThemes();
$this->setActiveTheme();
});
}
/**
* Set the active theme based on the settings
*/
private function setActiveTheme()
{
if ($this->app->runningInConsole() || ! app('asgard.isInstalled')) {
return;
}
if ($this->inAdministration()) {
$themeName = $this->app['config']->get('asgard.core.core.admin-theme');
return $this->app['stylist']->activate($themeName, true);
}
$themeName = $this->app['setting.settings']->get('core::template', null, 'Flatly');
return $this->app['stylist']->activate($themeName, true);
}
/**
* Check if we are in the administration
* @return bool
*/
private function inAdministration()
{
$segment = config('laravellocalization.hideDefaultLocaleInURL', false) ? 1 : 2;
return $this->app['request']->segment($segment) === $this->app['config']->get('asgard.core.core.admin-prefix');
}
/**
* Register all themes with activating them
*/
private function registerAllThemes()
{
$directories = $this->app['files']->directories(config('stylist.themes.paths', [base_path('/Themes')])[0]);
foreach ($directories as $directory) {
$this->app['stylist']->registerPath($directory);
}
}
}
<?php
namespace Modules\Setting\Repositories\Cache;
use Modules\Core\Repositories\Cache\BaseCacheDecorator;
use Modules\Setting\Repositories\SettingRepository;
class CacheSettingDecorator extends BaseCacheDecorator implements SettingRepository
{
public function __construct(SettingRepository $setting)
{
parent::__construct();
$this->entityName = 'setting.settings';
$this->repository = $setting;
}
/**
* Create or update the settings
* @param $settings
* @return mixed
*/
public function createOrUpdate($settings)
{
$this->cache->tags($this->entityName)->flush();
return $this->repository->createOrUpdate($settings);
}
/**
* Find a setting by its name
* @param $settingName
* @return mixed
*/
public function findByName($settingName)
{
return $this->cache
->tags([$this->entityName, 'global'])
->remember("{$this->locale}.{$this->entityName}.findByName.{$settingName}", $this->cacheTime,
function () use ($settingName) {
return $this->repository->findByName($settingName);
}
);
}
/**
* Return all modules that have settings
* with its settings
* @param array|string $modules
* @return array
*/
public function moduleSettings($modules)
{
$moduleList = implode(',', $modules);
return $this->cache
->tags([$this->entityName, 'global'])
->remember("{$this->locale}.{$this->entityName}.moduleSettings.{$moduleList}", $this->cacheTime,
function () use ($modules) {
return $this->repository->moduleSettings($modules);
}
);
}
/**
* Return the saved module settings
* @param $module
* @return mixed
*/
public function savedModuleSettings($module)
{
return $this->cache
->tags([$this->entityName, 'global'])
->remember("{$this->locale}.{$this->entityName}.savedModuleSettings.{$module}", $this->cacheTime,
function () use ($module) {
return $this->repository->savedModuleSettings($module);
}
);
}
/**
* Find settings by module name
* @param string $module
* @return mixed
*/
public function findByModule($module)
{
return $this->cache
->tags([$this->entityName, 'global'])
->remember("{$this->locale}.{$this->entityName}.findByModule.{$module}", $this->cacheTime,
function () use ($module) {
return $this->repository->findByModule($module);
}
);
}
/**
* Find the given setting name for the given module
* @param string $settingName
* @return mixed
*/
public function get($settingName)
{
return $this->cache
->tags([$this->entityName, 'global'])
->remember("{$this->locale}.{$this->entityName}.get.{$settingName}", $this->cacheTime,
function () use ($settingName) {
return $this->repository->get($settingName);
}
);
}
/**
* Return the translatable module settings
* @param $module
* @return array
*/
public function translatableModuleSettings($module)
{
return $this->cache
->tags([$this->entityName, 'global'])
->remember("{$this->locale}.{$this->entityName}.translatableModuleSettings.{$module}", $this->cacheTime,
function () use ($module) {
return $this->repository->translatableModuleSettings($module);
}
);
}
/**
* Return the non translatable module settings
* @param $module
* @return array
*/
public function plainModuleSettings($module)
{
return $this->cache
->tags([$this->entityName, 'global'])
->remember("{$this->locale}.{$this->entityName}.plainModuleSettings.{$module}", $this->cacheTime,
function () use ($module) {
return $this->repository->plainModuleSettings($module);
}
);
}
}
<?php
namespace Modules\Setting\Repositories\Eloquent;
use Illuminate\Support\Facades\Config;
use Modules\Core\Repositories\Eloquent\EloquentBaseRepository;
use Modules\Setting\Events\SettingWasCreated;
use Modules\Setting\Events\SettingWasUpdated;
use Modules\Setting\Repositories\SettingRepository;
class EloquentSettingRepository extends EloquentBaseRepository implements SettingRepository
{
/**
* Update a resource
* @param $id
* @param $data
* @return mixed
*/
public function update($id, $data)
{
}
/**
* Return all settings, with the setting name as key
* @return array
*/
public function all()
{
$rawSettings = parent::all();
$settings = [];
foreach ($rawSettings as $setting) {
$settings[$setting->name] = $setting;
}
return $settings;
}
/**
* Create or update the settings
* @param $settings
* @return mixed|void
*/
public function createOrUpdate($settings)
{
$this->removeTokenKey($settings);
foreach ($settings as $settingName => $settingValues) {
if ($setting = $this->findByName($settingName)) {
$this->updateSetting($setting, $settingValues);
continue;
}
$this->createForName($settingName, $settingValues);
}
}
/**
* Remove the token from the input array
* @param $settings
*/
private function removeTokenKey(&$settings)
{
unset($settings['_token']);
}
/**
* Find a setting by its name
* @param $settingName
* @return mixed
*/
public function findByName($settingName)
{
return $this->model->where('name', $settingName)->first();
}
/**
* Create a setting with the given name
* @param string $settingName
* @param $settingValues
*/
private function createForName($settingName, $settingValues)
{
$setting = new $this->model();
$setting->name = $settingName;
if ($this->isTranslatableSetting($settingName)) {
$setting->isTranslatable = true;
$this->setTranslatedAttributes($settingValues, $setting);
event(new SettingWasCreated($settingName, true, $settingValues));
} else {
$setting->isTranslatable = false;
$setting->plainValue = $this->getSettingPlainValue($settingValues);
event(new SettingWasCreated($settingName, false, $settingValues));
}
return $setting->save();
}
/**
* Update the given setting
* @param object setting
* @param $settingValues
*/
private function updateSetting($setting, $settingValues)
{
$name = $setting->name;
if ($this->isTranslatableSetting($name)) {
$this->setTranslatedAttributes($settingValues, $setting);
event(new SettingWasUpdated($name, true, $settingValues));
} else {
$oldValues = $setting->plainValue;
$setting->plainValue = $this->getSettingPlainValue($settingValues);
event(new SettingWasUpdated($name, true, $settingValues, $oldValues));
}
return $setting->save();
}
/**
* @param $settingValues
* @param $setting
*/
private function setTranslatedAttributes($settingValues, $setting)
{
foreach ($settingValues as $lang => $value) {
$setting->translateOrNew($lang)->value = $value;
}
}
/**
* Return all modules that have settings
* with its settings
* @param array|string $modules
* @return array
*/
public function moduleSettings($modules)
{
if (is_string($modules)) {
return config('asgard.' . strtolower($modules) . ".settings");
}
$modulesWithSettings = [];
foreach ($modules as $module) {
if ($moduleSettings = config('asgard.' . strtolower($module->getName()) . ".settings")) {
$modulesWithSettings[$module->getName()] = $moduleSettings;
}
}
return $modulesWithSettings;
}
/**
* Return the saved module settings
* @param $module
* @return mixed
*/
public function savedModuleSettings($module)
{
$moduleSettings = [];
foreach ($this->findByModule($module) as $setting) {
$moduleSettings[$setting->name] = $setting;
}
return $moduleSettings;
}
/**
* Find settings by module name
* @param string $module Module name
* @return mixed
*/
public function findByModule($module)
{
return $this->model->where('name', 'LIKE', $module . '::%')->get();
}
/**
* Find the given setting name for the given module
* @param string $settingName
* @return mixed
*/
public function get($settingName)
{
return $this->model->where('name', 'LIKE', "{$settingName}")->first();
}
/**
* Return the translatable module settings
* @param $module
* @return mixed
*/
public function translatableModuleSettings($module)
{
return array_filter($this->moduleSettings($module), function ($setting) {
return isset($setting['translatable']) && $setting['translatable'] === true;
});
}
/**
* Return the non translatable module settings
* @param $module
* @return array
*/
public function plainModuleSettings($module)
{
return array_filter($this->moduleSettings($module), function ($setting) {
return !isset($setting['translatable']) || $setting['translatable'] === false;
});
}
/**
* Return a setting name using dot notation: asgard.{module}.settings.{settingName}
* @param string $settingName
* @return string
*/
private function getConfigSettingName($settingName)
{
list($module, $setting) = explode('::', $settingName);
return "asgard.{$module}.settings.{$setting}";
}
/**
* Check if the given setting name is translatable
* @param string $settingName
* @return bool
*/
private function isTranslatableSetting($settingName)
{
$configSettingName = $this->getConfigSettingName($settingName);
$setting = config("$configSettingName");
return isset($setting['translatable']) && $setting['translatable'] === true;
}
/**
* Return the setting value(s). If values are ann array, json_encode them
* @param string|array $settingValues
* @return string
*/
private function getSettingPlainValue($settingValues)
{
if (is_array($settingValues)) {
return json_encode($settingValues);
}
return $settingValues;
}
}
<?php
namespace Modules\Setting\Repositories;
use Modules\Core\Repositories\BaseRepository;
interface SettingRepository extends BaseRepository
{
/**
* Create or update the settings
* @param $settings
* @return mixed
*/
public function createOrUpdate($settings);
/**
* Find a setting by its name
* @param $settingName
* @return mixed
*/
public function findByName($settingName);
/**
* Return all modules that have settings
* with its settings
* @param array|string $modules
* @return array
*/
public function moduleSettings($modules);
/**
* Return the saved module settings
* @param $module
* @return mixed
*/
public function savedModuleSettings($module);
/**
* Find settings by module name
* @param string $module
* @return mixed
*/
public function findByModule($module);
/**
* Find the given setting name for the given module
* @param string $settingName
* @return mixed
*/
public function get($settingName);
/**
* Return the translatable module settings
* @param $module
* @return array
*/
public function translatableModuleSettings($module);
/**
* Return the non translatable module settings
* @param $module
* @return array
*/
public function plainModuleSettings($module);
}
<div class="checkbox">
<label for="{{ $settingName }}">
<input id="{{ $settingName }}"
name="{{ $settingName }}"
type="checkbox"
class="flat-blue"
{{ isset($dbSettings[$settingName]) && (bool)$dbSettings[$settingName]->plainValue == true ? 'checked' : '' }}
value="1" />
{{ trans($moduleInfo['description']) }}
</label>
</div>
<div class='form-group'>
{!! Form::label($settingName, $moduleInfo['description']) !!}
<?php if (isset($dbSettings[$settingName])): ?>
{!! Form::input('number', $settingName, old($settingName, $dbSettings[$settingName]->plainValue), ['class' => 'form-control', 'placeholder' => trans($moduleInfo['description'])]) !!}
<?php else: ?>
{!! Form::input('number', $settingName, old($settingName), ['class' => 'form-control', 'placeholder' => trans($moduleInfo['description'])]) !!}
<?php endif; ?>
</div>
<div class="checkbox">
<?php foreach ($moduleInfo['options'] as $value => $optionName): ?>
<label for="{{ $optionName }}">
<input id="{{ $optionName }}"
name="{{ $settingName }}"
type="radio"
class="flat-blue"
{{ isset($dbSettings[$settingName]) && (bool)$dbSettings[$settingName]->plainValue == $value ? 'checked' : '' }}
value="{{ $value }}" />
{{ trans($optionName) }}
</label>
<?php endforeach; ?>
</div>
<div class='form-group'>
{!! Form::label($settingName, trans($moduleInfo['description'])) !!}
<?php if (isset($dbSettings[$settingName])): ?>
{!! Form::text($settingName, old($settingName, $dbSettings[$settingName]->plainValue), ['class' => 'form-control', 'placeholder' => trans($moduleInfo['description'])]) !!}
<?php else: ?>
{!! Form::text($settingName, old($settingName), ['class' => 'form-control', 'placeholder' => trans($moduleInfo['description'])]) !!}
<?php endif; ?>
</div>
<div class='form-group'>
{!! Form::label($settingName, trans($moduleInfo['description'])) !!}
<?php if (isset($dbSettings[$settingName])): ?>
{!! Form::textarea($settingName, old($settingName, $dbSettings[$settingName]->plainValue), ['class' => 'form-control', 'placeholder' => trans($moduleInfo['description'])]) !!}
<?php else: ?>
{!! Form::textarea($settingName, old($settingName), ['class' => 'form-control', 'placeholder' => trans($moduleInfo['description'])]) !!}
<?php endif; ?>
</div>
<div class='form-group'>
{!! Form::label($settingName, trans($moduleInfo['description'])) !!}
<?php if (isset($dbSettings[$settingName])): ?>
{!! Form::textarea($settingName, old($settingName, $dbSettings[$settingName]->plainValue), ['class' => 'form-control ckeditor', 'placeholder' => trans($moduleInfo['description'])]) !!}
<?php else: ?>
{!! Form::textarea($settingName, old($settingName), ['class' => 'form-control ckeditor', 'placeholder' => trans($moduleInfo['description'])]) !!}
<?php endif; ?>
</div>
<div class="checkbox">
<?php $oldValue = (isset($dbSettings[$settingName]) && $dbSettings[$settingName]->hasTranslation($lang)) ? $dbSettings[$settingName]->translate($lang)->value : ''; ?>
<label for="{{ $settingName . "[$lang]" }}">
<input id="{{ $settingName . "[$lang]" }}"
name="{{ $settingName . "[$lang]" }}"
type="checkbox"
class="flat-blue"
{{ isset($dbSettings[$settingName]) && (bool)$oldValue == true ? 'checked' : '' }}
value="1" />
{{ trans($moduleInfo['description']) }}
</label>
</div>
<div class='form-group'>
{!! Form::label($settingName . "[$lang]", trans($moduleInfo['description'])) !!}
<?php if (isset($dbSettings[$settingName])): ?>
<?php $value = $dbSettings[$settingName]->hasTranslation($lang) ? $dbSettings[$settingName]->translate($lang)->value : ''; ?>
{!! Form::input('number', $settingName . "[$lang]", old($settingName . "[$lang]", $value), ['class' => 'form-control', 'placeholder' => trans($moduleInfo['description'])]) !!}
<?php else: ?>
{!! Form::input('number', $settingName . "[$lang]", old($settingName . "[$lang]"), ['class' => 'form-control', 'placeholder' => trans($moduleInfo['description'])]) !!}
<?php endif; ?>
</div>
<div class="checkbox">
<?php foreach ($moduleInfo['options'] as $value => $optionName): ?>
<?php $oldValue = (isset($dbSettings[$settingName]) && $dbSettings[$settingName]->hasTranslation($lang)) ? $dbSettings[$settingName]->translate($lang)->value : ''; ?>
<label for="{{ $optionName . "[$lang]" }}">
<input id="{{ $optionName . "[$lang]" }}"
name="{{ $settingName . "[$lang]" }}"
type="radio"
class="flat-blue"
{{ isset($dbSettings[$settingName]) && (bool)$oldValue == $value ? 'checked' : '' }}
value="{{ $value }}" />
{{ trans($optionName) }}
</label>
<?php endforeach; ?>
</div>
<div class='form-group'>
{!! Form::label($settingName . "[$lang]", trans($moduleInfo['description'])) !!}
<?php if (isset($dbSettings[$settingName])): ?>
<?php $value = $dbSettings[$settingName]->hasTranslation($lang) ? $dbSettings[$settingName]->translate($lang)->value : ''; ?>
{!! Form::text($settingName . "[$lang]", old($settingName . "[$lang]", $value), ['class' => 'form-control', 'placeholder' => trans($moduleInfo['description'])]) !!}
<?php else: ?>
{!! Form::text($settingName . "[$lang]", old($settingName . "[$lang]"), ['class' => 'form-control', 'placeholder' => trans($moduleInfo['description'])]) !!}
<?php endif; ?>
</div>
<div class='form-group'>
{!! Form::label($settingName . "[$lang]", trans($moduleInfo['description'])) !!}
<?php if (isset($dbSettings[$settingName])): ?>
<?php $value = $dbSettings[$settingName]->hasTranslation($lang) ? $dbSettings[$settingName]->translate($lang)->value : ''; ?>
{!! Form::textarea($settingName . "[$lang]", old($settingName . "[$lang]", $value), ['class' => 'form-control', 'placeholder' => trans($moduleInfo['description'])]) !!}
<?php else: ?>
{!! Form::textarea($settingName . "[$lang]", old($settingName . "[$lang]"), ['class' => 'form-control', 'placeholder' => trans($moduleInfo['description'])]) !!}
<?php endif; ?>
</div>
<div class='form-group'>
{!! Form::label($settingName . "[$lang]", trans($moduleInfo['description'])) !!}
<?php if (isset($dbSettings[$settingName])): ?>
<?php $value = $dbSettings[$settingName]->hasTranslation($lang) ? $dbSettings[$settingName]->translate($lang)->value : ''; ?>
{!! Form::textarea($settingName . "[$lang]", old($settingName . "[$lang]", $value), ['class' => 'form-control ckeditor', 'placeholder' => trans($moduleInfo['description'])]) !!}
<?php else: ?>
{!! Form::textarea($settingName . "[$lang]", old($settingName . "[$lang]"), ['class' => 'form-control ckeditor', 'placeholder' => trans($moduleInfo['description'])]) !!}
<?php endif; ?>
</div>
@extends('layouts.master')
@section('content-header')
<h1>
{{ trans('setting::settings.title.module name settings', ['module' => ucfirst($currentModule)]) }}
</h1>
<ol class="breadcrumb">
<li><a href="#"><i class="fa fa-dashboard"></i> {{ trans('core::core.breadcrumb.home') }}</a></li>
<li><a href="{{ URL::route('admin.setting.settings.index') }}"><i class="fa fa-cog"></i> {{ trans('setting::settings.breadcrumb.settings') }}</a></li>
<li class="active"><i class="fa fa-cog"></i> {{ trans('setting::settings.breadcrumb.module settings', ['module' => ucfirst($currentModule)]) }}</li>
</ol>
@stop
@section('content')
{!! Form::open(['route' => ['admin.setting.settings.store'], 'method' => 'post']) !!}
<div class="row">
<div class="sidebar-nav col-sm-2">
<div class="box box-primary">
<div class="box-header">
<h3 class="box-title">{{ trans('setting::settings.title.module settings') }}</h3>
</div>
<style>
a.active {
text-decoration: none;
background-color: #eee;
}
</style>
<ul class="nav nav-list">
<?php foreach ($modulesWithSettings as $module => $settings): ?>
<li>
<a href="{{ URL::route('dashboard.module.settings', [$module]) }}"
class="{{ $module == $currentModule->getLowerName() ? 'active' : '' }}">
{{ ucfirst($module) }}
<small class="badge pull-right bg-blue">{{ count($settings) }}</small>
</a>
</li>
<?php endforeach; ?>
</ul>
</div>
</div>
<div class="col-md-10">
<?php if ($translatableSettings): ?>
<div class="box box-primary">
<div class="box-header">
<h3 class="box-title">{{ trans('core::core.title.translatable fields') }}</h3>
</div>
<div class="box-body">
<div class="nav-tabs-custom">
@include('partials.form-tab-headers')
<div class="tab-content">
<?php $i = 0; ?>
<?php foreach (LaravelLocalization::getSupportedLocales() as $locale => $language): ?>
<?php $i++; ?>
<div class="tab-pane {{ App::getLocale() == $locale ? 'active' : '' }}" id="tab_{{ $i }}">
@include('setting::admin.partials.fields', ['settings' => $translatableSettings])
</div>
<?php endforeach; ?>
</div>
</div>
</div>
</div>
<?php endif; ?>
<?php if ($plainSettings): ?>
<div class="box box-primary">
<div class="box-header">
<h3 class="box-title">{{ trans('core::core.title.non translatable fields') }}</h3>
</div>
<div class="box-body">
@include('setting::admin.partials.fields', ['settings' => $plainSettings])
</div>
</div>
<?php endif; ?>
<div class="box-footer">
<button type="submit" class="btn btn-primary btn-flat">{{ trans('core::core.button.update') }}</button>
<button class="btn btn-default btn-flat" name="button" type="reset">{{ trans('core::core.button.reset') }}</button>
<a class="btn btn-danger pull-right btn-flat" href="{{ URL::route('admin.setting.settings.index')}}"><i class="fa fa-times"></i> {{ trans('core::core.button.cancel') }}</a>
</div>
</div>
</div>
{!! Form::close() !!}
@stop
@section('scripts')
<script>
$( document ).ready(function() {
$('input[type="checkbox"].flat-blue, input[type="radio"].flat-blue').iCheck({
checkboxClass: 'icheckbox_flat-blue',
radioClass: 'iradio_flat-blue'
});
$('input[type="checkbox"]').on('ifChecked', function(){
$(this).parent().find('input[type=hidden]').remove();
});
$('input[type="checkbox"]').on('ifUnchecked', function(){
var name = $(this).attr('name'),
input = '<input type="hidden" name="' + name + '" value="0" />';
$(this).parent().append(input);
});
});
</script>
@stop
<?php foreach ($settings as $settingName => $moduleInfo): ?>
<?php $type = array_get($moduleInfo, 'translatable', false) ? 'translatable' : 'plain' ?>
<?php $fieldView = str_contains($moduleInfo['view'], '::') ? $moduleInfo['view'] : "setting::admin.fields.$type.{$moduleInfo['view']}" ?>
<?php $locale = isset($locale) ? $locale : '' ?>
@include($fieldView, [
'lang' => $locale,
'settings' => $settings,
'setting' => $settingName,
'moduleInfo' => $moduleInfo,
'settingName' => strtolower($currentModule) . '::' . $settingName
])
<?php endforeach;
<?php
namespace Modules\Setting\Sidebar;
use Maatwebsite\Sidebar\Group;
use Maatwebsite\Sidebar\Item;
use Maatwebsite\Sidebar\Menu;
use Modules\User\Contracts\Authentication;
class SidebarExtender implements \Maatwebsite\Sidebar\SidebarExtender
{
/**
* @var Authentication
*/
protected $auth;
/**
* @param Authentication $auth
*
* @internal param Guard $guard
*/
public function __construct(Authentication $auth)
{
$this->auth = $auth;
}
/**
* @param Menu $menu
*
* @return Menu
*/
public function extendWith(Menu $menu)
{
$menu->group(trans('workshop::workshop.title'), function (Group $group) {
$group->item(trans('setting::settings.title.settings'), function (Item $item) {
$item->icon('fa fa-cog');
$item->weight(50);
$item->route('admin.setting.settings.index');
$item->authorize(
$this->auth->hasAccess('setting.settings.index')
);
});
});
return $menu;
}
}
<?php
namespace Modules\Setting\Support;
use Modules\Setting\Contracts\Setting;
use Modules\Setting\Repositories\SettingRepository;
class Settings implements Setting
{
/**
* @var SettingRepository
*/
private $setting;
/**
* @param SettingRepository $setting
*/
public function __construct(SettingRepository $setting)
{
$this->setting = $setting;
}
/**
* Getting the setting
* @param string $name
* @param string $locale
* @param string $default
* @return mixed
*/
public function get($name, $locale = null, $default = null)
{
$defaultFromConfig = $this->getDefaultFromConfigFor($name);
$setting = $this->setting->findByName($name);
if (! $setting) {
return is_null($default) ? $defaultFromConfig : $default;
}
if ($setting->isTranslatable) {
if ($setting->hasTranslation($locale)) {
return empty($setting->translate($locale)->value) ? $defaultFromConfig : $setting->translate($locale)->value;
}
} else {
return empty($setting->plainValue) ? $defaultFromConfig : $setting->plainValue;
}
return $defaultFromConfig;
}
/**
* Determine if the given configuration value exists.
*
* @param string $name
* @return bool
*/
public function has($name)
{
$default = microtime(true);
return $this->get($name, null, $default) !== $default;
}
/**
* Set a given configuration value.
*
* @param string $key
* @param mixed $value
* @return \Modules\Setting\Entities\Setting
*/
public function set($key, $value)
{
return $this->setting->create([
'name' => $key,
'plainValue' => $value,
]);
}
/**
* Get the default value from the settings configuration file,
* for the given setting name.
* @param string $name
* @return string
*/
private function getDefaultFromConfigFor($name)
{
list($module, $settingName) = explode('::', $name);
return config("asgard.$module.settings.$settingName.default", '');
}
}
<?php
namespace Modules\Setting\Tests;
use Illuminate\Contracts\Console\Kernel;
use Illuminate\Database\Eloquent\Model;
use Maatwebsite\Sidebar\SidebarServiceProvider;
use Modules\Setting\Providers\SettingServiceProvider;
use Modules\Setting\Repositories\SettingRepository;
use Orchestra\Testbench\TestCase;
abstract class BaseSettingTest extends TestCase
{
/**
* @var SettingRepository
*/
protected $settingRepository;
public function setUp()
{
parent::setUp();
$this->resetDatabase();
$this->settingRepository = app(SettingRepository::class);
}
protected function getPackageProviders($app)
{
return [
SettingServiceProvider::class,
SidebarServiceProvider::class,
];
}
protected function getEnvironmentSetUp($app)
{
$app['path.base'] = __DIR__ . '/..';
$app['config']->set('database.default', 'sqlite');
$app['config']->set('database.connections.sqlite', array(
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
));
$app['config']->set('asgard.core.settings', [
'site-name' => [
'description' => 'core::settings.site-name',
'view' => 'text',
'translatable' => true,
],
'template' => [
'description' => 'core::settings.template',
'view' => 'core::fields.select-theme',
],
'locales' => [
'description' => 'core::settings.locales',
'view' => 'core::fields.select-locales',
'translatable' => false,
],
]);
}
protected function getPackageAliases($app)
{
return ['Eloquent' => Model::class];
}
private function resetDatabase()
{
// Makes sure the migrations table is created
$this->artisan('migrate', [
'--database' => 'sqlite',
]);
// We empty all tables
$this->artisan('migrate:reset', [
'--database' => 'sqlite',
]);
// Migrate
$this->artisan('migrate', [
'--database' => 'sqlite',
]);
}
}
<?php
namespace Modules\Setting\Tests;
class EloquentSettingRepositoryTest extends BaseSettingTest
{
public function setUp()
{
parent::setUp();
}
/** @test */
public function it_creates_translated_setting()
{
// Prepare
$data = [
'core::site-name' => [
'en' => 'AsgardCMS_en',
'fr' => 'AsgardCMS_fr',
],
];
// Run
$this->settingRepository->createOrUpdate($data);
// Assert
$setting = $this->settingRepository->find(1);
$this->assertEquals('core::site-name', $setting->name);
$this->assertEquals('AsgardCMS_en', $setting->translate('en')->value);
$this->assertEquals('AsgardCMS_fr', $setting->translate('fr')->value);
}
/** @test */
public function it_creates_plain_setting()
{
// Prepare
$data = [
'core::template' => 'asgard',
];
// Run
$this->settingRepository->createOrUpdate($data);
// Assert
$setting = $this->settingRepository->find(1);
$this->assertEquals('core::template', $setting->name);
$this->assertEquals('asgard', $setting->plainValue);
}
/** @test */
public function it_finds_setting_by_name()
{
// Prepare
$data = [
'core::site-name' => [
'en' => 'AsgardCMS_en',
'fr' => 'AsgardCMS_fr',
],
];
// Run
$this->settingRepository->createOrUpdate($data);
// Assert
$setting = $this->settingRepository->findByName('core::site-name');
$this->assertEquals('core::site-name', $setting->name);
$this->assertEquals('AsgardCMS_en', $setting->translate('en')->value);
$this->assertEquals('AsgardCMS_fr', $setting->translate('fr')->value);
}
/** @test */
public function it_returns_module_settings()
{
// Prepare
$data = [
'core::site-name' => [
'en' => 'AsgardCMS_en',
'fr' => 'AsgardCMS_fr',
],
'core::template' => 'asgard',
'blog::posts-per-page' => 10,
];
// Run
$this->settingRepository->createOrUpdate($data);
// Assert
$blogSettings = $this->settingRepository->findByModule('blog');
$this->assertEquals(1, $blogSettings->count());
$coreSettings = $this->settingRepository->findByModule('core');
$this->assertEquals(2, $coreSettings->count());
}
/** @test */
public function it_encodes_array_of_non_translatable_data()
{
// Prepare
$data = [
'core::locales' => [
"su",
"bi",
"bs",
],
];
// Run
$this->settingRepository->createOrUpdate($data);
// Assert
$setting = $this->settingRepository->find(1);
$this->assertEquals('core::locales', $setting->name);
$this->assertEquals('["su","bi","bs"]', $setting->plainValue);
}
}
<?php
namespace Modules\Setting\Tests;
class SettingsTest extends BaseSettingTest
{
/**
* @var \Modules\Setting\Support\Settings
*/
protected $setting;
public function setUp()
{
parent::setUp();
$this->setting = app('Modules\Setting\Support\Settings');
}
/** @test */
public function it_gets_a_setting_without_locale()
{
// Prepare
$data = [
'core::site-name' => [
'en' => 'AsgardCMS_en',
'fr' => 'AsgardCMS_fr',
],
'core::template' => 'asgard',
'blog::posts-per-page' => 10,
];
// Run
$this->settingRepository->createOrUpdate($data);
// Assert
$setting = $this->setting->get('core::site-name');
$this->assertEquals('AsgardCMS_en', $setting);
}
/** @test */
public function it_gets_setting_in_given_locale()
{
// Prepare
$data = [
'core::site-name' => [
'en' => 'AsgardCMS_en',
'fr' => 'AsgardCMS_fr',
],
'core::template' => 'asgard',
'blog::posts-per-page' => 10,
];
// Run
$this->settingRepository->createOrUpdate($data);
// Assert
$setting = $this->setting->get('core::site-name', 'fr');
$this->assertEquals('AsgardCMS_fr', $setting);
}
/** @test */
public function it_returns_a_default_value_if_no_setting_found()
{
// Prepare
$setting = $this->setting->get('core::non-existing-setting', 'en', 'defaultValue');
// Assert
$this->assertEquals('defaultValue', $setting);
}
}
url: https://github.com/AsgardCms/Setting
versions:
"2.0@unreleased":
added:
- Laravel 5.2 compatibility
- Add ability to set a plain setting value via <code>Modules\Setting\Support\Settings</code>
- new <code>@setting()</code> blade directive
changed:
- Using new more flexible way of handle permissions via middleware
removed:
- Removing laracasts/flash dependency
- <code>Setting</code> contract has been moved to the Setting module
"1.14.0":
changed:
- Use <code>$router</code> variable in routes file
"1.13.1":
changed:
- Use the findByName method to find a setting
"1.13.0":
changed:
- Removed language files, they are now in the translation module
added:
- Adding a wysiwyg settings field.
"1.12.1":
changed:
- Manual inclusing of iCheck css file has been removed
"1.12.0":
changed:
- Make setting name unique in database
"1.11.0":
added:
- Added Russian translations
changed:
- Improving german translations
"1.10.0":
added:
- Chinese Simplified language
"1.9.0":
added:
- Dutch and Portuguese language
"1.8.0":
added:
- Spanish translations
"1.7.0":
added:
- Added portuguese translations
"1.6.0":
added:
- Adding a <code>CacheSettingDecorator</code> class which handles the caching correctly
"1.5.0":
changed:
- Set default theme location
- Use the global <code>isInstalled</code> method
"1.4.0":
changed:
- Use the helper functions in controller
- Use manual route definition over the route resource shortcut
"1.3.0":
added:
- Adding a setting helper function, <code>setting()</code>
"1.2.1":
changed:
- Do not cache the theme directories
"1.2.0":
changed:
- Clearing the settings cache on create / update
"1.1.1":
changed:
- Removing unused <code>start.php</code> file
"1.1.0":
changed:
- Adding table engine into migrations
"1.0.9":
changed:
- Require stable version of Doctrine/Dbal
"1.0.8":
"1.0.7":
added:
- Using new sidebar extender class
removed:
- Old SidebarViewComposer
"1.0.6":
changed:
- Get a default value from settings configuration file if setting is empty or not set
"1.0.5":
changed:
- Fixing radio and checkbox field settings not being defined at first use
"1.0.4":
changed:
- Changing the settings value fields to TEXT type, using doctrine/dbal to make it work in all db drivers
"1.0.3":
changed:
- Changing the settings value fields to TEXT type
"1.0.2":
changed:
- Adding changelog file
"1.0.1":
changed:
- Using tagged versions of modules
"1.0.0":
changed:
- Initial release
{
"name": "asgardcms/setting-module",
"type": "asgard-module",
"description": "Setting module for AsgardCMS. Handles all the site settings.",
"keywords": [
"asgardcms",
"settings"
],
"license": "MIT",
"authors": [
{
"name": "Nicolas Widart",
"email": "info@asgardcms.com",
"role": "Developer"
}
],
"support": {
"email": "support@asgardcms.com",
"issues": "https://github.com/AsgardCms/Platform/issues",
"source": "https://github.com/AsgardCms/Setting"
},
"require": {
"php": ">=5.6",
"composer/installers": "~1.0",
"asgardcms/core-module": "~2.0",
"doctrine/dbal": "~2.5"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"orchestra/testbench": "3.3.*",
"phpro/grumphp": "^0.9.1",
"friendsofphp/php-cs-fixer": "^1.11"
},
"autoload-dev": {
"psr-4": {
"Modules\\Setting\\": ".",
"Modules\\": "Modules/"
}
},
"extra": {
"branch-alias": {
"dev-2.0": "2.0.x-dev"
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
parameters:
git_dir: .
bin_dir: vendor/bin
stop_on_failure: true
tasks:
phpcsfixer:
config_file: .php_cs
composer:
file: ./composer.json
jsonlint:
ignore_patterns: []
<?php
if (! function_exists('setting')) {
function setting($name, $locale = null, $default = null)
{
return app('setting.settings')->get($name, $locale, $default);
}
}
{
"name": "Setting",
"alias": "setting",
"description": "Module for handling all site settings.",
"keywords": [
"asgardcms",
"settings"
],
"version": "2.0.0",
"active": 1,
"order": 1,
"providers": [
"Modules\\Setting\\Providers\\SettingServiceProvider",
"Modules\\Setting\\Providers\\ThemeServiceProvider",
"Modules\\Setting\\Providers\\RouteServiceProvider",
"Modules\\Setting\\Providers\\EventServiceProvider"
],
"aliases": {
"Setting": "Modules\\Setting\\Facades\\Settings",
"SettingDirective": "Modules\\Setting\\Blade\\Facades\\SettingDirective"
},
"files": [
"helpers.php"
]
}
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./Tests/</directory>
</testsuite>
</testsuites>
</phpunit>
# Setting Module
[![Latest Version](https://img.shields.io/github/release/asgardcms/setting.svg?style=flat-square)](https://github.com/asgardcms/setting/releases)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
[![Quality Score](https://img.shields.io/scrutinizer/g/asgardcms/setting.svg?style=flat-square)](https://scrutinizer-ci.com/g/asgardcms/setting)
[![SensioLabs Insight](https://img.shields.io/sensiolabs/i/92d544b4-a3ca-4c2a-9ffd-0741c521cb14.svg)](https://insight.sensiolabs.com/projects/92d544b4-a3ca-4c2a-9ffd-0741c521cb14)
[![CodeClimate](https://img.shields.io/codeclimate/github/AsgardCms/Setting.svg)](https://codeclimate.com/github/AsgardCms/Setting)
[![Total Downloads](https://img.shields.io/packagist/dd/asgardcms/setting-module.svg?style=flat-square)](https://packagist.org/packages/asgardcms/setting-module)
[![Total Downloads](https://img.shields.io/packagist/dm/asgardcms/setting-module.svg?style=flat-square)](https://packagist.org/packages/asgardcms/setting-module)
[![Total Downloads](https://img.shields.io/packagist/dt/asgardcms/setting-module.svg?style=flat-square)](https://packagist.org/packages/asgardcms/setting-module)
[![Slack](http://slack.asgardcms.com/badge.svg)](http://slack.asgardcms.com/)
| Branch | Travis-ci |
| ---------------- | --------------- |
| master | [![Build Status](https://travis-ci.org/AsgardCms/Setting.svg?branch=master)](https://travis-ci.org/AsgardCms/Setting) |
## Resources
- [Contribute to AsgardCMS](https://asgardcms.com/en/docs/getting-started/contributing)
- [License](LICENSE.md)
- [Documentation](http://asgardcms.com/docs/setting-module/adding-settings)
## Info
All AsgardCMS modules respect [Semantic Versioning](http://semver.org/).
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment