method_invoke('init'); $instances[$name]->type_invoke('init'); } return $instances[$name]; } } /** * Simple access layer for drush_sitealias_get_record. * * Everytime sitealiases are fetched a lot of processing happens, but if the * file doesnt exist yet there's a whole lot of unnecesary stuff happening. * * We cache the result locally here. */ function provision_sitealias_get_record($name) { static $cache = array(); $name = provision_normalise_context_name($name); if (!isset($cache[$name])) { $cache[$name] = drush_sitealias_get_record($name); } return $cache[$name]; } /** * Create a new context object. * * @param $name * The name of the context object to instantiate. * @param $allow_creation * Defaults to TRUE. Allows creating a new context object with the specified * $name. * * @return * An instance of the specified context, or NULL if it could not be loaded. */ function provision_context_factory($name, $allow_creation = TRUE) { // the default type, can also be 'platform' or 'site' $type = 'server'; $record = provision_sitealias_get_record($name); if (!$allow_creation && empty($record)) { drush_set_error('PROVISION_MISSING_CONTEXT', dt('Could not find provision alias named: @name' , array('@name' => $name))); return NULL; } $options = array_merge(drush_get_context('stdin'), drush_get_context('options'), drush_get_context('cli')); if (isset($record['context_type'])) { $type = $record['context_type']; } elseif (isset($options['context_type'])) { $type = $options['context_type']; } $classname = "Provision_Context_{$type}"; return new $classname($name); }