From a374e6d91814d76fd185ffd3b9231e0eb2e09dd3 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Sat, 10 Dec 2022 00:33:43 +0100 Subject: [PATCH] use anonymous function --- _public.php | 52 +++++++++++++++++++++------------------------------- 1 file changed, 21 insertions(+), 31 deletions(-) diff --git a/_public.php b/_public.php index 40e95b1..aad4bef 100644 --- a/_public.php +++ b/_public.php @@ -14,39 +14,29 @@ if (!defined('DC_RC_PATH')) { 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 -{ - public static function alias($args) - { - $o = new dcAliases(); - $aliases = $o->getAliases(); + foreach ($aliases as $v) { + if (@preg_match('#^/.*/$#', $v['alias_url']) && @preg_match($v['alias_url'], $args)) { + $part = preg_replace($v['alias_url'], $v['alias_destination'], $args); - foreach ($aliases as $v) { - if (@preg_match('#^/.*/$#', $v['alias_url']) && @preg_match($v['alias_url'], $args)) { - self::callAliasHandler(preg_replace($v['alias_url'], $v['alias_destination'], $args)); + break; + } elseif ($v['alias_url'] == $args) { + $part = $v['alias_destination']; - return; - } 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); + break; } } -} + + 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); + } +});