Error while creating s9e/textformatter plugin

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
Татьяна5
Registered User
Posts: 189
Joined: Wed Feb 13, 2013 5:30 pm
Name: Tatiana

Error while creating s9e/textformatter plugin

Post by Татьяна5 »

I used this instruction: https://s9etextformatter.readthedocs.io ... er_parser/
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;
	}
It is work, but I get an error:

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
How to fix it? Where to set the address of the class or remove the use of the class?
User avatar
JoshyPHP
Code Contributor
Posts: 1288
Joined: Mon Jul 11, 2011 12:28 am

Re: Error while creating s9e/textformatter plugin

Post by JoshyPHP »

You're using a closure during configuration and those can't be serialized for storage. That's probably why it can't find it at parsing time. Either use a serializable callback or set up your custom parser at parsing time with the core.text_formatter_s9e_parser_setup event.
I wrote the library that handles markup in phpBB 3.2+.
Post Reply

Return to “Extension Writers Discussion”