Skip to content

Commit

Permalink
make the debugger smarter wrt. location of jsxmlrpc visual editor
Browse files Browse the repository at this point in the history
  • Loading branch information
gggeek committed Dec 20, 2022
1 parent bb5bf03 commit 1fc56c0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 12 deletions.
6 changes: 5 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
5 changes: 3 additions & 2 deletions debugger/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
38 changes: 29 additions & 9 deletions debugger/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
?><!DOCTYPE html>
<html lang="en">
<head>
Expand Down

0 comments on commit 1fc56c0

Please sign in to comment.