PHP code example of bluesteel42 / settings-bundle

1. Go to this page and download the library: Download bluesteel42/settings-bundle 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/ */

    

bluesteel42 / settings-bundle example snippets


// app/AppKernel.php
public function registerBundles()
{
    // ...
    $bundles[] = new BlueSteel42\SettingsBundle\BlueSteel42SettingsBundle();
}
-memcached

//  Get the service
$service = $this->get('bluesteel42.settings');
//  Get a key
$value = $service->get('my_key');
// Get a subkey
$subValue = $service->get('second_key.sub_key.third_level_key');
// Get a key with a default value if not found
$items_per_page = $service->get('items_per_page', 10);

//  Set a key
$service->set('items_per_page', 20);
//  Set a subkey
$service->set('my_key.sub_key','subval1');

$myArray = array('first' => 'red', 'second' => 'blue', 'third' => 'yellow');
$service->set('colors', $myArray);
echo $service->get('colors.first'); // outputs 'red'

$service->set('colors', 'black and white');
echo $service->get('colors.first'); // outputs null
echo $service->get('colors'); // outputs 'black and white'

//  Delete a key
$service->delete('my_key');

//  Flush Modification
$service->flush();

$allValues = array('colors.first' => 'red', 'colors.second' => 'blue'); // wrong

//correct
$allValues = 
    array(
        'colors' => 
            array(
                'first' => 'red', 
                'second' => 'blue'
            )
    );
    
$service->setAll($allValues);

$service->set('controller.one', 1)
    ->set('controller.two', 2)
    ->set('controller.three', 3)
    ->set('controller.four', 4)
    ->flush();
get($key, $default = null)
set($key, $value)
delete($key)
setAll(array $values
set($key, $value)