Add parser logic for new module.xml settings

This commit is contained in:
Kijin Sung 2023-08-10 23:52:01 +09:00
parent 5881d08f6a
commit d0306df095
3 changed files with 77 additions and 0 deletions

View file

@ -52,6 +52,9 @@ class ModuleActionParser extends BaseParser
$info->grant = new \stdClass;
$info->menu = new \stdClass;
$info->error_handlers = [];
$info->event_handlers = [];
$info->namespaces = [];
$info->prefixes = [];
// Parse grants.
foreach ($xml->grants->grant ?: [] as $grant)
@ -239,6 +242,45 @@ class ModuleActionParser extends BaseParser
}
}
// Parse error handlers.
foreach ($xml->errorHandlers->errorHandler ?: [] as $errorHandler)
{
$attrs = self::_getAttributes($errorHandler);
$info->error_handlers[intval($attrs['code'])] = [$attrs['class'], $attrs['method']];
}
// Parse event handlers.
foreach ($xml->eventHandlers->eventHandler ?: [] as $eventHandler)
{
$attrs = self::_getAttributes($eventHandler);
$def = new \stdClass;
foreach (['before', 'after', 'beforeaction', 'afteraction'] as $key)
{
if (isset($attrs[$key]))
{
$def->event_name = (str_contains($key, 'action') ? 'act:' : '') . $attrs[$key];
$def->position = str_starts_with($key, 'before') ? 'before' : 'after';
$def->class_name = $attrs['class'];
$def->method = $attrs['method'];
$info->event_handlers[] = $def;
break;
}
}
}
// Parse custom namespaces.
foreach ($xml->namespaces->namespace ?: [] as $namespace)
{
$info->namespaces[] = strval($namespace['name']);
}
// Parse custom prefixes.
foreach ($xml->prefixes->prefix ?: [] as $prefix)
{
$info->prefixes[] = strval($prefix['name']);
}
// Return the complete result.
return $info;
}