Skip to content
Damon V. Caskey edited this page Jul 5, 2017 · 5 revisions

Index

Configuration

To promote maximum flexibility and forward compatibility, Yukon uses a system of controlled injection dependency for class options. What this means is that individual arguments and settings controlling class behavior are always encapsulated within one or more configuration classes. If necessary, the configuration classes themselves may have their own configuration classes, continuing on until every group of options is broken down into its own class.

As an example, connection arguments for the primary Database class are controlled by a Connection class, while line output options are controlled by a Line Configuration class. In the case of the Connection class, a smaller subset of options is nested in a Connection Configuration class. See individual class sections for details on their individual dependencies.

Should an object be established from a class that has configuration dependencies and no dependency object is provided, the dependent class will establish any missing configuration dependencies with default options as defined by config.php.

On Construction

Most configuration dependencies may be passed through the dependent class constructor, setting up configuration options as the dependent class object is created. In this example, the connection configuration is established, a few options are set, and the configuration is passed along to a new connection object.

// Establish connection configuration object.
$connect_config = new \dc\yukon\ConnectConfig();
		
// Use application defaults as connection arguments.
$connect_config->set_host(DATABASE::HOST);
$connect_config->set_name(DATABASE::NAME);
$connect_config->set_user(DATABASE::USER);
$connect_config->set_password(DATABASE::PASSWORD);

// Open connection with configuration arguments.
$connection = new dc\yukon\Connect($connect_config);

Existing

Once instantiated, class objects will provide read and write to any of their configuration dependencies via access and mutator method(s).

Alter Dependency

In this example, we will establish the connection object first, and then use an accessor method to get and modify its primary configuration dependency.

// Open connection with default arguments.
$connection = new dc\yukon\Connect();

// Get connection's configuration object.
$connect_config = get_config();
		
// Use application defaults as connection arguments.
$connect_config->set_host(DATABASE::HOST);
$connect_config->set_name(DATABASE::NAME);
$connect_config->set_user(DATABASE::USER);
$connect_config->set_password(DATABASE::PASSWORD);

Replace Dependency

With this example, we will create a new connection configuration class object. We can then use the connection class object's mutator method to replace its connection configuration dependency outright.

// Open connection with default arguments.
$connection = new dc\yukon\Connect();

// Establish new connection configuration object.
$connect_config = new \dc\yukon\ConnectConfig();
		
// Use application defaults as connection arguments.
$connect_config->set_host(DATABASE::HOST);
$connect_config->set_name(DATABASE::NAME);
$connect_config->set_user(DATABASE::USER);
$connect_config->set_password(DATABASE::PASSWORD);

// Replace connection config with the one we just created. 
$connection->set_config($connect_config);