承接 kenarkose/settlement 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

kenarkose/settlement

最新稳定版本:2.0.0

Composer 安装命令:

composer require kenarkose/settlement

包简介

Framework Agnostic Persistent Typed and Group-able Settings with JSON Driver

README 文档

README

Framework Agnostic Persistent Typed and Group-able Settings with JSON Driver.

Build Status Total Downloads Latest Stable Version License

Settlement provides a simple solution for persistent settings with support for types and groups.

Features

  • Flexible API for persistent settings
  • Configurable JSON driver
  • Grouped and typed settings
  • Group and type validation
  • Service provider for Laravel 5
  • A phpunit test suite for easy development

Installation

Installing Settlement is simple. Just pull the package in through Composer.

{
    "require": {
        "kenarkose/settlement": "~2.0"
    }
}

Usage

Instantiate a new JSON repository with path and filename and you are good to go.

use Kenarkose\Settlement\Repository\JSONRepository;

$settings = new JSONRepository('path/to', 'settings.json');

Here is a list of methods that are defined by the repository interface.


$settings->set('foo', 'bar');
$settings->set('foo', 42, null, 'number');
$settings->set('foo', 'bar', 'Label', 'text', 'baz_group');

$settings->get('foo'); // 'bar'

$settings->getComplete('foo');
// ['value' => 'bar', 'label' =>'Label', 'type' => 'text', 'group' => 'baz_group']

$setting->has('foo'); // true

$setting->delete('foo');

$setting->getGroup('baz_group'); // Name of the Baz Group

$setting->setGroup('foo_group', 'Name of the Foo Group');

$setting->hasGroup('foo_group'); // true

$setting->getGroupSettings('baz_group');
// ['foo' => ['value' => 'bar', 'label' => 'Label', 'type' => 'string', 'group' => 'baz_group']]

$setting->deleteGroup('foo_group');

$setting->flush();

Additionally, you may use other methods that is provided by the JSONRepository.


$setting->path(); // Returns current path
$setting->path('new/path'); // Sets a new path

$setting->filename(); // Returns current filename
$setting->filename('config.json'); // Sets a new filename

$setting->settings(); // Returns all stored settings
$setting->settings(
    ['foo' => ['value' => 'bar', 'type' => 'string', 'group' => null]
); // Replaces stored settings

$setting->groups(); // Returns all stored groups
$setting->groups(
    ['dummy' => 'Dummy Group']
); // Replaces stored groups

$setting->stored(); // Returns all stored information
$setting->stored([
    'settings' => [...],
    'groups' => [...]
]); // Replaces all stored information

$setting->load(); // Loads from current path and filename
$setting->load('new/path', 'config.json'); // Loads from new path and filename

$setting->save(); // Saves to current path and filename
$setting->save('new/path', 'config.json'); // Saves to new path and filename

For more options you may refer to source code and tests as Settlement is well tested and documented.

For Laravel Users

The Settlement Service Provider for Laravel 5 registers the default LaravelJSONRepository, the Facade, and the settings() helper.

Laravel Installation

  1. In order to register Settlement Service Provider add 'Kenarkose\Settlement\Provider\Laravel\SettlementServiceProvider' to the end of providers array in your config/app.php file.

    'providers' => array(
    
        'Illuminate\Foundation\Providers\ArtisanServiceProvider',
        'Illuminate\Auth\AuthServiceProvider',
        ...
        'Kenarkose\Settlement\Provider\Laravel\SettlementServiceProvider',
    
    ),
  2. You may access the services provided by Settlement by using the supplied Facade.

    Settings::get('foo');
    
    Settings::set('bar', 'baz');

    In order to register the Facade add 'Settings' => 'Kenarkose\Settlement\Provider\Laravel\Settings' to the end of aliases array in your config/app.php file.

    'aliases' => array(
    
        'App'        => 'Illuminate\Support\Facades\App',
        'Artisan'    => 'Illuminate\Support\Facades\Artisan',
        ...
        'Settings' => 'Kenarkose\Settlement\Provider\Laravel\Settings',
    
    ),
  3. A helper function is also provided if the Facade is not preferred.

    settings(); // Returns the repository
    
    // Getting a value
    settings('foo'); // is the same as settings()->get('foo');
    
    // Setting a value
    settings('foo', 'bar'); // is the same as settings()->set('foo', 'bar');
    // Other possible derivations of setting
    settings('foo', 'bar', 'string');
    settings('foo', 'bar', 'string', 'group');
  4. Finally, you may customize Settlement's behavior by publishing the configuration file. To do so, use the following command.

    php artisan vendor:publish

    Than, you will find the configuration file on the config/settlement.php path.

License

Settlement is released under MIT License.

统计信息

  • 总下载量: 770
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-08-20