Commit 534b17a0 authored by Jon Pugh's avatar Jon Pugh

Issue #1966886: First pass at Search and Replace "Context" for "Entity" and "context" and "entity".

parent a476c77c
......@@ -17,11 +17,11 @@ class Provision_Config {
public $data = array();
/**
* A Provision_Context object thie configuration relates to.
* A Provision_Entity object thie configuration relates to.
*
* @var Provision_Context
* @var Provision_Entity
*/
public $context = NULL;
public $entity = NULL;
/**
* If set, replaces file name in log messages.
......@@ -49,32 +49,32 @@ class Provision_Config {
public $store = NULL;
/**
* Forward $this->... to $this->context->...
* Forward $this->... to $this->entity->...
* object.
*/
function __get($name) {
if (isset($this->context)) {
return $this->context->$name;
if (isset($this->entity)) {
return $this->entity->$name;
}
}
/**
* Constructor, overriding not recommended.
*
* @param $context
* An alias name for d(), the Provision_Context that this configuration
* @param $entity
* An alias name for d(), the Provision_Entity that this configuration
* is relevant to.
* @param $data
* An associative array to potentially manipulate in process() and make
* available as variables to the template.
*/
function __construct($context, $data = array()) {
function __construct($entity, $data = array()) {
if (is_null($this->template)) {
throw new Exception(dt("No template specified for: %class", array('%class' => get_class($this))));
}
// Accept both a reference and an alias name for the context.
$this->context = is_object($context) ? $context : d($context);
// Accept both a reference and an alias name for the entity.
$this->entity = is_object($entity) ? $entity : d($entity);
if (sizeof($data)) {
$this->data = $data;
......@@ -82,7 +82,7 @@ class Provision_Config {
if (!is_null($this->data_store_class) && class_exists($this->data_store_class)) {
$class = $this->data_store_class;
$this->store = new $class($context, $data);
$this->store = new $class($entity, $data);
}
}
......
......@@ -28,8 +28,8 @@ class Provision_Config_Data_Store extends Provision_Config {
protected $mode = 0700;
function __construct($context, $data = array()) {
parent::__construct($context, $data);
function __construct($entity, $data = array()) {
parent::__construct($entity, $data);
$this->load_data();
}
......
......@@ -27,7 +27,7 @@ class Provision_Config_Drupal_Settings extends Provision_Config {
}
$this->version = provision_version();
$this->api_version = provision_api_version();
$this->cloaked = drush_get_option('provision_db_cloaking', $this->context->service('http')->cloaked_db_creds());
$this->cloaked = drush_get_option('provision_db_cloaking', $this->entity->service('http')->cloaked_db_creds());
if (provision_hosting_feature_enabled('subdirs')) {
$this->data['subdirs_support_enabled'] = TRUE;
}
......
......@@ -14,24 +14,24 @@ class Provision_Config_Drushrc extends Provision_Config {
public $template = 'provision_drushrc.tpl.php';
public $description = 'Drush configuration file';
protected $mode = 0440;
protected $context_name = 'drush';
protected $entity_name = 'drush';
function filename() {
return _drush_config_file($this->context_name);
return _drush_config_file($this->entity_name);
}
function __construct($context, $data = array()) {
parent::__construct($context, $data);
function __construct($entity, $data = array()) {
parent::__construct($entity, $data);
$this->load_data();
}
function load_data() {
// we fetch the context to pass into the template based on the context name
$this->data = array_merge(drush_get_context($this->context_name), $this->data);
// we fetch the entity to pass into the template based on the entity name
$this->data = array_merge(drush_get_entity($this->entity_name), $this->data);
}
function process() {
unset($this->data['context-path']);
unset($this->data['entity-path']);
unset($this->data['config-file']);
$this->data['option_keys'] = array_keys($this->data);
}
......
......@@ -8,12 +8,12 @@
* Class for writing the /var/aegir/.drush/drushrc.php file.
*/
class Provision_Config_Drushrc_Aegir extends Provision_Config_Drushrc {
protected $context_name = 'home.drush';
protected $entity_name = 'home.drush';
public $template = 'provision_drushrc_aegir.tpl.php';
public $description = 'Aegir Drush configuration file';
function __construct($context = '@none', $data = array()) {
parent::__construct($context, $data);
function __construct($entity = '@none', $data = array()) {
parent::__construct($entity, $data);
$this->load_data();
}
......
......@@ -12,14 +12,14 @@ class Provision_Config_Drushrc_Alias extends Provision_Config_Drushrc {
/**
* @param $name
* String '\@name' for named context.
* String '\@name' for named entity.
* @param $options
* Array of string option names to save.
*/
function __construct($context, $data = array()) {
parent::__construct($context, $data);
function __construct($entity, $data = array()) {
parent::__construct($entity, $data);
$this->data = array(
'aliasname' => ltrim($context, '@'),
'aliasname' => ltrim($entity, '@'),
'options' => $data,
);
}
......
......@@ -8,7 +8,7 @@
* Class for writing $platform/drushrc.php files.
*/
class Provision_Config_Drushrc_Platform extends Provision_Config_Drushrc {
protected $context_name = 'drupal';
protected $entity_name = 'drupal';
public $description = 'Platform Drush configuration file';
// platforms contain no confidential information
protected $mode = 0444;
......
......@@ -8,6 +8,6 @@
* Server level config for drushrc.php files.
*/
class Provision_Config_Drushrc_Server extends Provision_Config_Drushrc {
protected $context_name = 'user';
protected $entity_name = 'user';
public $description = 'Server drush configuration';
}
......@@ -8,7 +8,7 @@
* Class for writing $platform/sites/$url/drushrc.php files.
*/
class Provision_Config_Drushrc_Site extends Provision_Config_Drushrc {
protected $context_name = 'site';
protected $entity_name = 'site';
public $template = 'provision_drushrc_site.tpl.php';
public $description = 'Site Drush configuration file';
......
<?php
/**
* @file
* Provides the Provision_Context class.
* Provides the Provision_Entity class.
*/
/**
* Base context class.
* Base entity class.
*
* Contains magic getter/setter functions
*/
class Provision_Context {
class Provision_Entity {
/**
* Name for saving aliases and referencing.
*/
......@@ -28,7 +28,7 @@ class Provision_Context {
protected $properties = array();
/**
* Keeps track of properites that are names of Provision_Context objects.
* Keeps track of properites that are names of Provision_Entity objects.
* Set with is_oid().
*/
protected $oid_map = array();
......@@ -38,7 +38,7 @@ class Provision_Context {
/**
* Retrieve value from $properties array if property does not exist in class
* proper. Properties that refer to Provision_Context objects will be run
* proper. Properties that refer to Provision_Entity objects will be run
* through d(), see is_oid().
*
* TODO: consider returning a reference to the value, so we can do things like:
......@@ -63,7 +63,7 @@ class Provision_Context {
}
/**
* Specify that a property contains a named context.
* Specify that a property contains a named entity.
*/
function is_oid($name) {
$this->oid_map[$name] = TRUE;
......@@ -121,7 +121,7 @@ class Provision_Context {
function method_invoke($func, $args = array(), $services = TRUE) {
provision::method_invoke($this, $func, $args);
// Services will be invoked regardless of the existence of a
// implementation in the context class.
// implementation in the entity class.
if ($services) {
$this->services_invoke($func, $args);
}
......@@ -131,7 +131,7 @@ class Provision_Context {
* Execute the method for the current object type.
*
* This function is used to avoid having to conditionally
* check the context objects type to execute the correct code.
* check the entity objects type to execute the correct code.
*
* This will generate a function call like : $method_$type,
* ie: $this->init_server().
......@@ -148,7 +148,7 @@ class Provision_Context {
*
* This method provides a general case for extending drush commands.
* This allows the developer to not have to conditionally check the
* context object type in all his methods, and reduces the need
* entity object type in all his methods, and reduces the need
* to define drush_hook_$command methods for a lot of cases.
*
* This will generate a function call like : $method_$type_cmd.
......@@ -158,7 +158,7 @@ class Provision_Context {
}
/**
* Constructor for the context.
* Constructor for the entity.
*/
function __construct($name) {
$this->name = $name;
......@@ -170,9 +170,9 @@ class Provision_Context {
function init() {
preg_match("/^Provision_Context_(.*)$/", get_class($this), $matches);
$this->type = $matches[1];
$this->setProperty('context_type', $this->type);
$this->setProperty('entity_type', $this->type);
// Set up the parent of this context object.
// Set up the parent of this entity object.
if (!is_null($this->parent_key)) {
$this->setProperty($this->parent_key);
$this->is_oid($this->parent_key);
......@@ -215,7 +215,7 @@ class Provision_Context {
}
/**
* Write out this named context to an alias file.
* Write out this named entity to an alias file.
*/
function write_alias() {
$config = new Provision_Config_Drushrc_Alias($this->name, $this->properties);
......@@ -226,7 +226,7 @@ class Provision_Context {
* Subscribe a service handler.
*
* All future calls to $this->service($service) will be redirected
* to the context object of #name you specify.
* to the entity object of #name you specify.
*/
function service_subscribe($service, $name) {
$this->service_subs[$service] = $name;
......@@ -242,7 +242,7 @@ class Provision_Context {
* @param $service
* Service type, such as 'http' or 'db'
* @param $name
* Override service owner with a context name as accepted by d().
* Override service owner with a entity name as accepted by d().
*
* @return
* A Provision_Service object.
......@@ -260,7 +260,7 @@ class Provision_Context {
}
/**
* Call method $callback on each of the context's service objects.
* Call method $callback on each of the entity's service objects.
*
* @param $callback
* A Provision_Service method.
......@@ -303,7 +303,7 @@ class Provision_Context {
}
/**
* Return context-specific configuration options for help.
* Return entity-specific configuration options for help.
*
* @return
* array('option' => 'description')
......
<?php
/**
* @file Provision named context platform class.
* @file Provision named entity platform class.
*/
/**
* Class for the platform context.
* Class for the platform entity.
*/
class Provision_Context_platform extends Provision_Context {
class Provision_Entity_platform extends Provision_Entity {
public $parent_key = 'server';
static function option_documentation() {
......
<?php
/**
* @file Provision named context server class.
* @file Provision named entity server class.
*/
/**
* Server context class.
* Server entity class.
*
* This class bootstraps the Service API by generating server
* objects for each of the available service types.
*/
class Provision_Context_server extends Provision_Context {
class Provision_Entity_server extends Provision_Entity {
/**
* Associative array of services for this server.
*
......@@ -115,10 +115,10 @@ class Provision_Context_server extends Provision_Context {
}
/**
* Retrieve a service of a specific type from the context.
* Retrieve a service of a specific type from the entity.
*/
function service($service, $name = null) {
$this->services[$service]->setContext(($name) ? $name : $this->name);
$this->services[$service]->setEntity(($name) ? $name : $this->name);
return $this->services[$service];
}
......@@ -164,7 +164,7 @@ class Provision_Context_server extends Provision_Context {
* Full path to sync.
* @param $additional_options
* An array of options that overrides whatever was passed in on the command
* line (like the 'process' context, but only for the scope of this one
* line (like the 'process' entity, but only for the scope of this one
* call).
*/
function sync($path = NULL, $additional_options = array()) {
......@@ -213,7 +213,7 @@ class Provision_Context_server extends Provision_Context {
* Full path to fetch.
* @param $additional_options
* An array of options that overrides whatever was passed in on the command
* line (like the 'process' context, but only for the scope of this one
* line (like the 'process' entity, but only for the scope of this one
* call).
*/
function fetch($path, $additional_options = array()) {
......
<?php
/**
* @file Provision named context site class.
* @file Provision named entity site class.
*/
class Provision_Context_site extends Provision_Context {
class Provision_Entity_site extends Provision_Entity {
public $parent_key = 'platform';
static function option_documentation() {
......
......@@ -15,14 +15,14 @@ class Provision_Service extends Provision_ChainedState {
protected $server = '@server_master';
/**
* The context in which this service stores its data
* The entity in which this service stores its data
*
* This is usually an object made from a class derived from the
* Provision_Context base class
* Provision_Entity base class
*
* @see Provision_Context
* @see Provision_Entity
*/
public $context;
public $entity;
protected $service = NULL;
protected $application_name = NULL;
......@@ -110,15 +110,15 @@ class Provision_Service extends Provision_ChainedState {
$data = array('name' => $data);
}
if (!isset($this->config_cache[$this->context->name][$config])) {
$this->config_cache[$this->context->name][$config] = array();
if (!isset($this->config_cache[$this->entity->name][$config])) {
$this->config_cache[$this->entity->name][$config] = array();
foreach ((array) $this->configs[$config] as $class) {
$this->config_cache[$this->context->name][$config][] = new $class($this->context, array_merge($this->config_data($config), $data));
$this->config_cache[$this->entity->name][$config][] = new $class($this->entity, array_merge($this->config_data($config), $data));
}
}
if (isset($this->config_cache[$this->context->name][$config])) {
$this->_config = $this->config_cache[$this->context->name][$config];
if (isset($this->config_cache[$this->entity->name][$config])) {
$this->_config = $this->config_cache[$this->entity->name][$config];
}
return $this;
......@@ -299,17 +299,17 @@ class Provision_Service extends Provision_ChainedState {
}
/**
* Set the currently active context of the service.
* Set the currently active entity of the service.
*
* @arg mixed $context
* the context to store this services data into. this can be an
* @arg mixed $entity
* the entity to store this services data into. this can be an
* object, or a string in which case the object will be loaded
* dynamically with d()
*
* @see d()
*/
function setContext($context) {
$this->context = is_object($context) ? $context : d($context);
function setEntity($entity) {
$this->entity = is_object($entity) ? $entity : d($entity);
}
/**
......
......@@ -237,7 +237,7 @@ class Provision_Service_db extends Provision_Service {
/**
* Return a hostname suitable for database grants from a server object.
*/
function grant_host(Provision_Context_server $server) {
function grant_host(Provision_Entity_server $server) {
return $server->remote_host;
}
}
......@@ -125,7 +125,7 @@ class Provision_Service_db_mysql extends Provision_Service_db_pdo {
}
}
function grant_host(Provision_Context_server $server) {
function grant_host(Provision_Entity_server $server) {
$command = sprintf('mysql -u intntnllyInvalid -h %s -P %s -e "SELECT VERSION()"',
escapeshellarg($this->server->remote_host),
escapeshellarg($this->server->db_port));
......
......@@ -16,7 +16,7 @@
* $name.
*
* @return
* provision_Context object or NULL if it can't be loaded and
* provision_Entity object or NULL if it can't be loaded and
* $allow_creation == FALSE.
*/
function & d($name = NULL, $_root_object = FALSE, $allow_creation = TRUE) {
......@@ -103,7 +103,7 @@ function provision_context_factory($name, $allow_creation = TRUE) {
elseif (isset($options['context_type'])) {
$type = $options['context_type'];
}
$classname = "Provision_Context_{$type}";
$classname = "Provision_Entity_{$type}";
return new $classname($name);
}
......@@ -89,12 +89,12 @@ function provision_drush_command() {
$items['provision-save'] = array(
'description' => dt('Save Drush alias'),
'arguments' => array(
'@context_name' => 'Context to save',
'@context_name' => 'Entity to save',
),
'options' => array_merge(array(
'context_type' => 'server, platform, or site; default server',
'delete' => 'Remove the alias.',
), Provision_Context_server::option_documentation(), Provision_Context_platform::option_documentation(), Provision_Context_site::option_documentation()),
), Provision_Entity_server::option_documentation(), Provision_Entity_platform::option_documentation(), Provision_Entity_site::option_documentation()),
// we should populate from all known contexts, unfortunately we don't
// enumerate them yet... see https://drupal.org/node/1972286
'allow-additional-options' => TRUE,
......
......@@ -45,7 +45,7 @@ function drush_provision_hostmaster_uninstall() {
drush_log(dt("Destroying @resource", array('@resource' => $resource->uri)));
$context = $resource->context;
if (!$context) {
drush_log(dt('Context missing for resource @resource, guessing', array('@resource' => $resource->uri)), 'warning');
drush_log(dt('Entity missing for resource @resource, guessing', array('@resource' => $resource->uri)), 'warning');
$context = $resource->uri;
}
provision_backend_invoke($context, 'provision-delete');
......@@ -57,7 +57,7 @@ function drush_provision_hostmaster_uninstall() {
drush_log(dt("Destroying @resource", array('@resource' => $resource->uri)));
$context = $resource->context;
if (!$context) {
drush_log(dt('Context missing for platform @resource, ignoring', array('@resource' => $resource->uri)), 'warning');
drush_log(dt('Entity missing for platform @resource, ignoring', array('@resource' => $resource->uri)), 'warning');
} else {
provision_backend_invoke($context, 'provision-delete');
}
......@@ -69,7 +69,7 @@ function drush_provision_hostmaster_uninstall() {
drush_log(dt("Destroying @resource", array('@resource' => $resource->uri)));
$context = $resource->context;
if (!$context) {
drush_log(dt('Context missing for platform @resource, ignoring', array('@resource' => $resource->uri)), 'warning');
drush_log(dt('Entity missing for platform @resource, ignoring', array('@resource' => $resource->uri)), 'warning');
} else {
provision_backend_invoke($context, 'provision-delete');
}
......
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