From 71d9263664885dcca91f20772cd104cf36cc2644 Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Wed, 13 Oct 2021 18:50:04 +0100 Subject: [PATCH] Pass State to render stack closure --- src/Configurables/RenderStack.php | 9 +++++---- src/Parsedown.php | 4 ++-- tests/src/Configurables/RenderStackTest.php | 10 ++++++---- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/Configurables/RenderStack.php b/src/Configurables/RenderStack.php index fe0930d..b9a831f 100644 --- a/src/Configurables/RenderStack.php +++ b/src/Configurables/RenderStack.php @@ -4,14 +4,15 @@ namespace Erusev\Parsedown\Configurables; use Erusev\Parsedown\Configurable; use Erusev\Parsedown\Html\Renderable; +use Erusev\Parsedown\State; final class RenderStack implements Configurable { - /** @var list<\Closure(Renderable[]):Renderable[]> */ + /** @var list<\Closure(Renderable[],State):Renderable[]> */ private $stack; /** - * @param list<\Closure(Renderable[]):Renderable[]> $stack + * @param list<\Closure(Renderable[],State):Renderable[]> $stack */ private function __construct($stack = []) { @@ -25,7 +26,7 @@ final class RenderStack implements Configurable } /** - * @param \Closure(Renderable[]):Renderable[] $RenderMap + * @param \Closure(Renderable[],State):Renderable[] $RenderMap * @return self */ public function push(\Closure $RenderMap): self @@ -33,7 +34,7 @@ final class RenderStack implements Configurable return new self(\array_merge($this->stack, [$RenderMap])); } - /** @return list<\Closure(Renderable[]):Renderable[]> */ + /** @return list<\Closure(Renderable[],State):Renderable[]> */ public function getStack(): array { return $this->stack; diff --git a/src/Parsedown.php b/src/Parsedown.php index 997b152..b5046b9 100644 --- a/src/Parsedown.php +++ b/src/Parsedown.php @@ -49,11 +49,11 @@ final class Parsedown \array_reverse($State->get(RenderStack::class)->getStack()), /** * @param Renderable[] $Renderables - * @param \Closure(Renderable[]):Renderable[] $RenderMap + * @param \Closure(Renderable[],State):Renderable[] $RenderMap * @return Renderable[] */ function (array $Renderables, \Closure $RenderMap): array { - return $RenderMap($Renderables); + return $RenderMap($Renderables, $this->State); }, $State->applyTo($StateRenderables) ); diff --git a/tests/src/Configurables/RenderStackTest.php b/tests/src/Configurables/RenderStackTest.php index 8755304..357be8f 100644 --- a/tests/src/Configurables/RenderStackTest.php +++ b/tests/src/Configurables/RenderStackTest.php @@ -23,16 +23,18 @@ final class RenderStackTest extends TestCase ->push( /** * @param Renderable[] $Rs - * return Renderable[] + * @param State $_ + * @return Renderable[] */ - function ($Rs) { return \array_merge($Rs, [new Text('baz')]); } + function ($Rs, $_) { return \array_merge($Rs, [new Text('baz')]); } ) ->push( /** * @param Renderable[] $Rs - * return Renderable[] + * @param State $_ + * @return Renderable[] */ - function ($Rs) { return \array_merge($Rs, [new Text('bar')]); } + function ($Rs, $_) { return \array_merge($Rs, [new Text('bar')]); } ) ;