namespace App\Controller;
use PhpXmlRpc\Client;
+use PhpXmlRpc\PhpXmlRpc;
use PhpXmlRpc\Request;
use PhpXmlRpc\Value;
+use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\Routing\Annotation\Route;
+/**
+ * An example usage of the xml-rpc client, configured as a service, from within a Symfony controller
+ */
class ClientController extends AbstractController
{
protected $client;
- public function __construct(Client $client)
+ public function __construct(Client $client, LoggerInterface $logger = null)
{
$this->client = $client;
+ if ($logger) {
+ PhpXmlRpc::setLogger($logger);
+ }
}
#[Route('/getStateName/{stateNo}', name: 'getstatename', methods: ['GET'])]
App\Controller\ClientController:
arguments:
$client: '@App\Service\XmlRpcClient'
+ # in case you want to use a dedicated log file for all xml-rpc related stuff
+ #$logger: '@monolog.logger.xmlrpc'
namespace App\Controller;
+use PhpXmlRpc\PhpXmlRpc;
use PhpXmlRpc\Server;
+use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
{
protected $server;
- public function __construct(Server $server)
+ public function __construct(Server $server, LoggerInterface $logger = null)
{
$this->server = $server;
+ if ($logger) {
+ PhpXmlRpc::setLogger($logger);
+ }
}
# This single method serves ALL the xml-rpc requests.
- # The configuration for which xml-rpc methods exist and how they are handled is carried out in the Server service
+ # The configuration for which xml-rpc methods exist and how they are handled is carried out in the Server service definition
#[Route('/xmlrpc', name: 'xml_rpc', methods: ['POST'])]
public function serve(): Response
{
xml_rpc_server_options: []
services:
- # explicitly configure the services
+ # explicitly configure the services where autowiring is impossible
App\Service\CommentManager:
class: CommentManager
App\Controller\ServerController:
arguments:
$server: '@App\Service\XmlRpcServer'
+ # in case you want to use a dedicated log file for all xml-rpc related stuff
+ #$logger: '@monolog.logger.xmlrpc'