Skip to content

Commit 1fc56c0

Browse files
committed
make the debugger smarter wrt. location of jsxmlrpc visual editor
1 parent bb5bf03 commit 1fc56c0

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
lines changed

NEWS.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
## XML-RPC for PHP version 4.xx.yy - unreleased
1+
## XML-RPC for PHP version 4.9.yy - unreleased
22

33
* improved: avoid stalling the webserver when using the debugger with the php built-in webserver and testing the demo
44
server within the same install
55

6+
* improved: allow installation of the jsxmlrpc library within the debugger folder via composer or npm to enable the
7+
visual-editing capabilities of the debugger, as this works well when the debugger is used as web-root (target usage
8+
scenario being f.e. using the php cli-webserver to run the debugger)
9+
610

711
## XML-RPC for PHP version 4.9.2 - 2022-12-18
812

debugger/common.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313

1414
// handle class autoloading:
1515
if (file_exists(__DIR__.'/../vendor/autoload.php')) {
16-
// if the debugger is installed as top-level project with Composer, allow finding classes from dependencies
16+
// if the debugger's package is installed as top-level project, and dependencies via Composer, allow finding classes
17+
// from dependencies
1718
include_once(__DIR__.'/../vendor/autoload.php');
1819
} else {
1920
// assume this is either a standalone install, or installed as Composer dependency
2021
/// @todo if the latter is true, should we just not skip using the custom Autoloader, and let a top-level
21-
/// debugger include this one, taking care of autoloading ?
22+
/// debugger include this one, taking care of autoloading?
2223
include_once __DIR__ . "/../src/Autoloader.php";
2324
PhpXmlRpc\Autoloader::register();
2425
}

debugger/controller.php

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,41 @@
2222
$action = 'list';
2323
}
2424

25-
// Path to the visual xmlrpc editing dialog's containing folder. Can be absolute, or relative to this debugger's folder.
26-
// We allow to easily configure this path via defines
27-
$editorpath = (defined('JSXMLRPC_PATH') ? JSXMLRPC_PATH : '../..') . '/jsxmlrpc/debugger/';
28-
// In case the webserver is set up so that the url to that folder is different. We default to JSXMLRPC_PATH for BC
29-
$editorurlpath = defined('JSXMLRPC_BASEURL') ? JSXMLRPC_BASEURL : $editorpath;
25+
$haseditor = false;
26+
$editorurlpath = null;
27+
// @const JSXMLRPC_BASEURL Url to the visual xmlrpc editing dialog's containing folder. We allow to easily configure this
3028
if (defined('JSXMLRPC_BASEURL')) {
29+
$editorurlpath = JSXMLRPC_BASEURL;
3130
$haseditor = true;
3231
} else {
33-
if ($editorpath[0] !== '/') {
34-
$haseditor = is_file(realpath(__DIR__ . '/' . $editorpath . 'visualeditor.html'));
32+
/// @deprecated
33+
/// @const JSXMLRPC_PATH Path to the visual xmlrpc editing dialog's containing folder. Can be absolute, or
34+
/// relative to this debugger's folder.
35+
if (defined('JSXMLRPC_PATH')) {
36+
$editorpaths = array(JSXMLRPC_PATH[0] === '/' ? JSXMLRPC_PATH : (__DIR__ . '/' . JSXMLRPC_PATH));
3537
} else {
36-
$haseditor = is_file(realpath($editorpath . 'visualeditor.html'));;
38+
$editorpaths = array(
39+
__DIR__ . '/vendor/phpxmlrpc/jsxmlrpc/debugger/', // this package is top-level, jsxmlrpc installed via composer in debugger
40+
__DIR__ . '/node_modules/@jsxmlrpc/jsxmlrpc/debugger/', // this package is top-level, jsxmlrpc installed via npm in debugger
41+
__DIR__ . '/../vendor/phpxmlrpc/jsxmlrpc/debugger/', // this package is top-level, jsxmlrpc installed via composer
42+
__DIR__ . '/../node_modules/@jsxmlrpc/jsxmlrpc/debugger/', // this package is top-level, jsxmlrpc installed via npm
43+
__DIR__ . '/../../jsxmlrpc/debugger/', // this package is a composer dependency, jsxmlrpc too
44+
);
3745
}
38-
}
46+
foreach($editorpaths as $editorpath) {
47+
if (is_file(realpath($editorpath . 'visualeditor.html'))) {
48+
$haseditor = true;
49+
break;
50+
}
51+
}
52+
if ($haseditor) {
53+
$editorurlpath = preg_replace('|^' . preg_quote(__DIR__, '|') .'|', '', $editorpath);
3954

55+
/// @todo for cases 3, 4 and 5 above, look at `parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)` and check if the
56+
/// web root is not pointing directly at this folder, as in that case the link to the visualeditor will not
57+
/// work, as it will be in the form http(s)://domain/../../jsxmlrpc/debugger/visualeditor.html
58+
}
59+
}
4060
?><!DOCTYPE html>
4161
<html lang="en">
4262
<head>

0 commit comments

Comments
 (0)