Write to Laravel Config files and maintain file integrity

Overview

Laravel Config Writer

Write to Laravel Config files and maintain file integrity.

This library is an extension of the Config component used by Laravel. It adds the ability to write to configuration files.

You can rewrite array values inside a basic configuration file that returns a single array definition (like a Laravel config file) whilst maintaining the file integrity, leaving comments and advanced settings intact.

The following value types are supported for writing: strings, integers, booleans and single-dimension arrays.

Support

This provider is designed to be used in Laravel from 5.4 version.

Setup

Install through composer:

composer require "daftspunk/laravel-config-writer"

Add this to app/config/app.php under the 'providers' key:

October\Rain\Config\ServiceProvider::class,

Lumen case

Add this to bootstrap/app.php in the 'service providers' section declaration:

$app->register(October\Rain\Config\ServiceProvider::class);

Usage

You can write to config files like this:

Config::write('app.url', 'http://domain.com');

app('config')->write('app.url', 'http://domain.com');

Outside Laravel

The Rewrite class can be used anywhere.

$writeConfig = new October\Rain\Config\DataWriter\Rewrite;
$writeConfig->toFile('path/to/config.php', [
    'item' => 'new value',
    'nested.config.item' => 'value',
    'arrayItem' => ['Single', 'Level', 'Array', 'Values'],
    'numberItem' => 3,
    'booleanItem' => true
]);
Comments
  • Update for Laravel 5.4 and greater and Lumen support

    Update for Laravel 5.4 and greater and Lumen support

    Due to inactivity, I have forked this project to resolve some main issues it has:

    • For #13 & #15: Compatibility with Laravel 5.4 and greater,
    • Add Lumen provider support,
    • Add PHP explicit typings (PHP 7),
    • Fix regex 'non-greedy' search,
    • Update Readme.md for usage.

    If you want this update, you can check this repository https://github.com/tekreme73/laravel-config-writer

    I have changed the architecture and rename the namespace, that's why I'm not doing a PR, sorry for that. If you want to, I can make a PR but it will need some commit to remove my 'Tekreme73' namespace...

    opened by tekreme73 4
  • add provider in auto register in composer.json

    add provider in auto register in composer.json

        "extra": {
            "laravel": {
                "providers": [
                    "October\Rain\Config\ServiceProvider",
                ]
            }
        },
    
    opened by vahidalvandi 2
  • Laravel v9 Installation Error

    Laravel v9 Installation Error

    Installation on Laravel 9

    ERROR!!! Could not find a matching version of package daftspunk/laravel-config-writer. Check the package spelling, your version constraint and that the package is availabl e in a stability which matches your minimum-stability (dev).

    opened by Soltee 2
  • Is Laravel 5.8 supported?

    Is Laravel 5.8 supported?

    I'm running Laravel 5.8.27 and installed illuminate/config, which gave me version 5.8. When I tried installing your config writer, I got this error:

    $ composer require "daftspunk/laravel-config-writer" Using version ^1.0 for daftspunk/laravel-config-writer ./composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev) Your requirements could not be resolved to an installable set of packages.

    Problem 1 - don't install illuminate/config 4.2.x-dev|don't install laravel/framework v5.8.27 - don't install illuminate/config 4.2.x-dev|remove laravel/framework v5.8.27 - don't install illuminate/config 4.2.x-dev|don't install laravel/framework v5.8.27 - daftspunk/laravel-config-writer v1.0 requires illuminate/config 4.2.x -> satisfiable by illuminate/config[4.2.x-dev]. - Installation request for daftspunk/laravel-config-writer ^1.0 -> satisfiable by daftspunk/laravel-config-writer[v1.0]. - Installation request for laravel/framework (locked at v5.8.27, required as 5.8.*) -> satisfiable by laravel/framework[v5.8.27].

    Installation failed, reverting ./composer.json to its original content.

    Did I do something wrong? Any advice? Thank you!

    opened by rottndandie 2
  • Update for Laravel 5.4 and greater and Lumen support

    Update for Laravel 5.4 and greater and Lumen support

    • For #13 & #15: Compatibility with Laravel 5.4 and greater,
    • Add Lumen provider support,
    • Add PHP explicit typings (PHP 7),
    • Fix regex 'non-greedy' search,
    • Update Readme.md for usage.
    opened by tekreme73 2
  • Rewrite config files with env calls

    Rewrite config files with env calls

    It it common to have env method calls in config files. These should also be rewritable. To implement this I had to be able to use a specific replace pattern for each regex pattern. Currently rewriting .env/.env.example/.env.subtype is not supported. It just replaces the fallback value.

    The problem originally occured in october https://github.com/octobercms/library/pull/397. As these libraries share the same code I added the pull requests to both libraries.

    opened by JoshuaBehrens 1
  • Undefined method getConfigLoader

    Undefined method getConfigLoader

    Hello,

    The method used in the service provider $loader = $app->getConfigLoader(); doesn't exists.

    Call to undefined method Illuminate\Foundation\Application::getConfigLoader()
    

    Any idea how to make it work ?

    opened by nWidart 1
  • General improvements

    General improvements

    Made a few improvements to the package:

    1. Fixed possible typo (Rewrite instead of Rewriter)
    2. Change to use a service provider instead.
    3. Requires laravel 4.2 now
    4. The file picker acts more the way laravel does by default. For example, if our environment is 'local' it will open the local config (if it exsists), and then check if the array key exists. If not, then it will open the config in the app/config folder. This helps to prevent the key not found errors, if they haven't specifically been set for that environment.
    5. Removed unnecessary "october/support" requirement.
    opened by greatwitenorth 1
  • Write to array in array

    Write to array in array

    I need to write an array to an array. Is this possible even possible? Like e.g.

    rules.php

    return [
    'rules' => [
           [
                'name' => 'Test rule',
                'value' => 'value1'
            ],
            [
                'name' => 'Test rule 2',
                'value' => 'value 2'
            ]
        ]
    ]
    
    opened by sheriffmarley 0
  • Usage within OctoberCMS ?

    Usage within OctoberCMS ?

    Can someone help me out getting this to work within an octobercms component ?

    Use Config;
    
    Config::write('acme.demo::url', 'http://octobercms.com');
    

    Error :

    Call to undefined method October\Rain\Config\Repository::write()
    

    Looking at the documentation there's a public method toFile()

    use October\Rain\Config\ConfigWriter;
    (new ConfigWriter)->toFile('acme.demo::url', 'http://octobercms.com');
    

    Error :

    file_get_contents(acme.demo::url): failed to open stream: Invalid argument
    

    Note that my plugin : Acme\Demo has a Config Directory and a config.php file.

    Anyone?

    opened by rajakhoury 0
  • String with backslash fails

    String with backslash fails

    I tried to install October CMS which uses laravel-config-writer. The installer asks for the password of the MySQL database and since my passwords are all randomly generated, they contain special characters and sometimes that might be a backslash (). The installer always failed with the error:

    Unable to rewrite key "connections.mysql.password" in config, rewrite failed

    Now I understand that having one backslash isn't really smart anyways, since it will be stored in a string where the backslash will act as escape character. However even if you use two backslashes to escape the first one, rewrite will just error.

    Maybe you don't want to support backslashes, but I thought it's worth reporting regardless. :smiley:

    opened by eXpl0it3r 0
  • Recomended Way To Put Code Swap out IoC

    Recomended Way To Put Code Swap out IoC

    Hi,

    whats the recomended way to put this code?

    App::instance('config', function($app){
        $loader = $app->getConfigLoader();
        $writer = October\Rain\Config\FileWriter($loader, $app['path'].'/config');
        return new October\Rain\Config\Repository($loader, $writer, $app['env']);
    })
    

    Maybe in App::filter() ?

    Thanks

    opened by fer-ri 0
Releases(v1.1)
Owner
Sam Geo
Co-Founder @OctoberCMS
Sam Geo
This tool is used to build and maintain browscap files.

Browser Capabilities Project This tool is used to build and maintain browscap files.

Browser Capabilities Project 400 Dec 29, 2022
Provide CSV, JSON, XML and YAML files as an Import Source for the Icinga Director and optionally ship hand-crafted additional Icinga2 config files

Icinga Web 2 Fileshipper module The main purpose of this module is to extend Icinga Director using some of it's exported hooks. Based on them it offer

Icinga 25 Sep 18, 2022
CrateKeyShopGUI Pocketmine-MP plugin which can be set in Config.yml file

CrateKeyShopGUI CrateKeyShopGUI Pocketmine-MP plugin which can be set in Config.yml file Depend FormAPI EconomyAPI PiggyCrate InvCrashFix Download Dow

null 4 Jan 7, 2022
🧬 Nano is a zero-config, no skeleton, minimal Hyperf distribution that allows you to quickly build a Hyperf application with just a single PHP file.

Nano is a zero-config, no skeleton, minimal Hyperf distribution that allows you to quickly build a Hyperf application with just a single PHP file.

Hyperf 273 Jan 4, 2023
Basic class library to read, write and view files using PHP.

File Basic class library to read, write and view files using PHP. Supported PHP Versions Build Status (dev) Main Aim of The Library The main aim of th

WebFiori 2 May 13, 2022
Columnar analytics for PHP - a pure PHP library to read and write simple columnar files in a performant way.

Columnar Analytics (in pure PHP) On GitHub: https://github.com/envoymediagroup/columna About the project What does it do? This library allows you to w

Envoy Media Group 2 Sep 26, 2022
A PHP library to write values to .env (DotEnv) files

DotEnvWriter A PHP library to write values to .env (DotEnv) files Installation DotEnvWriter can be installed with Composer. composer require mirazmac/

Miraz Mac 9 May 24, 2022
File Upload widget with multiple file selection, drag&drop support, progress bar, validation and preview images, audio and video for jQuery

File Upload widget with multiple file selection, drag&drop support, progress bar, validation and preview images, audio and video for jQuery. Supports cross-domain, chunked and resumable file uploads. Works with any server-side platform (Google App Engine, PHP, Python, Ruby on Rails, Java, etc.) that supports standard HTML form file uploads.

Sebastian Tschan 31.1k Dec 30, 2022
php-cs-fixer config for REDAXO

php-cs-fixer config for REDAXO Installation composer require --dev redaxo/php-cs-fixer-config Example .php-cs-fixer.dist.php: <?php $finder = (new P

REDAXO CMS c/o Yakamara Media GmbH & Co. KG 7 Aug 14, 2022
📦🚀 Fast, zero config application bundler with PHARs.

Fork of the unmaintained box2 project. This project needs your help! Upgrading from Box2? Checkout the upgrade guide! Goal The Box application simplif

Box Project 865 Dec 26, 2022
phalcon config loader for yaml

Phalcon Config Loarder for Yaml Loads all the yml in the directory of the app/config. Version PHP: 7.0.x, 7.1.x, 7.2.x Phalcon: 3.x Composer { "r

Toshiyuki Ienaga 2 Oct 7, 2022
Default Nginx config for Magento

Default Nginx config for Magento DEMO: https://www.magenx.com Get cloud server: at DigitalOcean magento Magento upto 1.9.x default magento configurati

MagenX 499 Dec 22, 2022
Easily manage git hooks in your composer config

composer-git-hooks Manage git hooks easily in your composer configuration. This command line tool makes it easy to implement a consistent project-wide

Ezinwa Okpoechi 985 Jan 3, 2023
php-cs-fixer config for Yakamara projects

php-cs-fixer config for Yakamara projects Installation composer require --dev yakamara/php-cs-fixer-config Example .php-cs-fixer.dist.php: <?php $fi

Yakamara Media GmbH & Co. KG 4 Nov 29, 2022
Php-file-iterator - FilterIterator implementation that filters files based on a list of suffixes, prefixes, and other exclusion criteria.

php-file-iterator Installation You can add this library as a local, per-project dependency to your project using Composer: composer require phpunit/ph

Sebastian Bergmann 7.1k Jan 3, 2023
Type and shape system for arrays. Help write clearer code when implementing configs for your PocketMine-MP plugin or composer project.

ConfigStruct Type and shape system for arrays. Help write clearer code when implementing configs for your PocketMine-MP plugin or composer project. It

EndermanbugZJFC 9 Aug 22, 2022
🖍 Write beautiful blog articles using Markdown inside your Laravel app.

Blogged Write beautiful blog articles using Markdown inside your Laravel app. Blogged ?? Blogged is a carefully designed Laravel package provides an e

Saleem Hadad 131 Dec 16, 2022
Perch Dashboard app for exporting content to (Kirby) text files and Kirby Blueprint files

toKirby Perch Dashboard app for exporting content to (Kirby) text files and Kirby Blueprint files. You can easily install and test it in a few steps.

R. Banus 4 Jan 15, 2022