diff --git a/common/framework/parsers/ModuleActionParser.php b/common/framework/parsers/ModuleActionParser.php index 9a5d7b5eb..f0a7b601c 100644 --- a/common/framework/parsers/ModuleActionParser.php +++ b/common/framework/parsers/ModuleActionParser.php @@ -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; } diff --git a/tests/_data/module/module.xml b/tests/_data/module/module.xml index d68118641..ce887491e 100644 --- a/tests/_data/module/module.xml +++ b/tests/_data/module/module.xml @@ -30,4 +30,17 @@ + + + + + + + + + + + + + diff --git a/tests/unit/framework/parsers/ModuleActionParserTest.php b/tests/unit/framework/parsers/ModuleActionParserTest.php index 3a2490395..f52b86bee 100644 --- a/tests/unit/framework/parsers/ModuleActionParserTest.php +++ b/tests/unit/framework/parsers/ModuleActionParserTest.php @@ -63,5 +63,27 @@ class ModuleActionParserTest extends \Codeception\TestCase\Test // Error handlers $this->assertTrue(is_array($info->error_handlers)); $this->assertEquals('dispTestErrorHandler', $info->error_handlers[404]); + $this->assertEquals(['Controllers\Errors', 'dispErrorMethod'], $info->error_handlers[405]); + + // Event handlers + $this->assertTrue(is_array($info->event_handlers)); + $this->assertTrue(is_object($info->event_handlers[0])); + $this->assertEquals('document.insertDocument', $info->event_handlers[0]->event_name); + $this->assertEquals('after', $info->event_handlers[0]->position); + $this->assertEquals('Controllers\\Triggers', $info->event_handlers[0]->class_name); + $this->assertEquals('triggerAfterInsertDocument', $info->event_handlers[0]->method); + $this->assertTrue(is_object($info->event_handlers[1])); + $this->assertEquals('act:document.procDocumentVoteUp', $info->event_handlers[1]->event_name); + $this->assertEquals('before', $info->event_handlers[1]->position); + $this->assertEquals('controller', $info->event_handlers[1]->class_name); + $this->assertEquals('triggerBeforeDocumentVoteUp', $info->event_handlers[1]->method); + + // Custom namespaces + $this->assertTrue(is_array($info->namespaces)); + $this->assertTrue(in_array('VendorName\\Hello\\World', $info->namespaces)); + + // Custom prefixes + $this->assertTrue(is_array($info->prefixes)); + $this->assertTrue(in_array('foobar', $info->prefixes)); } }