2017 © Pedro Peláez
 

cakephp-plugin dynamic-database-config

Utility dynamically compile database config

image

imsamurai/dynamic-database-config

Utility dynamically compile database config

  • Friday, September 19, 2014
  • by imsamurai
  • Repository
  • 1 Watchers
  • 1 Stars
  • 49 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

API Documentation

Check out Dynamic Database Config API Documentation, (*1)

Abstract

Build Status Coverage Status Latest Stable Version Total Downloads Latest Unstable Version License, (*2)

CakePHP DynamicDatabaseConfig Plugin for more flexible handle datasource configs, (*3)

Installation

Step 1: Clone or download to Plugin/DynamicDatabaseConfig

cd my_cake_app/app git://github.com/imsamurai/CakePHP-DynamicDatabaseConfig.git Plugin/DynamicDatabaseConfig, (*4)

or if you use git add as submodule:, (*5)

cd my_cake_app
git submodule add "git://github.com/imsamurai/CakePHP-DynamicDatabaseConfig.git" "app/Plugin/DynamicDatabaseConfig"

then update submodules:, (*6)

git submodule init
git submodule update

Step 2: Extend your DATABASE_CONFIG

:: database.php ::

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


Then make configs that you want to be dynamically loaded (when class instance will be created)

:: database.php ::, (*8)

```php
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 */);
    }
}

Step 3: Load plugin

:: bootstrap.php ::

```php CakePlugin::load('DynamicDatabaseConfig');, (*9)


##Usage Once you add public methods in your DATABASE_CONFIG they will be automatically assigned to public property with same name. Now you can easily make new configs based on part of existing configs. Your old property-based configs will work as usual, unless you create method with same name. ##Advanced usage There exist simple dynamic rename of configs. Assume you want add default config, config for test and public enviroument. In your models used `default` config and you have information about is this public or test, for ex. constant `IS_PUBLIC_INSTALLATION`. In this case you need to add 3 configs, allow renaming and make renaming action:

:: database.php ::, (*10)

```php
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);
    }
}

Thats all! If you have questions or any suggestions you welcome at issues., (*11)

The Versions

19/09 2014

dev-master

9999999-dev http://github.com/imsamurai/CakePHP-DynamicDatabaseConfig

Utility dynamically compile database config

  Sources   Download

MIT

The Requires

 

plugin database config cakephp

19/09 2014

1.0.1

1.0.1.0 http://github.com/imsamurai/CakePHP-DynamicDatabaseConfig

Utility dynamically compile database config

  Sources   Download

MIT

The Requires

 

plugin database config cakephp

06/02 2014

1.0.0

1.0.0.0 http://github.com/imsamurai/CakePHP-DynamicDatabaseConfig

Utility dynamically compile database config

  Sources   Download

MIT

The Requires

 

plugin database config cakephp