PHP code example of northwoods / config

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

    

northwoods / config example snippets


use Northwoods\Config\ConfigFactory;

$config = ConfigFactory::make([
    'directory' => __DIR__ . '/config',
]);

$token = $config->get('app.timezone');

$config = ConfigFactory::make([
    'directory' => __DIR__ . '/config',
    'environment' => 'dev',
]);

return [
    'database' => [
        'password' => getenv('DATABASE_PASSWORD')
    ],
];

$config = ConfigFactory::make([
    'directory' => __DIR__ . '/config',
    'environment' => 'dev',
    'type' => 'yaml'
]);

use Northwoods\Config\Decorator\VariableDecorator;

// Wrap any existing configuration with the decorator
$config = new VariableDecorator($config);
$config->setVariables(['%cacheDir%' => '/tmp']);

return [
    'emails' => '%cacheDir%/emails',
];

// If not defined, $timezone will be null
$timezone = $config->get('app.timezone');

// If not defined, $timezone will be "UTC"
$timezone = $config->get('app.timezone', 'UTC');

$config->set('app.timezone', 'Europe/Berlin');

use function Northwoods\Config\array_path;
use function Northwoods\Config\array_path_set;

$config = [
    'service' => [
        'uri' => 'http://api.example.com/'
    ],
];

// get a value from an array
$uri = array_path($config, 'service.uri');

// set a value in an array
$config = array_path_set($config, 'service.uri', 'https://api.example.com/v2/')

return [
    'timezone' => "America/New_York"
];