PHP code example of alex-unruh / dot-notation-config
1. Go to this page and download the library: Download alex-unruh/dot-notation-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/ */
alex-unruh / dot-notation-config example snippets
// config/app.php
return [
'app_name' => 'My App',
'app_version' => '1.0.0',
'connection_params' => [
'host' => 'localhost',
'dbname' => 'my_database',
'user' => 'root',
'password' => '',
'port' => '3306'
]
];
// config/messages.php
return [
'internal_error' => 'Internal server error',
400 => 'Bad request'
];
// index.php
use AlexUnruh\Config;
Config::setDir('/config');
// Search data in /config/app.php file
echo Config::get('app.app_name'); // 'My App'
echo Config::get('app.connection_params.host'); // 'localhost'
// Search data in /config/messages.php file
echo Config::get('messages.400'); // 'Bad request'
print_r(Config::get('app')); // Returns all the array data placed in the app file.
// index.php
use AlexUnruh\Config;
$data = [
'app_name' => 'My App',
'app_version' => '1.0.0',
'connection_params' => [
'host' => 'localhost',
'dbname' => 'my_database',
'user' => 'root',
'password' => '',
'port' => '3306'
]
];
Config::setData('my_data', $data);
echo Config::get('my_data.app_name'); // 'My App'
echo Config::get('my_data.connection_params.host'); // 'localhost'
print_r(Config::get('my_data')); // Returns all the array data placed in the my_data array.