mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-09 11:44:10 +09:00
Add parser logic for new module.xml settings
This commit is contained in:
parent
5881d08f6a
commit
d0306df095
3 changed files with 77 additions and 0 deletions
|
|
@ -52,6 +52,9 @@ class ModuleActionParser extends BaseParser
|
||||||
$info->grant = new \stdClass;
|
$info->grant = new \stdClass;
|
||||||
$info->menu = new \stdClass;
|
$info->menu = new \stdClass;
|
||||||
$info->error_handlers = [];
|
$info->error_handlers = [];
|
||||||
|
$info->event_handlers = [];
|
||||||
|
$info->namespaces = [];
|
||||||
|
$info->prefixes = [];
|
||||||
|
|
||||||
// Parse grants.
|
// Parse grants.
|
||||||
foreach ($xml->grants->grant ?: [] as $grant)
|
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 the complete result.
|
||||||
return $info;
|
return $info;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,4 +30,17 @@
|
||||||
<permissions>
|
<permissions>
|
||||||
<permission action="procTestSubmitData" target="view" />
|
<permission action="procTestSubmitData" target="view" />
|
||||||
</permissions>
|
</permissions>
|
||||||
|
<errorHandlers>
|
||||||
|
<errorHandler code="405" class="Controllers\Errors" method="dispErrorMethod" />
|
||||||
|
</errorHandlers>
|
||||||
|
<eventHandlers>
|
||||||
|
<eventHandler after="document.insertDocument" class="Controllers\Triggers" method="triggerAfterInsertDocument" />
|
||||||
|
<eventHandler beforeAction="document.procDocumentVoteUp" class="controller" method="triggerBeforeDocumentVoteUp" />
|
||||||
|
</eventHandlers>
|
||||||
|
<namespaces>
|
||||||
|
<namespace name="VendorName\Hello\World" />
|
||||||
|
</namespaces>
|
||||||
|
<prefixes>
|
||||||
|
<prefix name="foobar" />
|
||||||
|
</prefixes>
|
||||||
</module>
|
</module>
|
||||||
|
|
|
||||||
|
|
@ -63,5 +63,27 @@ class ModuleActionParserTest extends \Codeception\TestCase\Test
|
||||||
// Error handlers
|
// Error handlers
|
||||||
$this->assertTrue(is_array($info->error_handlers));
|
$this->assertTrue(is_array($info->error_handlers));
|
||||||
$this->assertEquals('dispTestErrorHandler', $info->error_handlers[404]);
|
$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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue