summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDurham Hale <[email protected]>2012-08-28 22:44:39 +0100
committerDurham Hale <[email protected]>2012-08-28 22:44:39 +0100
commitb86d2ef4196ce0ab22aad4c836be077ba9051977 (patch)
treeaa0c6d07be3e720f88c41273365a5e9cd5ed53bc
parent5f9a7b4f73dafc55683b607ac5af7cdca64a5d8f (diff)
parent9f382150234e6ce398ec4519d1033e476d4b47f0 (diff)
Merge remote-tracking branch 'jordanlev/configure-with-array' into develop
-rw-r--r--README.markdown8
-rw-r--r--idiorm.php29
2 files changed, 28 insertions, 9 deletions
diff --git a/README.markdown b/README.markdown
index d18ba4e..d148145 100644
--- a/README.markdown
+++ b/README.markdown
@@ -407,6 +407,10 @@ Other than setting the DSN string for the database connection (see above), the `
ORM::configure('setting_name', 'value_for_setting');
+A shortcut is provided to allow passing multiple key/value pairs at once.
+
+ ORM::configure(array('setting_name_1' => 'value_for_setting_1', 'setting_name_2' => 'value_for_setting_2', 'etc' => 'etc'));
+
#### Database authentication details ####
Settings: `username` and `password`
@@ -417,6 +421,10 @@ Some database adapters (such as MySQL) require a username and password to be sup
ORM::configure('username', 'database_user');
ORM::configure('password', 'top_secret');
+Or you can combine the connection setup into a single line using the configuration array shortcut:
+
+ ORM::configure(array('connection_string' => 'mysql:host=localhost;dbname=my_database', 'username' => 'database_user', 'password' => 'top_secret'));
+
#### PDO Driver Options ####
Setting: `driver_options`
diff --git a/idiorm.php b/idiorm.php
index 0296176..9bd61c8 100644
--- a/idiorm.php
+++ b/idiorm.php
@@ -148,18 +148,29 @@
/**
* Pass configuration settings to the class in the form of
* key/value pairs. As a shortcut, if the second argument
- * is omitted, the setting is assumed to be the DSN string
- * used by PDO to connect to the database. Often, this
- * will be the only configuration required to use Idiorm.
+ * is omitted and the key is a string, the setting is
+ * assumed to be the DSN string used by PDO to connect
+ * to the database (often, this will be the only configuration
+ * required to use Idiorm). If you have more than one setting
+ * you wish to configure, another shortcut is to pass an array
+ * of settings (and omit the second argument).
*/
public static function configure($key, $value=null) {
- // Shortcut: If only one argument is passed,
- // assume it's a connection string
- if (is_null($value)) {
- $value = $key;
- $key = 'connection_string';
+ if (is_array($key)) {
+ // Shortcut: If only one array argument is passed,
+ // assume it's an array of configuration settings
+ foreach ($key as $one_key => $one_value) {
+ self::configure($one_key, $one_value);
+ }
+ } else {
+ if (is_null($value)) {
+ // Shortcut: If only one string argument is passed,
+ // assume it's a connection string
+ $value = $key;
+ $key = 'connection_string';
+ }
+ self::$_config[$key] = $value;
}
- self::$_config[$key] = $value;
}
/**