Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/mikejestes/idiorm into de…
Browse files Browse the repository at this point in the history
…velop
  • Loading branch information
treffynnon committed Aug 28, 2013
2 parents cb2841a + a9b6e52 commit 2a3758e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
10 changes: 10 additions & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ once.
'etc' => 'etc'
));
Use the ``get_config`` method to read current settings.

.. code-block:: php
<?php
$isLoggingEnabled = ORM::get_config('logging');
ORM::configure('logging', false);
// some crazy loop we don't want to log
ORM::configure('logging', $isLoggingEnabled);
Database authentication details
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
13 changes: 13 additions & 0 deletions idiorm.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,19 @@ public static function configure($key, $value = null, $connection_name = self::D
}
}

/**
* Retrieve configuration options by key, or as whole array.
* @param string $key
* @param string $connection_name Which connection to use
*/
public static function get_config($key = null, $connection_name = self::DEFAULT_CONNECTION) {
if ($key) {
return self::$_config[$connection_name][$key];
} else {
return self::$_config[$connection_name];
}
}

/**
* Despite its slightly odd name, this is actually the factory
* method used to acquire instances of the class. It is named
Expand Down
25 changes: 24 additions & 1 deletion test/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,27 @@ public function testInstanceIdColumnThree() {
$this->tearDownIdColumnOverrides();
}

}
public function testGetConfig() {
$this->assertTrue(ORM::get_config('logging'));
ORM::configure('logging', false);
$this->assertFalse(ORM::get_config('logging'));
}

public function testGetConfigArray() {
$expected = array(
'connection_string' => 'sqlite::memory:',
'id_column' => 'primary_key',
'id_column_overrides' => array(),
'error_mode' => PDO::ERRMODE_EXCEPTION,
'username' => null,
'password' => null,
'driver_options' => null,
'identifier_quote_character' => '`',
'logging' => true,
'caching' => false,
'return_result_sets' => false,
);
$this->assertEquals($expected, ORM::get_config());
}

}

0 comments on commit 2a3758e

Please sign in to comment.