From 1fc56c09280df0c4a625c0a5af62815d7e5b218e Mon Sep 17 00:00:00 2001 From: gggeek Date: Tue, 20 Dec 2022 15:00:01 +0000 Subject: [PATCH] make the debugger smarter wrt. location of jsxmlrpc visual editor --- NEWS.md | 6 +++++- debugger/common.php | 5 +++-- debugger/controller.php | 38 +++++++++++++++++++++++++++++--------- 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/NEWS.md b/NEWS.md index 96c70238..4746d799 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,8 +1,12 @@ -## XML-RPC for PHP version 4.xx.yy - unreleased +## XML-RPC for PHP version 4.9.yy - unreleased * improved: avoid stalling the webserver when using the debugger with the php built-in webserver and testing the demo server within the same install +* improved: allow installation of the jsxmlrpc library within the debugger folder via composer or npm to enable the + visual-editing capabilities of the debugger, as this works well when the debugger is used as web-root (target usage + scenario being f.e. using the php cli-webserver to run the debugger) + ## XML-RPC for PHP version 4.9.2 - 2022-12-18 diff --git a/debugger/common.php b/debugger/common.php index 706f03ff..f1fdc3ee 100644 --- a/debugger/common.php +++ b/debugger/common.php @@ -13,12 +13,13 @@ // handle class autoloading: if (file_exists(__DIR__.'/../vendor/autoload.php')) { - // if the debugger is installed as top-level project with Composer, allow finding classes from dependencies + // if the debugger's package is installed as top-level project, and dependencies via Composer, allow finding classes + // from dependencies include_once(__DIR__.'/../vendor/autoload.php'); } else { // assume this is either a standalone install, or installed as Composer dependency /// @todo if the latter is true, should we just not skip using the custom Autoloader, and let a top-level - /// debugger include this one, taking care of autoloading ? + /// debugger include this one, taking care of autoloading? include_once __DIR__ . "/../src/Autoloader.php"; PhpXmlRpc\Autoloader::register(); } diff --git a/debugger/controller.php b/debugger/controller.php index 021c9bb4..0d4acc60 100644 --- a/debugger/controller.php +++ b/debugger/controller.php @@ -22,21 +22,41 @@ $action = 'list'; } -// Path to the visual xmlrpc editing dialog's containing folder. Can be absolute, or relative to this debugger's folder. -// We allow to easily configure this path via defines -$editorpath = (defined('JSXMLRPC_PATH') ? JSXMLRPC_PATH : '../..') . '/jsxmlrpc/debugger/'; -// In case the webserver is set up so that the url to that folder is different. We default to JSXMLRPC_PATH for BC -$editorurlpath = defined('JSXMLRPC_BASEURL') ? JSXMLRPC_BASEURL : $editorpath; +$haseditor = false; +$editorurlpath = null; +// @const JSXMLRPC_BASEURL Url to the visual xmlrpc editing dialog's containing folder. We allow to easily configure this if (defined('JSXMLRPC_BASEURL')) { + $editorurlpath = JSXMLRPC_BASEURL; $haseditor = true; } else { - if ($editorpath[0] !== '/') { - $haseditor = is_file(realpath(__DIR__ . '/' . $editorpath . 'visualeditor.html')); + /// @deprecated + /// @const JSXMLRPC_PATH Path to the visual xmlrpc editing dialog's containing folder. Can be absolute, or + /// relative to this debugger's folder. + if (defined('JSXMLRPC_PATH')) { + $editorpaths = array(JSXMLRPC_PATH[0] === '/' ? JSXMLRPC_PATH : (__DIR__ . '/' . JSXMLRPC_PATH)); } else { - $haseditor = is_file(realpath($editorpath . 'visualeditor.html'));; + $editorpaths = array( + __DIR__ . '/vendor/phpxmlrpc/jsxmlrpc/debugger/', // this package is top-level, jsxmlrpc installed via composer in debugger + __DIR__ . '/node_modules/@jsxmlrpc/jsxmlrpc/debugger/', // this package is top-level, jsxmlrpc installed via npm in debugger + __DIR__ . '/../vendor/phpxmlrpc/jsxmlrpc/debugger/', // this package is top-level, jsxmlrpc installed via composer + __DIR__ . '/../node_modules/@jsxmlrpc/jsxmlrpc/debugger/', // this package is top-level, jsxmlrpc installed via npm + __DIR__ . '/../../jsxmlrpc/debugger/', // this package is a composer dependency, jsxmlrpc too + ); } -} + foreach($editorpaths as $editorpath) { + if (is_file(realpath($editorpath . 'visualeditor.html'))) { + $haseditor = true; + break; + } + } + if ($haseditor) { + $editorurlpath = preg_replace('|^' . preg_quote(__DIR__, '|') .'|', '', $editorpath); + /// @todo for cases 3, 4 and 5 above, look at `parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)` and check if the + /// web root is not pointing directly at this folder, as in that case the link to the visualeditor will not + /// work, as it will be in the form http(s)://domain/../../jsxmlrpc/debugger/visualeditor.html + } +} ?>