class Config extends Singleton (View source)

Manages configuration options for ActiveRecord.

ActiveRecord::initialize(function($cfg) { $cfg->set_model_home('models'); $cfg->set_connections(array( 'development' => 'mysql://user:pass@development.com/awesome_development', 'production' => 'mysql://user:pass@production.com/awesome_production')); });

Methods

static object
instance()

Static method for instantiating a singleton object.

from Singleton
string
get_called_class()

Similar to a get_called_class() for a child class to invoke.

from Singleton
static void
initialize(Closure $initializer)

Allows config initialization using a closure.

void
set_connections(array $connections, string $default_connection = null)

Sets the list of database connection strings.

array
get_connections()

Returns the connection strings array.

string
get_connection(string $name)

Returns a connection string if found otherwise null.

string
get_default_connection_string()

Returns the default connection string or null if there is none.

string
get_default_connection()

Returns the name of the default connection.

void
set_default_connection(string $name)

Set the name of the default connection.

void
set_model_directory(string $dir)

Sets the directory where models are located.

string
get_model_directory()

Returns the model directory.

void
set_logging(boolean $bool)

Turn on/off logging

void
set_logger(object $logger)

Sets the logger object for future SQL logging

boolean
get_logging()

Return whether or not logging is on

object
get_logger()

Returns the logger

set_date_class($date_class)

No description

get_date_class()

No description

get_date_format() deprecated

No description

set_date_format($format) deprecated

No description

set_cache(string $url, array $options = array())

Sets the url for the cache server to enable query caching.

Details

final static object instance()

Static method for instantiating a singleton object.

Return Value

object

final protected string get_called_class()

Similar to a get_called_class() for a child class to invoke.

Return Value

string

static void initialize(Closure $initializer)

Allows config initialization using a closure.

This method is just syntatic sugar.

ActiveRecord\Config::initialize(function($cfg) { $cfg->set_model_directory('/path/to/your/model_directory'); $cfg->set_connections(array( 'development' => 'mysql://username:password@127.0.0.1/database_name')); });

You can also initialize by grabbing the singleton object:

$cfg = ActiveRecord\Config::instance(); $cfg->set_model_directory('/path/to/your/model_directory'); $cfg->set_connections(array('development' => 'mysql://username:password@localhost/database_name'));

Parameters

Closure $initializer A closure

Return Value

void

void set_connections(array $connections, string $default_connection = null)

Sets the list of database connection strings.

$config->set_connections(array( 'development' => 'mysql://username:password@127.0.0.1/database_name'));

Parameters

array $connections Array of connections
string $default_connection Optionally specify the default_connection

Return Value

void

Exceptions

ConfigException

array get_connections()

Returns the connection strings array.

Return Value

array

string get_connection(string $name)

Returns a connection string if found otherwise null.

Parameters

string $name Name of connection to retrieve

Return Value

string connection info for specified connection name

string get_default_connection_string()

Returns the default connection string or null if there is none.

Return Value

string

string get_default_connection()

Returns the name of the default connection.

Return Value

string

void set_default_connection(string $name)

Set the name of the default connection.

Parameters

string $name Name of a connection in the connections array

Return Value

void

void set_model_directory(string $dir)

Sets the directory where models are located.

Parameters

string $dir Directory path containing your models

Return Value

void

string get_model_directory()

Returns the model directory.

Return Value

string

Exceptions

ConfigException if specified directory was not found

void set_logging(boolean $bool)

Turn on/off logging

Parameters

boolean $bool

Return Value

void

void set_logger(object $logger)

Sets the logger object for future SQL logging

Parameters

object $logger

Return Value

void

Exceptions

ConfigException if Logger objecct does not implement public log()

boolean get_logging()

Return whether or not logging is on

Return Value

boolean

object get_logger()

Returns the logger

Return Value

object

set_date_class($date_class)

Parameters

$date_class

get_date_class()

get_date_format() deprecated

deprecated

set_date_format($format) deprecated

deprecated

Parameters

$format

set_cache(string $url, array $options = array())

Sets the url for the cache server to enable query caching.

Only table schema queries are cached at the moment. A general query cache will follow.

Example:

$config->set_cache("memcached://localhost"); $config->set_cache("memcached://localhost",array("expire" => 60));

Parameters

string $url Url to your cache server.
array $options Array of options