From 80d75fe7125a7af6b1a5e8694663fa824e402fcb Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Wed, 30 Dec 2015 15:27:34 +1030 Subject: [PATCH] Allow extensions to modify text/XML prior to formatting --- .../core/src/Event/ConfigureFormatterParser.php | 9 ++++++++- .../core/src/Event/ConfigureFormatterRenderer.php | 9 ++++++++- framework/core/src/Formatter/Formatter.php | 12 +++++------- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/framework/core/src/Event/ConfigureFormatterParser.php b/framework/core/src/Event/ConfigureFormatterParser.php index f518d2033..95d326412 100644 --- a/framework/core/src/Event/ConfigureFormatterParser.php +++ b/framework/core/src/Event/ConfigureFormatterParser.php @@ -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; } } diff --git a/framework/core/src/Event/ConfigureFormatterRenderer.php b/framework/core/src/Event/ConfigureFormatterRenderer.php index e2ea07f35..a17d00df1 100644 --- a/framework/core/src/Event/ConfigureFormatterRenderer.php +++ b/framework/core/src/Event/ConfigureFormatterRenderer.php @@ -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; } } diff --git a/framework/core/src/Formatter/Formatter.php b/framework/core/src/Formatter/Formatter.php index 4812e2fb7..f8b0fb69d 100644 --- a/framework/core/src/Formatter/Formatter.php +++ b/framework/core/src/Formatter/Formatter.php @@ -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'); } /**