class WSClientServiceDescription in Web service client 7
Class representing web service descriptions.
Hierarchy
- class \Entity implements EntityInterface
- class \WSClientServiceDescription
Expanded class hierarchy of WSClientServiceDescription
1 string reference to 'WSClientServiceDescription'
- wsclient_entity_info in ./
wsclient.module - Implements hook_entity_info().
File
- ./
wsclient.inc, line 11 - Web service client - include file.
View source
class WSClientServiceDescription extends Entity {
public $settings = array();
public $operations = array();
public $datatypes = array();
public $global_parameters = array();
public $global_header_parameters = array();
public $name;
public $label;
public $url;
public $type;
protected $endpoint = NULL;
function __construct($values = array(), $entity_type = 'wsclient_service') {
parent::__construct($values, $entity_type);
}
/**
* Magic method to catch service invocations.
*/
public function __call($operation, $arguments) {
return $this
->invoke($operation, $arguments);
}
/**
* Invoke a service via its endpoint.
*
* @param string $operation
* The name of the operation to execute.
* @param array $arguments
* Arguments to pass to the service with this operation. If the array keys
* do not match the parameter information, the array values are assigned in
* sequential order according to the order of parameters.
*/
public function invoke($operation, array $arguments) {
if (!isset($this->operations[$operation])) {
throw new WSClientException('Operation %operation does not exist for web service %service.', array(
'%operation' => $operation,
'%service' => $this->name,
));
}
$named_arguments = array();
if (isset($this->operations[$operation]['parameter'])) {
$remaining_params = $this->operations[$operation]['parameter'];
// Assign named arguments and hidden parameters.
foreach ($this->operations[$operation]['parameter'] as $param => $info) {
if (isset($arguments[$param])) {
$named_arguments[$param] = $arguments[$param];
unset($arguments[$param]);
unset($remaining_params[$param]);
}
elseif ($info['type'] == 'hidden') {
$named_arguments[$param] = $info['default value'];
unset($remaining_params[$param]);
}
}
// Assign the rest in sequential order.
foreach ($remaining_params as $param => $info) {
$named_arguments[$param] = array_shift($arguments);
}
}
// Fill in global parameters.
foreach ($this->global_parameters as $param => $info) {
if (!isset($named_arguments[$param])) {
$named_arguments[$param] = $info['default value'];
}
}
// Unless explicitly permitted by 'allow null', unset optional parameters
// with NULL or empty ('') values.
if (isset($this->operations[$operation]['parameter'])) {
foreach ($this->operations[$operation]['parameter'] as $param => $info) {
if (isset($info['optional']) && $info['optional'] && (!isset($info['allow null']) || !$info['allow null']) && ($named_arguments[$param] === '' || !isset($named_arguments[$param]))) {
unset($named_arguments[$param]);
}
}
}
drupal_alter('wsclient_invoke_arguments', $named_arguments, $operation, $this);
$response = $this
->endpoint()
->call($operation, $named_arguments);
drupal_alter('wsclient_invoke_response', $response, $operation, $this);
return $response;
}
/**
* Determines access to the web service.
*/
public function access($account = NULL) {
if (method_exists($this
->endpoint(), 'access')) {
return $this
->endpoint()
->access($account);
}
return user_access('interact with ' . $this->name, $account);
}
/**
* Returns the associated web service endpoint object.
*
* @return WSClientEndpointInterface
*/
public function endpoint() {
if (!isset($this->endpoint)) {
$types = wsclient_get_types();
$this->endpoint = new $types[$this->type]['class']($this);
}
return $this->endpoint;
}
/**
* Returns info about the data types of the web service.
*/
public function dataTypes() {
$types = $this->datatypes;
foreach ($types as $type => $info) {
// Add in the service name so that others know where this type comes from.
$types[$type]['service'] = $this->name;
}
return $types;
}
/**
* Returns info about the actions of the web service.
*/
public function actions() {
$actions = array();
foreach ($this->operations as $name => $operation) {
$actions[$name] = $operation += array(
'base' => 'wsclient_service_action',
'named parameter' => TRUE,
);
$actions[$name]['parameter'] = array();
if (isset($operation['parameter'])) {
// Prefix operation parameter names to avoid name clashes.
foreach ((array) $operation['parameter'] as $param => $info) {
$actions[$name]['parameter']['param_' . $param] = $info;
}
}
$actions[$name]['parameter']['service'] = array(
'type' => 'hidden',
'default value' => $this->name,
);
$actions[$name]['parameter']['operation'] = array(
'type' => 'hidden',
'default value' => $name,
);
// Pass through the service result as provided variable.
if (!empty($actions[$name]['result'])) {
$actions[$name]['provides']['result'] = $actions[$name]['result'];
unset($actions[$name]['result']);
}
}
return $actions;
}
public function clearCache() {
$this
->endpoint()
->clearCache();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Entity:: |
protected | property | 1 | |
Entity:: |
protected | property | ||
Entity:: |
protected | property | ||
Entity:: |
protected | property | ||
Entity:: |
protected | property | ||
Entity:: |
public | function |
Builds a structured array representing the entity's content. Overrides EntityInterface:: |
1 |
Entity:: |
public | function |
Returns the bundle of the entity. Overrides EntityInterface:: |
|
Entity:: |
protected | function | Defines the entity label if the 'entity_class_label' callback is used. | 1 |
Entity:: |
protected | function | Override this in order to implement a custom default URI and specify 'entity_class_uri' as 'uri callback' hook_entity_info(). | |
Entity:: |
public | function |
Permanently deletes the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the info of the type of the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the type of the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Exports the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Gets the raw, translated value of a property or field. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Checks if the entity has a certain exportable status. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the entity identifier, i.e. the entities name or numeric id. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the internal, numeric identifier. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Checks whether the entity is the default revision. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the label of the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Permanently saves the entity. Overrides EntityInterface:: |
|
Entity:: |
protected | function | Set up the object instance on construction or unserializiation. | |
Entity:: |
public | function |
Returns the uri of the entity just as entity_uri(). Overrides EntityInterface:: |
|
Entity:: |
public | function |
Generate an array for rendering the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the EntityMetadataWrapper of the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function | Magic method to only serialize what's necessary. | |
Entity:: |
public | function | Magic method to invoke setUp() on unserialization. | |
WSClientServiceDescription:: |
public | property | ||
WSClientServiceDescription:: |
protected | property | ||
WSClientServiceDescription:: |
public | property | ||
WSClientServiceDescription:: |
public | property | ||
WSClientServiceDescription:: |
public | property | ||
WSClientServiceDescription:: |
public | property | ||
WSClientServiceDescription:: |
public | property | ||
WSClientServiceDescription:: |
public | property | ||
WSClientServiceDescription:: |
public | property | ||
WSClientServiceDescription:: |
public | property | ||
WSClientServiceDescription:: |
public | function | Determines access to the web service. | |
WSClientServiceDescription:: |
public | function | Returns info about the actions of the web service. | |
WSClientServiceDescription:: |
public | function | ||
WSClientServiceDescription:: |
public | function | Returns info about the data types of the web service. | |
WSClientServiceDescription:: |
public | function | Returns the associated web service endpoint object. | |
WSClientServiceDescription:: |
public | function | Invoke a service via its endpoint. | |
WSClientServiceDescription:: |
public | function | Magic method to catch service invocations. | |
WSClientServiceDescription:: |
function |
Overrides Entity:: |