Extension code:
Code: Select all
static public function getSubscribedEvents()
{
return array(
'core.text_formatter_s9e_configure_after' => 'text_formatter_s9e_configure_after',
'core.text_formatter_s9e_configure_finalize' => 'text_formatter_s9e_configure_finalize',
);
}
Code: Select all
public function text_formatter_s9e_configure_after($event)
{
$event['configurator']->tags->add('HEART')->template = '♥';
}
Code: Select all
public function text_formatter_s9e_configure_finalize($event)
{
$objects = $event['objects'];
$parser = $objects['parser'];
$parser->registerParser(
'MyParser',
function ($text, $matches) use ($parser)
{
// Here, $matches will contain the result of the following instruction:
// preg_match_all('(<3)', $text, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE)
foreach ($matches as $match)
{
// Let's create a self-closing tag around the match
$parser->addSelfClosingTag('HEART', $match[0][1], 2);
}
},
// Here we pass a regexp as the third argument to indicate that we only want to
// run this parser if the text matches (<3)
'(<3)'
);
$event['objects'] = $objects;
}
Code: Select all
Fatal error: Uncaught Error: Class 's9e\TextFormatter\Plugins\MyParser\Parser' not found in D:\WebServers\OpenServer\domains\phpbb33.zz\vendor\s9e\text-formatter\src\Parser.php:951
Stack trace:
#0 D:\WebServers\OpenServer\domains\phpbb33.zz\vendor\s9e\text-formatter\src\Parser.php(897): s9e\TextFormatter\Parser->getPluginParser()
#1 D:\WebServers\OpenServer\domains\phpbb33.zz\vendor\s9e\text-formatter\src\Parser.php(911): s9e\TextFormatter\Parser->executePluginParser()
#2 D:\WebServers\OpenServer\domains\phpbb33.zz\vendor\s9e\text-formatter\src\Parser.php(344): s9e\TextFormatter\Parser->executePluginParsers()
#3 D:\WebServers\OpenServer\domains\phpbb33.zz\phpbb\textformatter\s9e\parser.php(91): s9e\TextFormatter\Parser->parse()
#4 D:\WebServers\OpenServer\domains\phpbb33.zz\includes\message_parser.php(1250): phpbb\textformatter\s9e\parser->parse()
#5 D:\WebServers\OpenServer\domains\phpbb33.zz\posting.php(1112): parse_message->parse()
#6 {main} thrown in D:\WebServers\OpenServer\domains\phpbb33.zz\vendor\s9e\text-formatter\src\Parser.php on line 951