Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add static method get_config #141

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}

}