Add Regex to extra field
This commit is contained in:
parent
35637ddc37
commit
4f9a9e063a
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
define("WEBBASE_VERSION", "1.0.1");
|
define("WEBBASE_VERSION", "1.0.2");
|
||||||
|
|
||||||
function getProtocol() {
|
function getProtocol() {
|
||||||
return (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https" : "http";
|
return (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https" : "http";
|
||||||
@ -157,3 +157,13 @@ function serveStatic(string $webRoot, string $file) {
|
|||||||
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseClass($class) {
|
||||||
|
if (!startsWith($class, "\\")) {
|
||||||
|
$class = "\\$class";
|
||||||
|
}
|
||||||
|
|
||||||
|
$parts = explode("\\", $class);
|
||||||
|
$parts = array_map('ucfirst', $parts);
|
||||||
|
return implode("\\", $parts);
|
||||||
|
}
|
@ -111,9 +111,10 @@ if(isset($_GET["api"]) && is_string($_GET["api"])) {
|
|||||||
$response = (new Document404($user))->getCode();
|
$response = (new Document404($user))->getCode();
|
||||||
} else {
|
} else {
|
||||||
$target = trim(explode("\n", $route["target"])[0]);
|
$target = trim(explode("\n", $route["target"])[0]);
|
||||||
|
$extra = $route["extra"] ?? "";
|
||||||
|
|
||||||
$pattern = str_replace("/","\\/", $route["request"]);
|
$pattern = str_replace("/","\\/", $route["request"]);
|
||||||
$pattern = "/$pattern/";
|
$pattern = "/$pattern/i";
|
||||||
if (!startsWith($requestedUri, '/')) {
|
if (!startsWith($requestedUri, '/')) {
|
||||||
$requestedUri = "/$requestedUri";
|
$requestedUri = "/$requestedUri";
|
||||||
}
|
}
|
||||||
@ -122,6 +123,7 @@ if(isset($_GET["api"]) && is_string($_GET["api"])) {
|
|||||||
if (is_array($match) && !empty($match)) {
|
if (is_array($match) && !empty($match)) {
|
||||||
foreach($match as $index => $value) {
|
foreach($match as $index => $value) {
|
||||||
$target = str_replace("$$index", $value, $target);
|
$target = str_replace("$$index", $value, $target);
|
||||||
|
$extra = str_replace("$$index", $value, $extra);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,7 +141,7 @@ if(isset($_GET["api"]) && is_string($_GET["api"])) {
|
|||||||
$response = serveStatic($currentDir, $target);
|
$response = serveStatic($currentDir, $target);
|
||||||
break;
|
break;
|
||||||
case "dynamic":
|
case "dynamic":
|
||||||
$view = $route["extra"] ?? "";
|
$view = parseClass($extra);
|
||||||
$file = getClassPath($target);
|
$file = getClassPath($target);
|
||||||
if(!file_exists($file) || !is_subclass_of($target, Document::class)) {
|
if(!file_exists($file) || !is_subclass_of($target, Document::class)) {
|
||||||
$document = new Document404($user, $view);
|
$document = new Document404($user, $view);
|
||||||
|
@ -9,7 +9,7 @@ let Core = function () {
|
|||||||
params = typeof params !== 'undefined' ? params : {};
|
params = typeof params !== 'undefined' ? params : {};
|
||||||
callback = typeof callback !== 'undefined' ? callback : function (data) {};
|
callback = typeof callback !== 'undefined' ? callback : function (data) {};
|
||||||
|
|
||||||
const path = '/api/' + (func.startsWith('/') ? '' : '/') + func;
|
const path = '/api' + (func.startsWith('/') ? '' : '/') + func;
|
||||||
$.post(path, params, function (data) {
|
$.post(path, params, function (data) {
|
||||||
console.log(func + "(): success=" + data.success + " msg=" + data.msg);
|
console.log(func + "(): success=" + data.success + " msg=" + data.msg);
|
||||||
callback.call(this, data);
|
callback.call(this, data);
|
||||||
|
Loading…
Reference in New Issue
Block a user