JsonRpcMethodManager.php in JSON-RPC 8
File
src/Plugin/JsonRpcMethodManager.php
View source
<?php
namespace Drupal\jsonrpc\Plugin;
use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\jsonrpc\Annotation\JsonRpcMethod;
use Drupal\jsonrpc\MethodInterface;
use Drupal\jsonrpc\ParameterFactoryInterface;
class JsonRpcMethodManager extends DefaultPluginManager {
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
$this
->alterInfo(FALSE);
parent::__construct('Plugin/jsonrpc/Method', $namespaces, $module_handler, NULL, JsonRpcMethod::class);
$this
->setCacheBackend($cache_backend, 'jsonrpc_plugins');
}
public function alterDefinitions(&$definitions) {
foreach ($definitions as &$method) {
$this
->assertValidJsonRpcMethodPlugin($method);
if (isset($method->params)) {
foreach ($method->params as $key => &$param) {
$param
->setId($key);
}
}
}
parent::alterDefinitions($definitions);
}
protected function assertValidJsonRpcMethodPlugin(MethodInterface $method) {
foreach ($method->params as $param) {
if (!$param->factory && !$param->schema) {
throw new InvalidPluginDefinitionException($method
->id(), "Every JsonRpcParameterDefinition must define either a factory or a schema.");
}
if ($param->factory && !is_subclass_of($param->factory, ParameterFactoryInterface::class)) {
throw new InvalidPluginDefinitionException($method
->id(), "Parameter factories must implement ParameterFactoryInterface.");
}
}
}
}