update
This commit is contained in:
parent
bcb79777a6
commit
defa62be46
@ -765,6 +765,75 @@
|
|||||||
return $str;
|
return $str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function ParsePathVariablesIntoPage(&$actualPage, &$pathVars)
|
||||||
|
{
|
||||||
|
$actualPages = array();
|
||||||
|
$actualPage = null;
|
||||||
|
$pathVars = null;
|
||||||
|
|
||||||
|
foreach (System::$Parser->Pages as $page)
|
||||||
|
{
|
||||||
|
if (!$page->Enabled) continue;
|
||||||
|
|
||||||
|
/*
|
||||||
|
// this is simple, but only works if all path parts are within the //s...
|
||||||
|
// for example, it fails on d/{onevar}/xxx/{somevar}.htmld
|
||||||
|
// because {somevar} is not entirely within // like {onevar} is
|
||||||
|
|
||||||
|
$pathParts = explode("/", $page->FileName);
|
||||||
|
$pathPartCount = count($pathParts);
|
||||||
|
$found = true;
|
||||||
|
for ($i = 0; $i < $pathPartCount; $i++)
|
||||||
|
{
|
||||||
|
$pathPart = $pathParts[$i];
|
||||||
|
if (stripos($pathPart, "$(") == 0 && stripos($pathPart, ")") == strlen($pathPart) - 1)
|
||||||
|
{
|
||||||
|
$pathVarName = substr($pathPart, 2, strlen($pathPart) - 3);
|
||||||
|
$pathVars[$pathVarName] = $actualPathParts[$i];
|
||||||
|
}
|
||||||
|
else if (stripos($pathPart, "{") == 0 && stripos($pathPart, "}") == strlen($pathPart) - 1)
|
||||||
|
{
|
||||||
|
$pathVarName = substr($pathPart, 1, strlen($pathPart) - 2);
|
||||||
|
$pathVars[$pathVarName] = $actualPathParts[$i];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$app = "";
|
||||||
|
if (isset($actualPathParts[$i])) $app = $actualPathParts[$i];
|
||||||
|
|
||||||
|
if ($app != $pathPart && (!($app == "" && $pathPart == "")))
|
||||||
|
{
|
||||||
|
// a literal path string is broken; we can't use this
|
||||||
|
$found = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
$vars = System::ParsePathVariables($page->FileName, System::GetVirtualPathString());
|
||||||
|
if ($vars !== false)
|
||||||
|
{
|
||||||
|
if ($page !== null)
|
||||||
|
{
|
||||||
|
$actualPages[] = $page;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME : find the "best match" for the given route
|
||||||
|
$qs = new QuickSort();
|
||||||
|
$sortedPages = $qs->Sort($actualPages, function($left, $right)
|
||||||
|
{
|
||||||
|
$leftStr = System::__ReplaceAny($left->FileName, "{", "}" , "?");
|
||||||
|
$rightStr = System::__ReplaceAny($right->FileName, "{", "}" , "?");
|
||||||
|
$val = strlen($leftStr) > strlen($rightStr);
|
||||||
|
return $val;
|
||||||
|
});
|
||||||
|
$actualPage = $sortedPages[0];
|
||||||
|
$pathVars = System::ParsePathVariables($actualPage->FileName, System::GetVirtualPathString());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses a path in the form /static/routes/{with}/dynamic/{variables}.htmld
|
* Parses a path in the form /static/routes/{with}/dynamic/{variables}.htmld
|
||||||
* /static/routes/glbakdlsfjoaisf/dynamic/fds.htmld
|
* /static/routes/glbakdlsfjoaisf/dynamic/fds.htmld
|
||||||
@ -772,7 +841,7 @@
|
|||||||
* If the route matches, returns an array of the resulting path vars.
|
* If the route matches, returns an array of the resulting path vars.
|
||||||
* If the route does not match, returns FALSE.
|
* If the route does not match, returns FALSE.
|
||||||
*/
|
*/
|
||||||
private static function ParsePathStr(string $template, string $pathstr)
|
public static function ParsePathVariables(string $template, string $pathstr)
|
||||||
{
|
{
|
||||||
|
|
||||||
$l = strlen($template);
|
$l = strlen($template);
|
||||||
@ -994,68 +1063,9 @@
|
|||||||
|
|
||||||
$i = 0;
|
$i = 0;
|
||||||
$actualPage = null;
|
$actualPage = null;
|
||||||
$actualPages = array();
|
|
||||||
$pathVarsVars = array();
|
|
||||||
$sortedPages = null;
|
$sortedPages = null;
|
||||||
|
|
||||||
foreach (System::$Parser->Pages as $page)
|
if (System::ParsePathVariablesIntoPage( $actualPage, $pathVars ))
|
||||||
{
|
|
||||||
if (!$page->Enabled) continue;
|
|
||||||
|
|
||||||
/*
|
|
||||||
// this is simple, but only works if all path parts are within the //s...
|
|
||||||
// for example, it fails on d/{onevar}/xxx/{somevar}.htmld
|
|
||||||
// because {somevar} is not entirely within // like {onevar} is
|
|
||||||
|
|
||||||
$pathParts = explode("/", $page->FileName);
|
|
||||||
$pathPartCount = count($pathParts);
|
|
||||||
$found = true;
|
|
||||||
for ($i = 0; $i < $pathPartCount; $i++)
|
|
||||||
{
|
|
||||||
$pathPart = $pathParts[$i];
|
|
||||||
if (stripos($pathPart, "$(") == 0 && stripos($pathPart, ")") == strlen($pathPart) - 1)
|
|
||||||
{
|
|
||||||
$pathVarName = substr($pathPart, 2, strlen($pathPart) - 3);
|
|
||||||
$pathVars[$pathVarName] = $actualPathParts[$i];
|
|
||||||
}
|
|
||||||
else if (stripos($pathPart, "{") == 0 && stripos($pathPart, "}") == strlen($pathPart) - 1)
|
|
||||||
{
|
|
||||||
$pathVarName = substr($pathPart, 1, strlen($pathPart) - 2);
|
|
||||||
$pathVars[$pathVarName] = $actualPathParts[$i];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$app = "";
|
|
||||||
if (isset($actualPathParts[$i])) $app = $actualPathParts[$i];
|
|
||||||
|
|
||||||
if ($app != $pathPart && (!($app == "" && $pathPart == "")))
|
|
||||||
{
|
|
||||||
// a literal path string is broken; we can't use this
|
|
||||||
$found = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// FIXME : find the "best match" for the given route
|
|
||||||
$qs = new QuickSort();
|
|
||||||
|
|
||||||
$vars = System::ParsePathStr($page->FileName, System::GetVirtualPathString());
|
|
||||||
if ($vars !== false)
|
|
||||||
{
|
|
||||||
$actualPages[] = $page;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$sortedPages = $qs->Sort($actualPages, function($left, $right)
|
|
||||||
{
|
|
||||||
return strlen(System::__ReplaceAny($left->FileName, "{", "}" , "?")) > strlen(System::__ReplaceAny($right->FileName, "{", "}" , "?"));
|
|
||||||
});
|
|
||||||
$actualPage = $sortedPages[0];
|
|
||||||
$pathVars = System::ParsePathStr($actualPage->FileName, System::GetVirtualPathString());
|
|
||||||
|
|
||||||
if ($actualPage != null)
|
|
||||||
{
|
{
|
||||||
foreach ($pathVars as $key => $value)
|
foreach ($pathVars as $key => $value)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user