Commit 0c39b00e authored by Adrian Rossouw's avatar Adrian Rossouw

introduced the environment and the env factory stuff.

moved the services to be properties of the env object.
parent 19a68535
......@@ -11,14 +11,11 @@
include_once(dirname(__FILE__) . '/../provision.service.inc');
function db_drush_init() {
$command = drush_get_command();
$command = explode(" ", $command['command']);
if (preg_match("/^provision-/", $command[0])) {
provisionService::spawn('db', 'mysql');
}
function db_provision_services() {
return array('db' => 'mysql');
}
function db_drush_exit() {
// determine how to close it too.
provision_service('db')->close();
......
......@@ -11,19 +11,21 @@
include_once(dirname(__FILE__) . '/../provision.service.inc');
function file_drush_init() {
$command = drush_get_command();
$command = explode(" ", $command['command']);
if (preg_match("/^provision-/", $command[0])) {
provision_service('file', new provisionService_file());
}
function file_provision_services() {
return array('file' => 'local');
}
function file_drush_exit() {
// todo sync out to other servers
//provision_service('file')->sync();
}
class provisionService_file_local extends provisionService_file {
}
class provisionService_file extends provisionService {
/**
* Perform tasks on a path.
......
......@@ -2,14 +2,12 @@
include_once(dirname(__FILE__) . '/../provision.service.inc');
function http_drush_init() {
$command = drush_get_command();
$command = explode(" ", $command['command']);
if (preg_match("/^provision-/", $command[0])) {
provisionService::spawn('http', 'apache');
}
function http_provision_services() {
return array('http' => 'apache');
}
class provisionService_http extends provisionService {
function init() {
// Set up defines for platform
......
......@@ -53,6 +53,7 @@ function provision_drupal_drush_init($url = NULL) {
if (preg_match("/^provision-/", $command[0])) {
if ($url) {
// this stuff gets moved to environment
drush_set_option('uri' , 'http://' . $url);
provision_load_site_data($url);
drush_set_default('site_url', $url);
......
......@@ -60,6 +60,9 @@ include_once('provision.inc');
* @see provision_load_critical()
*/
function provision_drush_init() {
d('@self', provision_environment_factory(drush_get_merged_options()));
print_r(d());
$load = sys_getloadavg();
if (provision_load_critical($load)) {
drush_set_error('PROVISION_OVERLOAD', dt("load on system too heavy (@load), aborting", array('@load' => join(" ", $load))));
......
......@@ -14,14 +14,31 @@ function provision_environment_factory($options) {
}
$object = new $classname($options);
$object->init();
$object->clean();
return $object;
}
function & d($short_name = '@self', $object = null) {
static $instances = null;
if (is_object($object)) {
$instances[$short_name] = $object;
}
if (isset($instances[$short_name])) {
return $instances[$short_name];
}
return $instances['@self'];
}
class provisionEnvironment {
protected $options = array();
protected $properties = array();
protected $map = array();
protected $short_name = null;
protected $type = null;
function __get($name) {
......@@ -61,6 +78,10 @@ class provisionEnvironment {
$this->options = $options;
}
function init() {
return true;
}
function clean() {
$this->options = array();
}
......@@ -90,8 +111,46 @@ class provisionServer extends provisionEnvironment {
$this->setProperty('remote_host', 'localhost');
$this->setProperty('script_user', get_current_user());
$this->setProperty('aegir_root', '/var/aegir');
$this->setProperty('config_path', $this->aegir_root . '/config');
$this->setProperty('backup_path', $this->aegir_root . '/backup');
$this->setProperty('config_path', $this->aegir_root . '/config');
$this->setProperty('alias_path', $this->config_path . '/drush.d');
}
function init() {
parent::init();
$this->load_services();
}
function load_services() {
$service_list = drush_command_invoke_all('provision_services');
foreach ($service_list as $service => $default) {
$this->spawn_service($service, $default);
}
}
function spawn_service($service, $default = null) {
$reflect = new reflectionClass('provisionService_' . $service);
$base_dir = dirname($reflect->getFilename());
$type_option = "$service-service-type";
$type = isset($this->options[$type_option]) ? $this->options[$type_option] : $default;
if ($type) {
$file = sprintf("%s/%s/%s_service.inc", $base_dir, $type, $type);
$className = sprintf("provisionService_%s_%s", $service, $type);
if (file_exists($file)) {
drush_log("Loading $type driver for the $service service");
include_once($file);
$object = new $className();
$object->init();
$this->$service = $object;
}
}
else {
$this->$service = new provisionService_null();
}
}
}
......
<?php
// $Id$
include_once('provision.environment.inc');
include_once('provision.service.inc');
/**
* @file
......
......@@ -10,26 +10,6 @@ class provisionService {
return TRUE;
}
static function spawn($service, $default = null) {
$reflect = new reflectionClass('provisionService_' . $service);
$base_dir = dirname($reflect->getFilename());
$type = drush_get_option($service . '-service-type', $default);
if ($type) {
$file = sprintf("%s/%s/%s_service.inc", $base_dir, $type, $type);
$className = sprintf("provisionService_%s_%s", $service, $type);
if (file_exists($file)) {
drush_log("Loading $type driver for the $service service");
include_once($file);
provision_service($service, new $className())->init();
return TRUE;
}
}
return false;
}
}
......@@ -122,18 +102,7 @@ class provisionService_null extends provisionService {
}
}
provision_service('null', new provisionService_null());
function provision_service($type, $object = null) {
static $instances = null;
if (is_object($object)) {
$instances[$type] = $object;
}
if (isset($instances[$type])) {
return $instances[$type];
}
return $instances['null'];
return d()->$type;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment