community.aegirproject.org
Services
Services are the way in which new properties are added to contexts, in fact if you wish to store information in a context, this must be done by a service. There is no other way to store data in a context. One might assume that you can just ask provision to save an additional value on a context, but this will not work, and you'll probably get very frustrated indeed!
For example, the provisionService_pdo
service adds a 'master_db' property to the server context, it does this in a method thus:
<?php
function init_server() {
parent::init_server();
$this->server->setProperty('master_db');
}
?>
This means that the 'master_db' property can now be set in a provison-save drush command, and will be persisted when the context is saved.
A service may also define properties on the context as actually representing another context, so that you may access that subcontext directly. You can see an example of using this subcontext in the 'Implementation' section of this Provision Contexts guide, but the an example of how you let provision know that a property name is not just a string, but a named context is with a method on the service:
<?php
/**
* Register the http handler for platforms, based on the web_server option.
*/
static function subscribe_platform($context) {
$context->setProperty('web_server', '@server_master');
$context->is_oid('web_server');
$context->service_subscribe('http', $context->web_server->name);
}
?>
provisionService_http
is being asked to 'subscribe' to a platform, it sets a property on the context, as above, but additional uses the is_oid()
method to indicate that the property is a named context. It then uses that immediately when it gets the name of the web_server context: $context->web_server->name
. We'll worry about what 'subscribing' to a platform means later,.