use anonymous function

This commit is contained in:
Jean-Christian Paul Denis 2022-12-10 00:33:43 +01:00
parent 870bcb024b
commit a374e6d918
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951

View File

@ -14,39 +14,29 @@ if (!defined('DC_RC_PATH')) {
return null; return null;
} }
dcCore::app()->url->register('alias', '', '^(.*)$', ['urlAlias','alias']); dcCore::app()->url->register('alias', '', '^(.*)$', function ($args) {
$o = new dcAliases();
$aliases = $o->getAliases();
$part = $args;
class urlAlias extends dcUrlHandlers foreach ($aliases as $v) {
{ if (@preg_match('#^/.*/$#', $v['alias_url']) && @preg_match($v['alias_url'], $args)) {
public static function alias($args) $part = preg_replace($v['alias_url'], $v['alias_destination'], $args);
{
$o = new dcAliases();
$aliases = $o->getAliases();
foreach ($aliases as $v) { break;
if (@preg_match('#^/.*/$#', $v['alias_url']) && @preg_match($v['alias_url'], $args)) { } elseif ($v['alias_url'] == $args) {
self::callAliasHandler(preg_replace($v['alias_url'], $v['alias_destination'], $args)); $part = $v['alias_destination'];
return; break;
} elseif ($v['alias_url'] == $args) {
self::callAliasHandler($v['alias_destination']);
return;
}
}
self::callAliasHandler($args);
}
public static function callAliasHandler($part)
{
dcCore::app()->url->unregister('alias');
dcCore::app()->url->getArgs($part, $type, $args);
if (!$type) {
dcCore::app()->url->callDefaultHandler($args);
} else {
dcCore::app()->url->callHandler($type, $args);
} }
} }
}
dcCore::app()->url->unregister('alias');
dcCore::app()->url->getArgs($part, $type, $args);
if (!$type) {
dcCore::app()->url->callDefaultHandler($args);
} else {
dcCore::app()->url->callHandler($type, $args);
}
});