{"id":13828242,"url":"https://github.com/illuminatech/config","last_synced_at":"2025-10-17T20:49:12.302Z","repository":{"id":56990063,"uuid":"187034639","full_name":"illuminatech/config","owner":"illuminatech","description":"Manage Laravel configuration by persistent storage","archived":false,"fork":false,"pushed_at":"2024-03-25T10:56:37.000Z","size":117,"stargazers_count":146,"open_issues_count":0,"forks_count":14,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-04-26T13:05:00.931Z","etag":null,"topics":["config","configuration","database","laravel","persistent","repository"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/illuminatech.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["klimov-paul"],"patreon":"klimov_paul"}},"created_at":"2019-05-16T13:34:25.000Z","updated_at":"2024-06-19T01:39:40.462Z","dependencies_parsed_at":"2024-06-19T01:39:39.133Z","dependency_job_id":"bf9f151a-cfe9-4953-bd0d-0e4e76ceef8b","html_url":"https://github.com/illuminatech/config","commit_stats":{"total_commits":75,"total_committers":2,"mean_commits":37.5,"dds":"0.013333333333333308","last_synced_commit":"3dbd7bb4feef8d05ceccfdb6b924cc677c0930ae"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/illuminatech%2Fconfig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/illuminatech%2Fconfig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/illuminatech%2Fconfig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/illuminatech%2Fconfig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/illuminatech","download_url":"https://codeload.github.com/illuminatech/config/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225492420,"owners_count":17482869,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["config","configuration","database","laravel","persistent","repository"],"created_at":"2024-08-04T09:02:38.087Z","updated_at":"2025-10-17T20:49:07.259Z","avatar_url":"https://github.com/illuminatech.png","language":"PHP","funding_links":["https://github.com/sponsors/klimov-paul","https://patreon.com/klimov_paul"],"categories":["PHP"],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/illuminatech\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://avatars1.githubusercontent.com/u/47185924\" height=\"100px\"\u003e\n    \u003c/a\u003e\n    \u003ch1 align=\"center\"\u003eLaravel Persistent Configuration Repository\u003c/h1\u003e\n    \u003cbr\u003e\n\u003c/p\u003e\n\nThis extension introduces persistent configuration repository for Laravel.\nIts usage in particular provides support for application runtime configuration, loading config from database.\n\nFor license information check the [LICENSE](LICENSE.md)-file.\n\n[![Latest Stable Version](https://img.shields.io/packagist/v/illuminatech/config.svg)](https://packagist.org/packages/illuminatech/config)\n[![Total Downloads](https://img.shields.io/packagist/dt/illuminatech/config.svg)](https://packagist.org/packages/illuminatech/config)\n[![Build Status](https://github.com/illuminatech/config/workflows/build/badge.svg)](https://github.com/illuminatech/config/actions)\n\n\nInstallation\n------------\n\nThe preferred way to install this extension is through [composer](http://getcomposer.org/download/).\n\nEither run\n\n```\nphp composer.phar require --prefer-dist illuminatech/config\n```\n\nor add\n\n```json\n\"illuminatech/config\": \"*\"\n```\n\nto the require section of your composer.json.\n\n\nUsage\n-----\n\nThis extension allows reconfiguration of already created config repository using data from the external storage like relational database.\nIt provides special config repository class `\\Illuminatech\\Config\\PersistentRepository`, which wraps any given config repository,\nadding a layer for saving and restoring of data from the persistent storage.\n\n```php\n\u003c?php\n\nuse Illuminate\\Config\\Repository;\nuse Illuminate\\Support\\Facades\\App;\nuse Illuminatech\\Config\\PersistentRepository;\nuse Illuminatech\\Config\\StorageDb;\n\n$sourceConfigRepository = new Repository([\n    'foo' =\u003e [\n        'name' =\u003e 'Foo',\n    ],\n    'bar' =\u003e [\n        'enabled' =\u003e false,\n    ],\n    'other' =\u003e [\n        'value' =\u003e 'Some',\n    ],\n]);\n\n$storage = new StorageDb(App::make('db.connection'));\n\n$persistentConfigRepository = (new PersistentRepository($sourceConfigRepository, $storage))\n    -\u003esetItems([\n        'foo.name',\n        'bar.enabled',\n    ]);\n\necho $persistentConfigRepository-\u003eget('foo.name'); // returns value from database if present, otherwise the one from source repository, in this case - 'Foo'\n\necho $persistentConfigRepository-\u003eget('other.value'); // keys, which are not specified as \"items\" always remain intact, in this case - always return 'Some'\n```\n\nConfig data, which should be saved in persistent storage defined via `\\Illuminatech\\Config\\PersistentRepository::setItems()`.\nOnly keys, which are explicitly defined as \"items\", will be stored or retrieved from the persistent storage. Any other data\npresent in the source config repository will remain as it is.\n\nPersistentRepository fully decorates any config repository, matching `\\Illuminate\\Contracts\\Config\\Repository` and can substitute `\\Illuminate\\Config\\Repository` instance.\nIn particular this allows you to substitute regular Laravel config by `\\Illuminatech\\Config\\PersistentRepository` instance,\napplying configuration from database to the entire application. You can do so in your `AppServiceProvider` class. For example:\n\n```php\n\u003c?php\n\nnamespace App\\Providers;\n\nuse Illuminate\\Contracts\\Config\\Repository;\nuse Illuminate\\Support\\ServiceProvider;\nuse Illuminatech\\Config\\PersistentRepository;\nuse Illuminatech\\Config\\StorageDb;\n\nclass AppServiceProvider extends ServiceProvider\n{\n    public function boot()\n    {\n        $this-\u003eapp-\u003eextend('config', function (Repository $originConfig) {\n            $storage = new StorageDb($this-\u003eapp-\u003emake('db.connection'));\n\n            $newConfig = (new PersistentRepository($originConfig, $storage))\n                -\u003esetItems([\n                    'mail.contact.address' =\u003e [\n                        'label' =\u003e __('Email address receiving contact messages'),\n                        'rules' =\u003e ['sometimes', 'required', 'email'],\n                    ],\n                    // ...\n                ]);\n\n            return $newConfig;\n        });\n\n        // ...\n    }\n}\n```\n\nThen anytime you access 'config' service in your application via `config()` function, `\\Illuminate\\Support\\Facades\\Config` facade\nor via service container you will interact with `\\Illuminatech\\Config\\PersistentRepository` instance getting values modified\nby database data.\n\n\u003e Tip: with this extension there is no need for manually putting any data into actual storage (e.g. writing DB migrations or Seeding) -\n  it will be filled up automatically. If value for the particular item is missing in the storage, it will be simply picked up from\n  the wrapped config repository (e.g. as defined at 'config/*.php' files). However, some storages require some preparations before\n  they can function, like creating a database table.\n\n**Note:** this extension does not provide built in service provider for application config substitute as it might be not desired\nfor particular application, while `\\Illuminatech\\Config\\PersistentRepository` usage is not limited with this task.\nHowever, you can use `\\Illuminatech\\Config\\Providers\\AbstractPersistentConfigServiceProvider` class as a scaffold for such service provider.\nFor example:\n\n```php\n\u003c?php\n\nnamespace App\\Providers;\n\nuse Illuminatech\\Config\\Providers\\AbstractPersistentConfigServiceProvider;\nuse Illuminatech\\Config\\StorageContract;\nuse Illuminatech\\Config\\StorageDb;\n\nclass PersistentConfigServiceProvider extends AbstractPersistentConfigServiceProvider\n{\n    protected function storage(): StorageContract\n    {\n        return (new StorageDb($this-\u003eapp-\u003emake('db.connection')));\n    }\n\n    protected function items(): array\n    {\n        return [\n            'mail.contact.address' =\u003e [\n                'label' =\u003e __('Email address receiving contact messages'),\n                'rules' =\u003e ['sometimes', 'required', 'email'],\n            ],\n            // ...\n        ];\n    }\n}\n```\n\nDo not forget to register your particular persistent config service provider in \"providers\" section at \"config/app.php\":\n\n```php\n\u003c?php\n\nreturn [\n    // ...\n    'providers' =\u003e [\n        // ...\n        App\\Providers\\PersistentConfigServiceProvider::class,\n    ],\n    // ...\n];\n```\n\nYou may also manage persistent configuration per particular application entity. For example: imagine we need to allow\napplication user to customize appearance of his profile page, like changing color schema or enable/disable sidebar and so on.\nSuch settings can be managed by `\\Illuminatech\\Config\\PersistentRepository` bound to the user Eloquent model. Such model class\nmay look like following:\n\n```php\n\u003c?php\n\nnamespace App\\Models;\n\nuse Illuminate\\Config\\Repository;\nuse Illuminate\\Database\\Eloquent\\Model;\nuse Illuminatech\\Config\\PersistentRepository;\nuse Illuminatech\\Config\\StorageDb;\n\nclass User extends Model\n{\n    /**\n     * @var \\Illuminatech\\Config\\PersistentRepository configuration repository specific to this model.\n     */\n    private $config;\n\n    /**\n     * Returns configuration associated with this particular model.\n     *\n     * @return \\Illuminatech\\Config\\PersistentRepository config repository.\n     */\n    public function getConfig(): PersistentRepository\n    {\n        if ($this-\u003econfig === null) {\n            if (empty($this-\u003eid)) {\n                throw new \\InvalidArgumentException('Unable to get config for model without ID.');\n            }\n    \n            $repository = new Repository($this-\u003edefaultConfigData());\n    \n            $storage = (new StorageDb($this-\u003egetConnection()))\n                -\u003esetFilter(['user_id' =\u003e $this-\u003eid]); // ensure configuration varies per each model\n    \n            $this-\u003econfig = (new PersistentRepository($repository, $storage))\n                -\u003esetItems($this-\u003epersistentConfigItems());\n        }\n    \n        return $this-\u003econfig;\n    }\n    \n    /**\n     * Defines default configuration for the model instance.\n     *\n     * @return array config.\n     */\n    private function defaultConfigData()\n    {\n        return [\n            'sidebar' =\u003e [\n                'enabled' =\u003e true,\n            ],\n            'color' =\u003e [\n                'primary' =\u003e '#4099de',\n                'sidebar' =\u003e '#b3c1d1',\n            ],\n        ];\n    }\n    \n    /**\n     * Defines the config items, which should be manageable from web interface and stored in the database.\n     *\n     * @return array config items.\n     */\n    private function persistentConfigItems(): array\n    {\n        return [\n            'sidebar.enabled' =\u003e [\n                'label' =\u003e 'Sidebar enabled',\n                'rules' =\u003e ['sometimes', 'required', 'boolean'],\n            ],\n            'color.primary' =\u003e [\n                'label' =\u003e 'Primary color',\n                'rules' =\u003e ['sometimes', 'required', 'string'],\n            ],\n            'color.sidebar' =\u003e [\n                'label' =\u003e 'Sidebar color',\n                'rules' =\u003e ['sometimes', 'required', 'string'],\n            ],\n        ];\n    }\n}\n```\n\nIt will allow you to operate persistent configuration per each user record separately, so profile page composition may\nlook like following:\n\n```blade\n@php\n/* @var $user App\\Models\\User */ \n@endphp\n@extends('layouts.main')\n\n@section('content')\n@if ($user-\u003egetConfig()-\u003eget('sidebar.enabled'))\n    @include('includes.sidebar', ['color' =\u003e $user-\u003egetConfig()-\u003eget('color.sidebar')])\n@endif\n\u003cdiv style=\"background-color:{{ $user-\u003egetConfig()-\u003eget('color.primary') }};\"\u003e\n    ...\n\u003c/div\u003e\n@endsection\n```\n\n### Configuration items specification \u003cspan id=\"configuration-items-specification\"\u003e\u003c/span\u003e\n\nConfig parts, which should be saved in the persistent storage are defined by `\\Illuminatech\\Config\\PersistentRepository::setItems()`,\nwhich accepts a list of `\\Illuminatech\\Config\\Item` or configuration array for it.\nEach configuration item should define a key, which leads to the target value in source repository.\nConfiguration item also has several properties, which supports creation of web interface for configuration setup.\nThese are:\n\n - 'id' - string, item unique ID in the list, this value will be used in request fields and form inputs.\n - 'label' - string, verbose label for the config value input.\n - 'hint' - string, verbose description for the config value or input hint.\n - 'rules' - array, value validation rules.\n - 'cast' - string, native type for the value to be cast to.\n - 'encrypt' - bool, whether to encrypt value for the storage or not.\n - 'options' - array, additional descriptive options for the item, which can be used as you see fit.\n\nSince only 'key' is mandatory item may be specified by single string defining this key.\n\nHere are some examples of item specifications:\n\n```php\n\u003c?php\n\nuse Illuminatech\\Config\\Item;\nuse Illuminatech\\Config\\PersistentRepository;\n\n$persistentConfigRepository = (new PersistentRepository(...))\n    -\u003esetItems([\n        'some.config.value',\n        'another.config.value' =\u003e [\n            'label' =\u003e 'Custom label',\n            'rules' =\u003e ['required', 'numeric'],\n        ],\n        [\n            'key' =\u003e 'array.config.value',\n            'rules' =\u003e ['required', 'array'],\n            'cast' =\u003e 'array',\n        ],\n        new Item(['key' =\u003e 'explicit.object']),\n    ]);\n```\n\n\n### Configuration storage \u003cspan id=\"configuration-storage\"\u003e\u003c/span\u003e\n\nDeclared configuration items may be saved into persistent storage and then retrieved from it.\nThe actual item storage can be any class matching `\\Illuminatech\\Config\\StorageContract` interface.\n\nFollowing storages are available within this extension:\n\n - [\\Illuminatech\\Config\\StorageDb](src/StorageDb.php) - stores configuration inside relational database;\n - [\\Illuminatech\\Config\\StorageEloquent](src/StorageEloquent.php) - stores configuration using Eloquent models;\n - [\\Illuminatech\\Config\\StoragePhp](src/StoragePhp.php) - stores configuration in local PHP files;\n - [\\Illuminatech\\Config\\StorageArray](src/StorageArray.php) - stores configuration in runtime memory;\n\nPlease refer to the particular storage class for more details.\n\n\n### Saving and restoring data \u003cspan id=\"saving-and-restoring-data\"\u003e\u003c/span\u003e\n\n`\\Illuminatech\\Config\\PersistentRepository` will automatically retrieve config item values from persistent storage on the\nfirst attempt to get config value from it.\n\n```php\n\u003c?php\n\nuse Illuminatech\\Config\\PersistentRepository;\n\n$persistentConfigRepository = (new PersistentRepository(...))\n    -\u003esetItems([\n        'some.config',\n    ]);\n\n$value = $persistentConfigRepository-\u003eget('some.config'); // loads data from persistent storage automatically.\n```\n\nYou may also manually fetch data from persistent storage using `restore()` method:\n\n```php\n\u003c?php\n\nuse Illuminatech\\Config\\PersistentRepository;\n\n$persistentConfigRepository = (new PersistentRepository(...))\n    -\u003esetItems([\n        'some.config',\n    ]);\n\n$persistentConfigRepository-\u003erestore(); // loads/re-loads data from persistent storage\n```\n\n**Heads up!** Any error or exception, which appears during values restoration, will be automatically suppressed. This is \ndone to avoid application blocking in case storage is not yet ready for usage, for example: database table does not yet exist.\nStorage failure error will appear only at the application log. You should manually test value restoration is working at\nyour application to avoid unexpected behavior.\n\nTo save config data into persistent storage use method `save()`:\n\n```php\n\u003c?php\n\nuse Illuminatech\\Config\\PersistentRepository;\n\n$persistentConfigRepository = (new PersistentRepository(...))\n    -\u003esetItems([\n        'some.config',\n        'another.config',\n    ]);\n\n$persistentConfigRepository-\u003esave([\n    'some.config' =\u003e 'some persistent value',\n    'another.config' =\u003e 'another persistent value',\n]);\n```\n\nChanges made via regular config repository interface (e.g. via methods `set()`, `push()` and so on) will not be automatically\nsaved into the persistent storage. However, you may use `synchronize()` method to save current config item values into it.\n\n```php\n\u003c?php\n\nuse Illuminatech\\Config\\PersistentRepository;\n\n$persistentConfigRepository = (new PersistentRepository(...))\n    -\u003esetItems([\n        'some.config',\n        'another.config',\n    ]);\n\n$persistentConfigRepository-\u003eset('some.config', 'new value'); // no changes at the persistent storage at this point\n\n$persistentConfigRepository-\u003esynchronize(); // save values to the persistent storage\n```\n\n\u003e Tip: You may invoke `synchronize()` at the application [terminating stage](https://laravel.com/docs/5.8/middleware#terminable-middleware) ensuring all changes made\n  during application running are saved.\n\nMethod `reset()` clears all data saved to the persistent storage, restoring original (e.g. default) config repository values.\n\n```php\n\u003c?php\n\nuse Illuminate\\Config\\Repository;\nuse Illuminatech\\Config\\PersistentRepository;\n\n$sourceConfigRepository = new Repository([\n    'some' =\u003e [\n        'config' =\u003e 'original value',\n    ],\n]);\n\n$persistentConfigRepository = (new PersistentRepository($sourceConfigRepository, ...))\n    -\u003esetItems([\n        'some.config',\n    ]);\n\n$persistentConfigRepository-\u003esave([\n    'some.config' =\u003e 'new value',\n]);\n\necho $persistentConfigRepository-\u003eget('some.config'); // outputs 'new value'\n\n$persistentConfigRepository-\u003ereset(); // clears data in the persistent storage\n\necho $persistentConfigRepository-\u003eget('some.config'); // outputs 'original value'\n```\n\nYou can also use `resetValue()` method to reset particular config key only.\n\n\n### Caching \u003cspan id=\"caching\"\u003e\u003c/span\u003e\n\nYou can use [PSR-16](https://www.php-fig.org/psr/psr-16/) compatible cache storage to improve performance of the config item\nretrieval from persistent storage. For example:\n\n```php\n\u003c?php\n\nuse Illuminate\\Config\\Repository;\nuse Illuminate\\Support\\Facades\\App;\nuse Illuminatech\\Config\\PersistentRepository;\n\n$sourceConfigRepository = new Repository([\n    'some' =\u003e [\n        'config' =\u003e 'original value',\n    ],\n]);\n\n$persistentConfigRepository = (new PersistentRepository($sourceConfigRepository, ...))\n    -\u003esetItems([\n        'some.config',\n    ])\n    -\u003esetCache(App::make('cache.store'))\n    -\u003esetCacheKey('global-config')\n    -\u003esetCacheTtl(3600 * 24);\n```\n\n\n### Validation \u003cspan id=\"validation\"\u003e\u003c/span\u003e\n\nEach configuration item comes with validation rules, which matches `['sometimes' ,'required']` by default. You can easily\ncreate a validation for the user input before config saving, using these rules, or use `\\Illuminatech\\Config\\PersistentRepository::validate()`.\nFor example:\n\n```php\n\u003c?php\n\n/* @var $request Illuminate\\Http\\Request */\n/* @var $config Illuminatech\\Config\\PersistentRepository */\n\n$validatedData = $config-\u003evalidate($request-\u003eall()); // throws \\Illuminate\\Validation\\ValidationException if validation fails.\n// ...\n```\n\nYou can also use `\\Illuminatech\\Config\\PersistentRepository::makeValidator()` method to create a validator instance for manual processing.\n\n**Heads up!** Watch for usage dot symbols ('.') inside the input in case you do not use `\\Illuminatech\\Config\\PersistentRepository::validate()` method.\nBy default Laravel considers dots in validation rules as array nested keys separator. You should either prefix them\nwith backslash ('\\\\') or manually define `\\Illuminatech\\Config\\Item::$id` in the way it does not contain a dot.\n\n\n### Creating configuration web interface \u003cspan id=\"creating-configuration-web-interface\"\u003e\u003c/span\u003e\n\nOne of the most common use case for this extension is creating a web interface, which allows control of application\nconfiguration in runtime.\n`\\Illuminatech\\Config\\PersistentRepository` serves not only for applying of the configuration - it also helps to create an\ninterface for configuration editing.\n\nThe web controller for configuration management may look like following:\n\n```php\n\u003c?php\n\nnamespace App\\Http\\Controllers;\n\nuse Illuminate\\Contracts\\Container\\Container;\nuse Illuminate\\Http\\Request;\n\nclass ConfigController extends Controller\n{\n    /**\n     * @var \\Illuminatech\\Config\\PersistentRepository persistent config repository, which is set at `AppServiceProvider`.\n     */\n    private $config;\n    \n    public function __construct(Container $app)\n    {\n        $this-\u003econfig = $app-\u003eget('config');\n    }\n    \n    public function index()\n    {\n        $this-\u003econfig-\u003erestore(); // ensure config values restored from database\n        \n        return view('config.form', ['items' =\u003e $this-\u003econfig-\u003egetItems()]);\n    }\n    \n    public function update(Request $request)\n    {\n        $validatedData = $this-\u003econfig-\u003evalidate($request-\u003eall());\n    \n        $this-\u003econfig-\u003esave($validatedData);\n    \n        return back()-\u003ewith('status', 'success');\n    }\n    \n    public function restoreDefaults()\n    {\n        $this-\u003econfig-\u003ereset();\n        \n        return back()-\u003ewith('status', 'success');\n    }\n}\n```\n\nYou can operate `\\Illuminatech\\Config\\Item` interface during HTML form input composition. For example:\n\n```blade\n...\n\u003cform ...\u003e\n...\n@foreach ($items as $item)\n    \u003clabel\u003e{{ $item-\u003elabel }}\u003c/label\u003e\n    \u003cinput type=\"text\" name=\"{{ $item-\u003eid }}\" value=\"{{ $item-\u003egetValue() }}\"\u003e\n    \u003cp\u003e{{ $item-\u003ehint }}\u003c/p\u003e\n@endforeach\n...\n\u003c/form\u003e\n...\n```\n\n\u003e Tip: you can use `\\Illuminatech\\Config\\Item::$options` to setup configuration for the dynamic form inputs, specifying\n  input type, CSS class and so on inside of it.\n\n\n**Heads up!** Remember that PHP automatically replaces non-alphanumeric characters like dot ('.'), dash ('-') and so on\ninside request keys during native 'POST' parsing, making collection and validation for keys like 'config.some-key' impossible.\nYou will need to setup `\\Illuminatech\\Config\\Item::$id` value for each persistent configuration item manually, in case you\ngoing to submit values via regular 'POST' request. For example:\n\n```php\n\u003c?php\n\nuse Illuminatech\\Config\\PersistentRepository;\n\n$persistentConfigRepository = (new PersistentRepository(...))\n    -\u003esetItems([\n        'some.config.value' =\u003e [\n            'id' =\u003e 'some_config_value',\n        ],\n        'another-config-value' =\u003e [\n            'id' =\u003e 'another_config_value',\n        ],\n        // ...\n    ]);\n```\n\n\u003e Tip: you will not face this problem in case you submit configuration item values via REST API interface using JSON\n  format or via native (not spoofed) 'PUT' request.\n\nIn case you are using [Laravel Nova](https://nova.laravel.com/) for your application admin panel, you can easily create an application\nconfiguration setup interface with [illuminatech/nova-config](https://github.com/illuminatech/nova-config) extension.\n\n\n### Typecast \u003cspan id=\"typecast\"\u003e\u003c/span\u003e\n\nYou may operate complex type values like arrays as a persistent ones. In order to do so, you should specify config item\ntypecasting via `\\Illuminatech\\Config\\Item::$cast`. For example:\n\n```php\n\u003c?php\n\nuse Illuminate\\Config\\Repository;\nuse Illuminatech\\Config\\PersistentRepository;\n\n$sourceConfigRepository = new Repository([\n    'some' =\u003e [\n        'array' =\u003e ['one', 'two', 'three'],\n    ],\n]);\n\n$persistentConfigRepository = (new PersistentRepository($sourceConfigRepository, ...))\n    -\u003esetItems([\n        'some.array' =\u003e [\n            'cast' =\u003e 'array', // cast value from persistent storage to array\n            'rules' =\u003e ['sometimes', 'required', 'array'],\n        ],\n    ]);\n\n$persistentConfigRepository-\u003esave([\n    'some.array' =\u003e ['five', 'six'],\n]);\n\n$persistentConfigRepository-\u003erestore();\n\nvar_dump($persistentConfigRepository-\u003eget('some.array') === ['five', 'six']); // outputs 'true'\n```\n\n\n### Encryption \u003cspan id=\"encryption\"\u003e\u003c/span\u003e\n\nIn case you are planning to operate sensitive data like passwords, API keys and so on, you may want to store them as an\nencrypted strings rather than the plain ones. This can be achieved enabling `\\Illuminatech\\Config\\Item::$encrypt`.\nFor example:\n\n```php\n\u003c?php\n\nuse Illuminate\\Config\\Repository;\nuse Illuminatech\\Config\\PersistentRepository;\n\n$sourceConfigRepository = new Repository([\n    'some' =\u003e [\n        'apiKey' =\u003e 'secret',\n    ],\n]);\n\n$persistentConfigRepository = (new PersistentRepository($sourceConfigRepository, ...))\n    -\u003esetItems([\n        'some.apiKey' =\u003e [\n            'encrypt' =\u003e true, // encrypt value before placing it into the persistent storage\n        ],\n    ]);\n```\n\nNote that data encryption will impact the config repository performance.\n\n\n### Garbage collection \u003cspan id=\"garbage-collection\"\u003e\u003c/span\u003e\n\nAs your project evolves new configuration items may appear as well as some becomes redundant.\n`\\Illuminatech\\Config\\PersistentRepository` automatically ignores any value in persistent storage in case it has no\nmatching config item set by `setItems()`. Thus stored obsolete values will not affect config repository anyway, however\nthey still may consume extra space inside the storage. You may manually remove all obsolete values from the storage,\nusing `gc()` method:\n\n```php\n\u003c?php\n\nuse Illuminate\\Config\\Repository;\nuse Illuminatech\\Config\\PersistentRepository;\nuse Illuminatech\\Config\\StorageDb;\n\n$sourceConfigRepository = new Repository([\n    'some' =\u003e [\n        'config' =\u003e 'original value',\n    ],\n]);\n\n$storage = new StorageDb(...);\n$storage-\u003esave([\n    'some.config' =\u003e 'some value',\n    'obsolete.config' =\u003e 'obsolete value',\n]);\n\n$persistentConfigRepository = (new PersistentRepository($sourceConfigRepository, $storage))\n    -\u003esetItems([\n        'some.config',\n    ]);\n\n$persistentConfigRepository-\u003egc(); // removes 'obsolete.config' from storage\n```\n\nIn case `Illuminatech\\Config\\PersistentRepository::$gcEnabled` enabled garbage collection will be performed automatically\neach time config values are saved via `save()` or `synchronize()` method.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Filluminatech%2Fconfig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Filluminatech%2Fconfig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Filluminatech%2Fconfig/lists"}