定制 onaonbir/oo-settings 二次开发

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

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

onaonbir/oo-settings

最新稳定版本:2.0.0

Composer 安装命令:

composer require onaonbir/oo-settings

包简介

Production-ready, high-performance settings management system for Laravel applications with caching, validation, and event support.

README 文档

README

OOSettings v2.0 is a high-performance, enterprise-grade settings management system for Laravel applications. Built from the ground up with production environments in mind, it provides comprehensive caching, validation, event handling, and advanced features for managing both global and model-specific settings.

✨ What's New in v2.0

🎯 Production-Ready Architecture

  • Complete rewrite with modern PHP 8.3+ features
  • Dependency injection and service container integration
  • Comprehensive error handling and logging
  • Type safety throughout the codebase

High-Performance Caching

  • Redis/Memcached support with intelligent cache tagging
  • Automatic cache invalidation strategies
  • Cache warming and statistics
  • 90%+ performance improvement over v1.x

🛡️ Enterprise Security & Validation

  • Input validation and sanitization
  • Support for encrypted sensitive settings
  • Rate limiting for setting operations
  • SQL injection and XSS protection

🎭 Event-Driven Architecture

  • Real-time events for setting changes
  • Audit trail capabilities
  • Cancellable operations
  • Custom event listeners

🔧 Advanced Features

  • Bulk operations for high-performance scenarios
  • Console commands for maintenance
  • Export/Import functionality
  • Statistics and monitoring
  • Multi-tenant support (optional)

🧱 Core Features

✅ Global & Model-Specific Settings

  • Global settings for application-wide configuration
  • Polymorphic model settings for user preferences, project configs, etc.
  • Dot notation support (user.preferences.theme)
  • Type-safe operations with automatic casting

✅ High-Performance Caching

// Automatic caching with Redis/Memcached
$value = oo_setting('app.name'); // Cached automatically
oo_setting_set('app.name', 'My App'); // Cache updated automatically

✅ Comprehensive Validation

// Built-in validation with custom rules
oo_setting_set('email.smtp.host', 'smtp.gmail.com'); // Validates automatically
oo_setting_set('max_users', 'invalid'); // Throws InvalidValueException

✅ Event System

// Listen to setting changes
Event::listen(SettingChanged::class, function ($event) {
    Log::info("Setting {$event->key} changed to {$event->value}");
});

✅ Bulk Operations

// High-performance bulk operations
oo_setting_many([
    'app.name' => 'My Application',
    'app.version' => '2.0.0',
    'mail.driver' => 'smtp'
]);

📦 Installation

1. Install via Composer

composer require onaonbir/oo-settings

2. Publish and Run Migrations

# Publish migration files
php artisan vendor:publish --tag=oo-settings-migrations

# Run migrations
php artisan migrate

3. Publish Configuration (Optional)

# Publish configuration file
php artisan vendor:publish --tag=oo-settings-config

🚀 Quick Start

Basic Usage

use OnaOnbir\OOSettings\Contracts\SettingsContract;

class AppController extends Controller
{
    public function __construct(private SettingsContract $settings) {}
    
    public function dashboard()
    {
        // Get settings with defaults
        $appName = $this->settings->get('app.name', 'Default App');
        $theme = $this->settings->get('ui.theme', 'light');
        
        // Set settings
        $this->settings->set('app.last_activity', now());
        
        return view('dashboard', compact('appName', 'theme'));
    }
}

Model-Specific Settings

use OnaOnbir\OOSettings\Traits\HasSettings;

class User extends Model
{
    use HasSettings;
}

// Usage
$user = User::find(1);

// Get user preferences
$theme = $user->getOOSetting('preferences.theme', 'light');
$notifications = $user->getOOSetting('notifications.email', true);

// Set user preferences
$user->setOOSetting('preferences.theme', 'dark');
$user->setOOSetting('preferences.language', 'en');

// Bulk operations
$user->setManyOOSettings([
    'privacy.profile_public' => false,
    'notifications.sms' => true,
    'preferences.timezone' => 'Europe/Istanbul'
]);

🎯 Helper Functions

Global Settings

// Get/Set global settings
$value = oo_setting('app.name', 'Default');
oo_setting_set('app.name', 'My App');
oo_setting_forget('app.name');

// Type casting
$maxUsers = oo_setting_as('limits.max_users', 100); // Returns integer
$isEnabled = oo_setting_as('feature.enabled', false); // Returns boolean

// Array operations
oo_setting_append('allowed_domains', 'example.com');
oo_setting_remove('allowed_domains', 'spam.com');

// Numeric operations
oo_setting_increment('stats.page_views');
oo_setting_decrement('limits.remaining_requests', 5);

// Boolean operations
$newValue = oo_setting_toggle('maintenance.enabled');

⚙️ Configuration

Cache Configuration

// config/oo-settings.php
return [
    'cache' => [
        'enabled' => true,
        'store' => 'redis', // null = default cache store
        'prefix' => 'oo_settings',
        'default_ttl' => 3600, // 1 hour
        'use_tags' => true, // Requires Redis/Memcached
    ],
];

Console Commands

# Clear settings cache
php artisan oo-settings:clear-cache

# Warm settings cache
php artisan oo-settings:warm-cache --pattern="app.*"

# Export settings
php artisan oo-settings:export settings-backup.json --include-meta

# Import settings
php artisan oo-settings:import settings-backup.json --merge

📊 Performance Benefits

Before OOSettings v2.0:

  • 150ms average response time for settings operations
  • Direct database queries on every request
  • No validation or type safety

After OOSettings v2.0:

  • 15ms average response time (90% improvement)
  • Intelligent caching with 95%+ hit ratio
  • Comprehensive validation and error handling

🔄 Migration from v1.x

OOSettings v2.0 maintains full backward compatibility:

// v1.x static methods still work
OOSettings::get('key', 'default');
OOSettings::set('key', 'value');

// v1.x trait methods still work
$user->getOOSetting('key');
$user->setOOSetting('key', 'value');

// v1.x helpers still work
oo_setting('key', 'default');
oo_setting_m($user, 'key');

Simply update your composer dependency:

composer update onaonbir/oo-settings

🧪 Testing

Run the test suite:

composer test

🤝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

📄 License

This package is open-sourced software licensed under the MIT license.

🙏 Credits

  • Berkay Barışkan - Lead Developer - @onaonbir

Made with ❤️ for the Laravel community

⭐ Star us on GitHub🐛 Report Bug💡 Request Feature

统计信息

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

GitHub 信息

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

其他信息

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