class JsonRpcMethod in JSON-RPC 8
Same name and namespace in other branches
- 2.x src/Annotation/JsonRpcMethod.php \Drupal\jsonrpc\Annotation\JsonRpcMethod
Defines a JsonRpcParameterDefinition annotation object.
Hierarchy
- class \Drupal\Component\Annotation\AnnotationBase implements AnnotationInterface
- class \Drupal\jsonrpc\Annotation\JsonRpcMethod implements MethodInterface
Expanded class hierarchy of JsonRpcMethod
See also
\Drupal\jsonrpc\Plugin\JsonRpcServiceManager
2 files declare their use of JsonRpcMethod
- AnnotationNormalizer.php in modules/
jsonrpc_discovery/ src/ Normalizer/ AnnotationNormalizer.php - JsonRpcMethodManager.php in src/
Plugin/ JsonRpcMethodManager.php
1 string reference to 'JsonRpcMethod'
- AnnotationNormalizer::getAnnotationType in modules/
jsonrpc_discovery/ src/ Normalizer/ AnnotationNormalizer.php - Extract the annotation type.
4 classes are annotated with JsonRpcMethod
- AddPermissionToRole in modules/
jsonrpc_core/ src/ Plugin/ jsonrpc/ Method/ AddPermissionToRole.php - A method to add permissions to a role.
- ListPermissions in modules/
jsonrpc_core/ src/ Plugin/ jsonrpc/ Method/ ListPermissions.php - RPC method to list all the permissions.
- Plugins in modules/
jsonrpc_core/ src/ Plugin/ jsonrpc/ Method/ Plugins.php - Lists the plugin definitions of a given type.
- RouteBuilder in modules/
jsonrpc_core/ src/ Plugin/ jsonrpc/ Method/ RouteBuilder.php - RPC method to rebuild the routes.
File
- src/
Annotation/ JsonRpcMethod.php, line 18
Namespace
Drupal\jsonrpc\AnnotationView source
class JsonRpcMethod extends AnnotationBase implements MethodInterface {
/**
* The access required to use this RPC method.
*
* @var mixed
*/
public $access;
/**
* The class method to call.
*
* Optional. If the method ID is 'foo.bar', this defaults to 'bar'. If the
* method ID does not contain a dot (.), defaults to 'execute'.
*
* @var string
*/
public $call;
/**
* How to use this method.
*
* @var \Drupal\Core\Annotation\Translation
*
* @ingroup plugin_translatable
*/
public $usage;
/**
* The parameters for this method.
*
* Can be a keyed array where the parameter names are the keys or an indexed
* array for positional parameters.
*
* @var \Drupal\jsonrpc\Annotation\JsonRpcParameterDefinition[]
*/
public $params = [];
/**
* {@inheritdoc}
*/
public function id() {
return $this
->getId();
}
/**
* {@inheritdoc}
*/
public function call() {
if (!isset($this->call)) {
$this->call = 'execute';
}
return $this->call;
}
/**
* {@inheritdoc}
*/
public function getUsage() {
$this->usage;
}
/**
* {@inheritdoc}
*/
public function getParams() {
return $this->params;
}
/**
* {@inheritdoc}
*/
public function areParamsPositional() {
return array_reduce(array_keys($this
->getParams()), function ($positional, $key) {
return $positional ? !is_string($key) : $positional;
}, TRUE);
}
/**
* {@inheritdoc}
*/
public function get() {
return $this;
}
/**
* {@inheritdoc}
*/
public function access($operation = 'execute', AccountInterface $account = NULL, $return_as_object = FALSE) {
$account = $account ?: \Drupal::currentUser();
switch ($operation) {
case 'execute':
if (is_callable($this->access)) {
return call_user_func_array($this->access, [
$operation,
$account,
$return_as_object,
]);
}
$access_result = AccessResult::allowed();
foreach ($this->access as $permission) {
$access_result = $access_result
->andIf(AccessResult::allowedIfHasPermission($account, $permission));
}
break;
case 'view':
$access_result = $this
->access('execute', $account, $return_as_object);
break;
default:
$access_result = AccessResult::neutral();
break;
}
return $return_as_object ? $access_result : $access_result
->isAllowed();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AnnotationBase:: |
protected | property | The class used for this annotated class. | |
AnnotationBase:: |
public | property | The annotated class ID. | 1 |
AnnotationBase:: |
protected | property | The provider of the annotated class. | |
AnnotationBase:: |
public | function |
Gets the class of the annotated class. Overrides AnnotationInterface:: |
|
AnnotationBase:: |
public | function |
Gets the unique ID for this annotated class. Overrides AnnotationInterface:: |
1 |
AnnotationBase:: |
public | function |
Gets the name of the provider of the annotated class. Overrides AnnotationInterface:: |
|
AnnotationBase:: |
public | function |
Sets the class of the annotated class. Overrides AnnotationInterface:: |
|
AnnotationBase:: |
public | function |
Sets the name of the provider of the annotated class. Overrides AnnotationInterface:: |
|
JsonRpcMethod:: |
public | property | The access required to use this RPC method. | |
JsonRpcMethod:: |
public | property | The class method to call. | |
JsonRpcMethod:: |
public | property | The parameters for this method. | |
JsonRpcMethod:: |
public | property | How to use this method. | |
JsonRpcMethod:: |
public | function |
Checks data value access. Overrides AccessibleInterface:: |
|
JsonRpcMethod:: |
public | function |
Whether the parameters are by-position. Overrides MethodInterface:: |
|
JsonRpcMethod:: |
public | function |
The class method to call. Overrides MethodInterface:: |
|
JsonRpcMethod:: |
public | function |
Gets the value of an annotation. Overrides AnnotationInterface:: |
|
JsonRpcMethod:: |
public | function |
The parameters for this method. Overrides MethodInterface:: |
|
JsonRpcMethod:: |
public | function |
How to use this method. Overrides MethodInterface:: |
|
JsonRpcMethod:: |
public | function |
Gets the unique identifier of the plugin. Overrides PluginDefinitionInterface:: |