Installation and Configuration Management for the Enchilada Application Framework

A set of libraries allow easy install wizard support for applications using the Enchilada Libraries 3.x

Requirements

  • Enchilada Core Libraries
  • PHP 5.3+

Tortilla Configuration Framework Example

Load required libraries:

<?php
           
include 'EnchiladaLibrary.class.php';
            include
'Configurable.class.php';
            include
'SimpleConfiguration.class.php';
?>

Design Your Configurable Object

Design your configurable entity by extending the 'Configurable' class

<?php
           
class Connection extends Configurable {

            }
?>

List the 'required' configuration options as a comma separated list in a static variable named "Parameters".

<?php
           
class Connection extends Configurable {
                protected static
$Parameters = 'HOST,PORT,USER,PASS';
            }
?>

Setup corresponding private/protected variables. Note: Future versions of this framework will do this for you. For now
You have to do it your self.

<?php
class Connection extends Configurable {
    protected static
$Parameters = 'HOST,PORT,USER,PASS';
    protected
$HOST;
    protected
$PORT;
    protected
$USER;
    protected
$PASS;
    public function
Open() {
        echo
"Connecting to: {$this->HOST}:{$this->PORT} using {$this->USER}:{$this->PASS}";
    }
}
?>

Automatically Generate a Configuration for your Object

Create a new SimpleConfiguration by passing your configuration's class name:

<?php
            $config
= new SimpleConfiguration('Connection');
?>

The configuration options for your object can be obtained as an associative array. Note that the options are
automatically prefixed with your class name.

<?php
            $options
= $config->ListOptions();
           
print_r($options);
?>


		Array
(
    [CONNECTION_HOST] =>
    [CONNECTION_PORT] =>
    [CONNECTION_USER] =>
    [CONNECTION_PASS] =>
)

You can setup the options all at once:

<?php
            $options
['CONNECTION_HOST'] = 'host.domain.tld';
           
$options['CONNECTION_USER'] = 'pperson';
           
$options['CONNECTION_PORT'] = '21';

           
$config->Save($options);
?>

A simple validation feature is included to ensure all required parameters are set

<?php
           
// Returns an array containing missing options
           
$missing_options = $config->Validate();
           
print_r($missing_options);
?>


		Array
(
    [CONNECTION_PASS] =>
)

Options can even be set and accessed directly:

<?php
            $config
->CONNECTION_PASS = '1234';
            echo
$config->CONNECTION_PASS;
?>


		1234		

Get the currently set options:

<?php
           
// Returns an array with current options
           
$current_options = $config->Load();
?>

Applying a Configuration to your Object

Create an instance of your object and apply the configuration:

<?php
            $my_connection
= new Connection();
           
$my_connection->setConfiguration($config);
?>

Your object is now automatically configured for usage:

<?php
            $my_connection
->Open();
?>


		Connecting to: host.domain.tld:21 using pperson:1234
               

Tortilla Installation Framework Example

Take things to the next level with the Installation framework. First load the required library:

<?php
           
include 'SimpleInstaller.class.php';
?>

Install a Configuration

Create a new installer object by specifying the location of the configuration file it can read/write to:

<?php
            $installer
= new SimpleInstaller('config.inc.php');
?>

Save your object's options to persistent storage by 'installing' a configuration file:

<?php
            $installer
->writeConfiguration($config);
?>

What you should end up with is a new file with the following content:

<?php
define
("CONNECTION_HOST", "host.domain.tld");
define("CONNECTION_PORT", "21");
define("CONNECTION_USER", "pperson");
define("CONNECTION_PASS", "1234");
?>

Put it all together

With the Tortilla Installation and Configuration Framework you can load a configuration file
with the required options in order to properly run your application. Here is a full example:

<?php
            $app_installer
= new SimpleInstaller('config.inc.php');
           
$app_config = new SimpleConfiguration('Connection');
           
$app_connection = new Connection();
           
           
$app_config->Save($app_installer->readConfiguration());
           
$app_connection->setConfiguration($app_config);
           
$app_connection->Open();
?>


			Connecting to: host.domain.tld:21 using pperson:1234	
               

Where to get it

The latest version of these libraries can be found on GitHub