mirror of
https://github.com/flarum/framework.git
synced 2025-02-21 07:27:09 +08:00
Allow extensions to modify text/XML prior to formatting
This commit is contained in:
parent
bf87518161
commit
5a4e3b09cf
@ -24,13 +24,20 @@ class ConfigureFormatterParser
|
||||
*/
|
||||
public $context;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $text;
|
||||
|
||||
/**
|
||||
* @param Parser $parser
|
||||
* @param mixed $context
|
||||
* @param string $text
|
||||
*/
|
||||
public function __construct(Parser $parser, $context)
|
||||
public function __construct(Parser $parser, $context, &$text)
|
||||
{
|
||||
$this->parser = $parser;
|
||||
$this->context = $context;
|
||||
$this->text = &$text;
|
||||
}
|
||||
}
|
||||
|
@ -24,13 +24,20 @@ class ConfigureFormatterRenderer
|
||||
*/
|
||||
public $context;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $xml;
|
||||
|
||||
/**
|
||||
* @param Renderer $renderer
|
||||
* @param mixed $context
|
||||
* @param string $xml
|
||||
*/
|
||||
public function __construct(Renderer $renderer, $context)
|
||||
public function __construct(Renderer $renderer, $context, &$xml)
|
||||
{
|
||||
$this->renderer = $renderer;
|
||||
$this->context = $context;
|
||||
$this->xml = &$xml;
|
||||
}
|
||||
}
|
||||
|
@ -58,6 +58,8 @@ class Formatter
|
||||
{
|
||||
$parser = $this->getParser($context);
|
||||
|
||||
$this->events->fire(new ConfigureFormatterParser($parser, $context, $text));
|
||||
|
||||
return $parser->parse($text);
|
||||
}
|
||||
|
||||
@ -72,6 +74,8 @@ class Formatter
|
||||
{
|
||||
$renderer = $this->getRenderer($context);
|
||||
|
||||
$this->events->fire(new ConfigureFormatterRenderer($renderer, $context, $xml));
|
||||
|
||||
return $renderer->render($xml);
|
||||
}
|
||||
|
||||
@ -161,8 +165,6 @@ class Formatter
|
||||
|
||||
$parser->registeredVars['context'] = $context;
|
||||
|
||||
$this->events->fire(new ConfigureFormatterParser($parser, $context));
|
||||
|
||||
return $parser;
|
||||
}
|
||||
|
||||
@ -180,11 +182,7 @@ class Formatter
|
||||
}
|
||||
});
|
||||
|
||||
$renderer = $this->getComponent('renderer');
|
||||
|
||||
$this->events->fire(new ConfigureFormatterRenderer($renderer, $context));
|
||||
|
||||
return $renderer;
|
||||
return $this->getComponent('renderer');
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user