From b4faf9d353cdef8d8e81e3b6b7d35c028375172f Mon Sep 17 00:00:00 2001 From: gggeek Date: Tue, 10 Jan 2023 12:38:39 +0000 Subject: [PATCH] simplify serverside codegen demo --- demo/server/codegen.php | 47 +++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/demo/server/codegen.php b/demo/server/codegen.php index 103b2e60..082e7aed 100644 --- a/demo/server/codegen.php +++ b/demo/server/codegen.php @@ -3,7 +3,6 @@ require_once __DIR__ . "/_prepend.php"; require_once __DIR__.'/methodProviders/CommentManager.php'; -use PhpXmlRpc\Server; use PhpXmlRpc\Wrapper; $cm = new CommentManager(); @@ -17,14 +16,14 @@ $code = $w->wrapPhpClass( ) ); -// the generated code does not have an autoloader included - we need to add in one -$autoloader = __DIR__ . "/_prepend.php"; - $targetClassFile = '/tmp/MyServerClass.php'; -$targetDispatchMapFile = '/tmp/myServerDM.php'; +$targetServerFile = '/tmp/myServer.php'; // generate a file with a class definition +// the generated code does not have an autoloader included - we need to add in one +$autoloader = __DIR__ . "/_prepend.php"; + file_put_contents($targetClassFile, " $methodDef) { } file_put_contents($targetClassFile, "}\n", FILE_APPEND) || die('uh oh'); -// and a separate file with the dispatch map +// generate the separate file with the xml-rpc server and dispatch map -file_put_contents($targetDispatchMapFile, +file_put_contents($targetServerFile, "setDebug(2);' . "\n" . + '$s->exception_handling = 1;' . "\n" . + '$s->service();' . "\n" ) || die('uh oh'); // test that everything worked by running it in realtime // *** NB do not do this in prod! The whole concept of code-generation is to do it offline using console scripts/ci/cd *** -include_once $targetClassFile; - -// NB: since we are running the generated code within the same script, the existing CommentManager instance will be -// available for usage by the methods of MyServerClass, as we keep a reference to them within the variable Wrapper::$objHolder -// but if you are generating a php file for later use, it is up to you to initialize that variables with a -// CommentManager instance: -// $cm = new CommentManager(); -// Wrapper::$objHolder['xmlrpc_CommentManager_addComment'] = $cm; -// Wrapper::$objHolder['xmlrpc_CommentManager_getComments'] = $cm; - -$dm = include_once $targetDispatchMapFile; -$s = new Server($dm, false); -$s->setDebug(2); -$s->exception_handling = 1; -$s->service(); +include $targetServerFile; -- 2.47.0