Commit 9f46d874 authored by Adrian Rossouw's avatar Adrian Rossouw
Browse files

Flatten the class heirarchy so that server, platform, site are each

children of Environment .. but not of each other.

Added a required context_type field which allowed us to get
rid of the environment factory guesswork.
parent 35f887c0
...@@ -36,19 +36,14 @@ function & d($name = NULL, $root_object = FALSE) { ...@@ -36,19 +36,14 @@ function & d($name = NULL, $root_object = FALSE) {
* Create a new environment object and cache it in the d() static cache function. * Create a new environment object and cache it in the d() static cache function.
*/ */
function provision_environment_factory($name) { function provision_environment_factory($name) {
$classes = array('provisionServer', 'provisionPlatform', 'provisionSite'); $classes = array('server' => 'provisionServer', 'platform' => 'provisionPlatform', 'site' => 'provisionSite');
$options = array_merge(drush_sitealias_get_record($name), drush_get_context('stdin'), drush_get_context('options')); $options = drush_sitealias_get_record($name);
$type = isset($options['context_type']) ? $options['context_type'] : 'server';
$classname = $classes[$type];
if (provisionServer::evaluate($options)) {
$classname = array_shift($classes);
if (provisionPlatform::evaluate($options)) {
$classname = array_shift($classes);
if (provisionSite::evaluate($options)) {
$classname = array_shift($classes);
}
}
}
return new $classname($name); return new $classname($name);
} }
...@@ -102,7 +97,6 @@ class provisionEnvironment { ...@@ -102,7 +97,6 @@ class provisionEnvironment {
function __set($name, $value) { function __set($name, $value) {
if (!property_exists($this, $name)) { if (!property_exists($this, $name)) {
$this->properties[$name] = $value; $this->properties[$name] = $value;
$this->map[$name] = (array_key_exists($name, $this->map)) ? $this->map[$name] : $this->type;
} }
else { else {
$this->$name = $value; $this->$name = $value;
...@@ -143,6 +137,7 @@ class provisionEnvironment { ...@@ -143,6 +137,7 @@ class provisionEnvironment {
* Init stub function/ * Init stub function/
*/ */
function init() { function init() {
$this->setProperty('context_type', 'server');
return true; return true;
} }
...@@ -158,25 +153,17 @@ class provisionEnvironment { ...@@ -158,25 +153,17 @@ class provisionEnvironment {
} }
} }
/**
* Alter the map array to move a value between stacks.
*/
function setMap($field, $context) {
$this->map[$field] = $context;
}
/** /**
* Write out this named context to an alias file. * Write out this named context to an alias file.
*/ */
function write_alias() { function write_alias() {
foreach ($this->map as $key => $type) { $config = new provisionConfig_drushrc_alias($this->name, $this->properties);
if ($type === $this->type) {
$options[$key] = $this->properties[$key];
}
}
$config = new provisionConfig_drushrc_alias($this->name, $options);
$config->write(); $config->write();
} }
function service($service) {
return new provisionService_null($this->name);
}
} }
/** /**
...@@ -187,9 +174,6 @@ class provisionEnvironment { ...@@ -187,9 +174,6 @@ class provisionEnvironment {
*/ */
class provisionServer extends provisionEnvironment { class provisionServer extends provisionEnvironment {
protected $services = array(); protected $services = array();
public static function evaluate($options) {
return TRUE;
}
function init() { function init() {
parent::init(); parent::init();
...@@ -272,10 +256,7 @@ class provisionServer extends provisionEnvironment { ...@@ -272,10 +256,7 @@ class provisionServer extends provisionEnvironment {
/** /**
* Class for the platform environment. * Class for the platform environment.
*/ */
class provisionPlatform extends provisionServer { class provisionPlatform extends provisionEnvironment {
public static function evaluate($options) {
return isset($options['root']);
}
function init() { function init() {
parent::init(); parent::init();
...@@ -285,17 +266,29 @@ class provisionPlatform extends provisionServer { ...@@ -285,17 +266,29 @@ class provisionPlatform extends provisionServer {
// publish path can really be removed ... // publish path can really be removed ...
$this->setProperty('publish_path', $this->root); $this->setProperty('publish_path', $this->root);
$this->setProperty('sites_path', $this->root . '/sites'); $this->setProperty('sites_path', $this->root . '/sites');
$this->setProperty('server');
$this->is_oid('server');
$this->setProperty('web_server'); $this->setProperty('web_server');
$this->is_oid('web_server'); $this->is_oid('web_server');
} }
}
class provisionSite extends provisionPlatform { function verify() {
public static function evaluate($options) { $this->web_server->service('http')->verify();
if ($options['uri']) { }
return true;
function service($service) {
if ($service == 'http') {
return $this->web_server->service($service);
}
else {
return $this->server->service($service);
} }
} }
}
class provisionSite extends provisionEnvironment {
function init() { function init() {
parent::init(); parent::init();
...@@ -308,6 +301,9 @@ class provisionSite extends provisionPlatform { ...@@ -308,6 +301,9 @@ class provisionSite extends provisionPlatform {
$this->setProperty('client_email'); $this->setProperty('client_email');
$this->setProperty('db_server');
$this->is_oid('db_server');
// todo - turn into a re-usable mechanism for comma separated values // todo - turn into a re-usable mechanism for comma separated values
if ($this->options['aliases'] && !is_array($site_data['aliases'])) { if ($this->options['aliases'] && !is_array($site_data['aliases'])) {
$this->aliases = explode(",", $site_data['aliases']); $this->aliases = explode(",", $site_data['aliases']);
......
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