Singleton
   |
   --Config

Class Details

Manages configuration options for ActiveRecord.

 ActiveRecord::initialize(function($cfg) {
   $cfg->set_model_home('models');
   $cfg->set_connections(array(
     'development' => 'mysql://user:[email protected]/awesome_development',
     'production' => 'mysql://user:[email protected]/awesome_production'));
 });

	


Class Methods

public string get_connection ( string $name )

Returns a connection string if found otherwise null.

  • string $name - Name of connection to retrieve
  • return: connection info for specified connection name
public array get_connections ( )

Returns the connection strings array.

public void get_date_format ( )
  • deprecated:
public string get_default_connection ( )

Returns the name of the default connection.

public string get_default_connection_string ( )

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

public object get_logger ( )

Returns the logger

public boolean get_logging ( )

Return whether or not logging is on

public string get_model_directory ( )

Returns the model directory.

  • throws: ConfigException if specified directory was not found
public static void initialize ( $initializer )

Allows config initialization using a closure.

  • Closure $initializer - 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:[email protected]/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'));

	

public void set_cache ( string $url , [ array $options = array()] )

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

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

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));

	

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

Sets the list of database connection strings.

  • array $connections - Array of connections
  • string $default_connection - Optionally specify the default_connection
  • throws: ActiveRecord\ConfigException

 $config->set_connections(array(
     'development' => 'mysql://username:[email protected]/database_name'));

	

public void set_date_format ( $format )
  • $format -
  • deprecated:
public void set_default_connection ( string $name )

Set the name of the default connection.

  • string $name - Name of a connection in the connections array
public void set_logger ( object $logger )

Sets the logger object for future SQL logging

  • object $logger -
  • throws: ConfigException if Logger objecct does not implement public log()
public void set_logging ( boolean $bool )

Turn on/off logging

  • boolean $bool -
public void set_model_directory ( string $dir )

Sets the directory where models are located.

  • string $dir - Directory path containing your models