skyline/default-setting

This package is not installable via Composer 1.x, please make sure you upgrade to Composer 2+. Read more about our Composer 1.x deprecation policy.

v0.8.2 2021-01-09 11:05 UTC

This package is auto-updated.

Last update: 2021-10-09 12:52:40 UTC


README

The setup package is a simple controller of one PDO table holding dynamical settings for your application.

Installation

$ composer require skyline/default-setting

Usage

Fist you need to create an SQL table containing at least the following fields:

  1. id
    Identifies each entry uniquely
  2. name
    the name of the setting
  3. content
    The content of the setting
  4. multiple
    Specifies, if the entry is multiple (contents of settings with the same name are sacked)

You can design the table how you want.

Now in PHP see below how you can access the settings:

<?php
use Skyline\Setup\DefaultSetting;

$setup = DefaultSetting::getDefaultSetting();
echo $setup->getSetting('my-setting', /* default value */ 'not-available');

// Defining a setting, see below
$setup->setSetting('my-setting', /* value */ 13, /* temporary */ false, /* multiple */ false);
// Passing true to temporary will only update the value for the current request, while passing false writes the passed value into the database persistently.

// Removes the setting
$setup->removeSetting('my-setting', /* temporary */ false);
// Again passing false to temporary will remove the setting from the database as well.

See below how you can use a custom setting tool:

<?php
use Skyline\Setup\AbstractSetting;

class MySetting extends AbstractSetting {
    // Adjust the sql table field names
    const RECORD_ID_KEY = 'customized_id';
    const RECORD_NAME_KEY = 'customized_name';
    const RECORD_CONTENT_KEY = 'customized_content';
    const RECORD_MULTIPLE_KEY = 'customized_multiple';
    
    protected function getTableName() : string{
        return "MY_TABLE_NAME";
    }
}