diff options
-rw-r--r-- | docs/configuration.rst | 10 | ||||
-rw-r--r-- | idiorm.php | 13 | ||||
-rw-r--r-- | test/ConfigTest.php | 25 |
3 files changed, 47 insertions, 1 deletions
diff --git a/docs/configuration.rst b/docs/configuration.rst index 395a1eb..75d77f7 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -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 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -197,6 +197,19 @@ } /** + * 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 * this way for the sake of a readable interface, ie diff --git a/test/ConfigTest.php b/test/ConfigTest.php index 83194b4..43fe6fa 100644 --- a/test/ConfigTest.php +++ b/test/ConfigTest.php @@ -97,4 +97,27 @@ class ConfigTest extends PHPUnit_Framework_TestCase { $this->tearDownIdColumnOverrides(); } -}
\ No newline at end of file + 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()); + } + +} |