PHP code example of stillat / proteus

1. Go to this page and download the library: Download stillat/proteus library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

stillat / proteus example snippets




Stillat\Proteus\Support\Facades\ConfigWriter;

// Change the default locale to 'fr' and save to disk:
ConfigWriter::write('app.locale', 'fr');

// Add a new nested entry:
ConfigWriter::write('app.new.entry', 'new-value');

// And then update that new entry:
ConfigWriter::write('app.new.entry', 'updated-value');




Stillat\Proteus\Support\Facades\ConfigWriter;


ConfigWriter::writeMany('app', [
    'locale' => 'fr',
    'timezone' => 'Europe/Paris'
]);





Stillat\Proteus\Support\Facades\ConfigWriter;

$document = ConfigWriter::preview('app.locale', 'fr');

$document = ConfigWriter::previewMany('app', [
    'locale' => 'fr',
    'timezone' => 'Europe/Paris'
]);





Stillat\Proteus\Support\Facades\ConfigWriter;

ConfigWriter::guard('app.key');




Stillat\Proteus\Support\Facades\ConfigWriter;

ConfigWriter::guard('app.*');




Stillat\Proteus\Support\Facades\ConfigWriter;

ConfigWriter::guard('app.providers*');




Stillat\Proteus\Support\Facades\ConfigWriter;

// Calls to env, and other functions, will be updated.
ConfigWriter::ignoreFunctionCalls(false)->writeMany('app', [
    'key' => 'new-value',
    'locale' => 'fr',
    'timezone' => 'Europe/Paris'
]);



Stillat\Proteus\Support\Facades\ConfigWriter;

// Changes to locale and timezone will be ignored, since they will be preserved.
ConfigWriter::preserve([
    'locale', 'timezone'
])->writeMany('app', [
    'locale' => 'fr',
    'timezone' => 'Europe/Paris'
]);



use Stillat\Proteus\Support\Facades\ConfigWriter;

$document = ConfigWriter::edit('app')
    ->set('locale', 'fr')
    ->set('timezone', 'Europe/Paris')
    ->preview();



use Stillat\Proteus\Support\Facades\ConfigWriter;

$document = ConfigWriter::edit('app')
    ->set([
        'locale' => 'fr',
        'timezone' => 'Europe/Paris'  
    ])->preview();



use Stillat\Proteus\Support\Facades\ConfigWriter;

ConfigWriter::edit('app')
    ->set([
        'locale' => 'fr',
        'timezone' => 'Europe/Paris'  
    ])->save();



use Stillat\Proteus\Support\Facades\ConfigWriter;

ConfigWriter::edit('app')->remove('locale')->save();



use Stillat\Proteus\Support\Facades\ConfigWriter;

ConfigWriter::edit('app')->replace('providers', [
    // The new list of providers.
])->save();



use Stillat\Proteus\Support\Facades\ConfigWriter;

ConfigWriter::edit('app')->merge('providers', [
    SomeProvider::class,
    SomeOtherProvider::class
])->save();



use Stillat\Proteus\Support\Facades\ConfigWriter;

ConfigWriter::edit('app')
    ->set([
        'locale' => 'fr',
        'timezone' => 'Europe/Paris'  
    ])->merge('providers', [
        SomeProvider::class,
        SomeOtherProvider::class
    ])->set('fallback_locale', 'fr')->save();



use Stillat\Proteus\Support\Facades\ConfigWriter;

ConfigWriter::write('custom.path', ConfigWriter::f()->basePath('relative'));

return [

    'path' => base_path('relative'),

];



use Stillat\Proteus\Support\Facades\ConfigWriter;

// base_path
ConfigWriter::write('custom.path', ConfigWriter::f()->basePath('relative'));

// storage_path
ConfigWriter::write('custom.path', ConfigWriter::f()->storagePath('relative'));

// app_path
ConfigWriter::write('custom.path', ConfigWriter::f()->appPath('relative'));

// config_path
ConfigWriter::write('custom.path', ConfigWriter::f()->configPath('relative'));

// database_path
ConfigWriter::write('custom.path', ConfigWriter::f()->databasePath('relative'));

// public_path
ConfigWriter::write('custom.path', ConfigWriter::f()->publicPath('relative'));

// resource_path
ConfigWriter::write('custom.path', ConfigWriter::f()->resourcePath('relative'));

return [

    'key' => env('APP_KEY'),

];

use Stillat\Proteus\ConfigUpdater;

$updater = new ConfigUpdater();
$updater->open('./path/to/config.php');
$updater->update([
    'key' => 'new-key',
    'new' => [
        'deeply' => [
            'nested' => [
                'key' => [
                    'hello',
                    'world'
                ]
            ]        
        ]
    ]
]);

$newConfigContents = $updater->getDocument();



return [

    'key' => env('APP_KEY', 'new-key'),
    'new' => [
        'deeply' => [
            'nested' => [
                'key' => [
                    'hello',
                    'world',
                ],
            ],
        ],
    ],

];