From: gggeek Date: Tue, 31 Jan 2023 18:50:53 +0000 (+0000) Subject: add demo code for Symfony X-Git-Tag: 4.10.0~52 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=792a3ae7edf2d884a5c5370816e50236aec3022b;p=plcapi.git add demo code for Symfony --- diff --git a/demo/client/symfony/ClientController.php b/demo/client/symfony/ClientController.php new file mode 100644 index 00000000..b42ed0d6 --- /dev/null +++ b/demo/client/symfony/ClientController.php @@ -0,0 +1,34 @@ +client = $client; + } + + #[Route('/getStateName/{stateNo}', name: 'getstatename', methods: ['GET'])] + public function getStateName(int $stateNo): Response + { + $response = $this->client->send(new Request('examples.getStateName', [ + new Value($stateNo, Value::$xmlrpcInt) + ])); + if ($response->faultCode()) { + throw new HttpException(502, $response->faultString()); + } else { + return new Response("State number $stateNo is: " . $response->value()->scalarVal() . ''); + } + } +} diff --git a/demo/client/symfony/services.yaml b/demo/client/symfony/services.yaml new file mode 100644 index 00000000..f97690e4 --- /dev/null +++ b/demo/client/symfony/services.yaml @@ -0,0 +1,17 @@ +parameters: + xml_rpc_server: https://gggeek.altervista.org/sw/xmlrpc/demo/server/server.php + xml_rpc_client_options: [] + +services: + # explicitly configure the services where autowiring is impossible + + App\Service\XmlRpcClient: + class: PhpXmlRpc\Client + arguments: + - '%xml_rpc_server%' + calls: + - setOptions: ['%xml_rpc_client_options%'] + + App\Controller\ClientController: + arguments: + $client: '@App\Service\XmlRpcClient' diff --git a/demo/server/symfony/ServerController.php b/demo/server/symfony/ServerController.php new file mode 100644 index 00000000..80a0c8a9 --- /dev/null +++ b/demo/server/symfony/ServerController.php @@ -0,0 +1,29 @@ +server = $server; + } + + # 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 + #[Route('/xmlrpc', name: 'xml_rpc', methods: ['POST'])] + public function serve(): Response + { + $xmlrpcResponse = $this->server->service(null, true); + $response = new Response($xmlrpcResponse, 200, ['Content-Type' => 'text/xml']); + // there should be no need to avoid caching since this is only accessed via POST + return $response; + } +} diff --git a/demo/server/symfony/services.yaml b/demo/server/symfony/services.yaml new file mode 100644 index 00000000..79e7010e --- /dev/null +++ b/demo/server/symfony/services.yaml @@ -0,0 +1,31 @@ +parameters: + xml_rpc_server_options: [] + +services: + # explicitly configure the services + + App\Service\CommentManager: + class: CommentManager + + App\Service\XmlRpcServer: + class: PhpXmlRpc\Server + arguments: + - + # the dispatch map can not be defined using a parameter because it contains references to a service + discuss.addComment: + function: ['@App\Service\CommentManager', 'addComment'], + signature: + - ['int', 'string', 'string', 'string'] + docstring: Adds a comment to an item. The first parameter is the item ID, the second the name of the commenter, and the third is the comment itself. Returns the number of comments against that ID. + discuss.getComments: + function: ['@App\Service\CommentManager', 'getComments'], + signature: + - [ 'array', 'string' ] + docstring: Returns an array of comments for a given ID, which is the sole argument. Each array item is a struct containing name and comment text. + - false + calls: + - setOptions: ['%xml_rpc_server_options%'] + + App\Controller\ServerController: + arguments: + $server: '@App\Service\XmlRpcServer'