huangdijia/hyperf-config-array

Config extension for Hyperf.

0.1.1 2020-11-26 01:33 UTC

This package is auto-updated.

Last update: 2024-10-27 16:46:09 UTC


README

Latest Test Latest Stable Version Total Downloads GitHub license

Installation

composer require huangdijia/hyperf-config-array

Publish

php bin/hyperf.php vendor:publish huangdijia/hyperf-config-array

Define source

namespace App\Source;

use Huangdijia\ConfigArray\SourceInterface;
use Hyperf\DB\DB;

class DBSource implements SourceInterface
{
    public function toArray(): array
    {
        return DB::query('SELECT * FROM `config`;');
    }
}

Set config

// config/autoload/config_array.php
return [
    // ...
    'source' => App\Source\DBSource::class,
    // ...
    'mapping' => 'setting', // using as config('setting')
    // or
    'mapping' => [
        'setting_key' => 'setting.key', // using as config('setting.key')
    ],
];