XmlRpcExampleController.php in xmlrpc 8
File
xmlrpc_example/src/Controller/XmlRpcExampleController.php
View source
<?php
namespace Drupal\xmlrpc_example\Controller;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Link;
use Drupal\xmlrpc\XmlRpcTrait;
class XmlRpcExampleController extends ControllerBase {
use XmlRpcTrait;
public function info() {
$server = $this
->getEndpoint();
$options = [
'system.listMethods' => [],
];
$supported_methods = xmlrpc($server, $options);
if ($supported_methods === FALSE) {
$this
->messenger()
->addError($this
->t('Error return from xmlrpc(): Error: @errno, Message: @message', [
'@errno' => xmlrpc_errno(),
'@message' => xmlrpc_error_msg(),
]));
}
$build = [
'basic' => [
'#theme' => 'item_list',
'#title' => $this
->t('This XML-RPC example presents code that shows'),
'#items' => [
Link::createFromRoute($this
->t('XML-RPC server code'), 'xmlrpc_example.server'),
Link::createFromRoute($this
->t('XML-RPC client code'), 'xmlrpc_example.client'),
Link::createFromRoute($this
->t('An example hook_xmlrpc_alter() call'), 'xmlrpc_example.alter'),
],
],
'method_array' => [
'#theme' => 'item_list',
'#title' => $this
->t('These methods are supported by :url', [
':url' => UrlHelper::stripDangerousProtocols($server),
]),
'#list_type' => 'ul',
'#items' => $supported_methods,
],
];
return $build;
}
}