定制 scriptoshi/settings 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

scriptoshi/settings

最新稳定版本:1.0.0

Composer 安装命令:

composer require scriptoshi/settings

包简介

Flexible setting manager for scriptoshi based applications

README 文档

README

Scriptoshi Scripts

scriptoshi/settings is a flexible and powerful settings manager for Laravel Scriptoshi applications. This package allows you to easily manage configuration settings with support for caching, grouping, and dynamic retrieval.

Features

  • Easily store and retrieve settings in Scriptoshi Scripts.
  • Cache settings for optimized performance.
  • Group settings based on categories.
  • Supports multiple formats for values (including JSON and booleans).
  • Simple facade-based API for accessing settings.
  • Laravel 11+ compatible.

Installation

You can install the package via Composer:

composer require scriptoshi/settings

Configuration

Once installed, the package will automatically register the service provider.

You can publish the package's configuration file using the command:

php artisan vendor:publish --provider="Scriptoshi\Settings\SettingServiceProvider"

Usage

You can use the Setting facade or the Settings class directly to interact with your settings.

Retrieving Settings

Get a single setting:

use Scriptoshi\Settings\Facades\Setting;

$value = Setting::get('setting_name');

Get a setting with a default value:

$value = Setting::get('setting_name', 'default_value');

Get all settings:

$settings = Setting::all();

Get settings grouped by their group name:

$groupedSettings = Setting::group();

Get settings by group:

$groupSettings = Setting::for('group_name');

Storing Settings

Store or update a single setting:

Setting::set('setting_name', 'value');

Store multiple settings at once:

Setting::set([
    'setting_1' => 'value1',
    'setting_2' => 'value2',
]);

Caching Settings

Settings are cached by default to reduce database queries. You can manually refresh the cache with:

Setting::refresh();

Facade

The package includes a Setting facade for easy usage. The following methods are available:

  • Setting::get($key, $default = null, $fresh = false) – Retrieve a setting.
  • Setting::set($key, $value) – Store or update a setting.
  • Setting::all($fresh = false) – Retrieve all settings.
  • Setting::group($fresh = false) – Retrieve settings grouped by their category.
  • Setting::for($group) – Retrieve settings for a specific group.
  • Setting::json($group) – Retrieve settings for a specific group as JSON.
  • Setting::has($key) – Check if a setting exists.
  • Setting::remove($key) – Remove a setting.
  • Setting::refresh() – Refresh the cached settings.

Testing

Unit Tests

Run the unit tests with PHPUnit:

vendor/bin/phpunit

The package includes unit and feature tests to ensure everything is working as expected.

Development

  1. Clone the repository:

    git clone https://github.com/scriptoshi/settings.git
  2. Install dependencies:

    composer install
  3. Run tests:

    vendor/bin/phpunit

License

This package is licensed under the MIT License.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-11-20