PHP code example of imsamurai / dynamic-database-config

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

    

imsamurai / dynamic-database-config example snippets


App::uses('DynamicDatabaseConfig', 'DynamicDatabaseConfig.Config');
class DATABASE_CONFIG extends DynamicDatabaseConfig {
	//class items
}

App::uses('DynamicDatabaseConfig', 'DynamicDatabaseConfig.Config');
class DATABASE_CONFIG extends DynamicDatabaseConfig {
	//can't start with _ and must be public
	public defaultPublic() {
		return array(/* config data, like in property-config */);
	}
}


CakePlugin::load('DynamicDatabaseConfig');


App::uses('DynamicDatabaseConfig', 'DynamicDatabaseConfig.Config');
class DATABASE_CONFIG extends DynamicDatabaseConfig {

	//allow to rename configs
	const APPLY_NAMING_SCHEMA = true;

	//default config
	public default() {
		return array(/* config data, like in property-config */);
	}

	//public config
	public defaultPublic() {
		return array(/* config data, like in property-config */);
	}

	/local config
	public defaultLocal() {
		return array(/* config data, like in property-config */);
	}

	/* Method that will get each existing config name and try to rename it
	 * if $configName will not equals to returned value then
	 * config with returned value name will be erased with data from $configName
     *
	 * In case of current method if IS_PUBLIC_INSTALLATION is true
	 * `default` config gets data from `defaultPublic` otherwise from `defaultLocal`
	 */
	protected function _renameConfig($configName) {
		$postfix = IS_PUBLIC_INSTALLATION ? 'Public' : 'Local';
		return preg_replace('/(.*)' . $postfix . '$/', '\1', $configName);
	}
}

:: database.php ::

:: database.php ::

:: bootstrap.php ::

:: database.php ::