make the debugger smarter wrt. location of jsxmlrpc visual editor
authorgggeek <giunta.gaetano@gmail.com>
Tue, 20 Dec 2022 15:00:01 +0000 (15:00 +0000)
committergggeek <giunta.gaetano@gmail.com>
Tue, 20 Dec 2022 15:00:01 +0000 (15:00 +0000)
NEWS.md
debugger/common.php
debugger/controller.php

diff --git a/NEWS.md b/NEWS.md
index 96c7023..4746d79 100644 (file)
--- 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
 
index 706f03f..f1fdc3e 100644 (file)
 
 // 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();
 }
index 021c9bb..0d4acc6 100644 (file)
@@ -22,21 +22,41 @@ if ($action == '') {
     $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
+    }
+}
 ?><!DOCTYPE html>
 <html lang="en">
 <head>