承接 emadha/laravel-dynamic-config 相关项目开发

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

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

emadha/laravel-dynamic-config

Composer 安装命令:

composer require emadha/laravel-dynamic-config

包简介

This Package makes it possible for users to have their config files stored in a database table, making it easier to customize these values from UI.

README 文档

README

Introduction

This Package makes it possible for users to have their config files stored in a database table, making it easier to customize these values from UI.

Installation

You can install the package via composer:

composer require emadha/laravel-dynamic-config

The package will automatically register itself.

You can publish the config with:

Config file:

php artisan vendor:publish --provider="EmadHa\DynamicConfig\ServiceProvider" --tag="config"

Migration:

php artisan vendor:publish --provider="EmadHa\DynamicConfig\ServiceProvider" --tag="migrations"

Usage

First of all, you need to decide which config file(s) you want them to be stored in database by adding 'dynamic'=> true to the file, as simple as that:

# /config/app.php 
return [
    'dynamic' => true,
     ...
];
  • Note that dynamic indicator is defined in /config/emadha/dynamic-conf.php:
  • You can add dynamic=>true to any config file to store it in database and fetch the values from there instead of using the actual config file
  • The values defaults will be taken from the actual config file.
  • You can have more than one config file loaded dynamically
  • dynamic=>true can only be added in the first dimension of that config array.

The main config file of this packages is located in /config/emadha/dynamic-conf.php and contains the following code:

<?php
return [
    /* The Config database table name */
    'table'                   => 'confs',

    /*
     * The key that defines which config file should be loaded dynamically
     * and store into the database
     * Add that key to any config file to make it dynamic.
     */
    'dynamic_key'             => 'dynamics',

    /*
     * they key which will have the defaults of a config key
     * example: config('defaults.app.name'); This is added on runtime.
     */
    'defaults_key'            => 'defaults',

    /*
     * Delete orphan keys
     * if set to true and delete a key from the actual config file,
     * that key will be deleted from database.
     */
    'auto_delete_orphan_keys' => true,
];

The content of that file is pretty clear and well documented.

Usage

dd(config('app.name')); // Will return a Model object for that db row (key)
echo config('app.name'); // Will get the value from a config key using __toString() method from the DynamicConfig Model;
config('app.name')->setTo('Some New Value'); // will update that config key in database
config('app.name')->default(); // Will return the default value of that key (from the actual config file and not from the database)
config('app.name')->revert(); // Will revert the key value in database back to default (to what it is in the actual config file) 

As simple as that.

Why is that Useful?

In case you ever wanted to control the site title from a UI (backend, frontend), in a dynamic way without having to edit the actual config file, then this a good approach.

Another Example: Let's say you have a google analytics code a long with some other customizations, and you have these in /config/site.php as follows:

# /config/site.php
return [
    'dynamic'=>true,
    'title'=>config('app.name'),
    'description'=>'My Site Meta Description',
    'google'=>[
        'UA'=>'UA-XXXXXXXX-X',
        'enabled'=>true,
    ],
];

This config file cannot be easily modified from a user interface, thus your clients will not be able to edit this without editing the actual file, In that case this package will prove to be useful, adding the key dynamic=>true to that config file will make it store it's values in database using the same format as Laravel, therefore it will be no different for you to get the value of some key in that config file, example config('site.google.UA), plus adding some nice features like updating the value and revert back to default.

With that approach you can now create a backend input to customize these, using one line of code config('site.google.UA')->setTo('XYZ'); and then use it in your blade like normal:

{{-- welcome.blade.php--}}
<title>{{ config('site.title') }}</title>
<script>// Analytics ID: {{ config('site.google.UA')}}</script>

emadha/laravel-dynamic-config 适用场景与选型建议

emadha/laravel-dynamic-config 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.19k 次下载、GitHub Stars 达 14, 最近一次更新时间为 2020 年 03 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 emadha/laravel-dynamic-config 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 emadha/laravel-dynamic-config 我们能提供哪些服务?
定制开发 / 二次开发

基于 emadha/laravel-dynamic-config 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 14
  • Watchers: 1
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-03-27