diff --git a/src/TwigHooks/src/Hookable/Renderer/HookableTemplateRenderer.php b/src/TwigHooks/src/Hookable/Renderer/HookableTemplateRenderer.php index 2aee1a06..7d5974f6 100644 --- a/src/TwigHooks/src/Hookable/Renderer/HookableTemplateRenderer.php +++ b/src/TwigHooks/src/Hookable/Renderer/HookableTemplateRenderer.php @@ -8,14 +8,11 @@ use Sylius\TwigHooks\Hookable\HookableTemplate; use Sylius\TwigHooks\Provider\ConfigurationProviderInterface; use Sylius\TwigHooks\Provider\DataProviderInterface; +use Sylius\TwigHooks\Twig\Runtime\HooksRuntime; use Twig\Environment as Twig; final class HookableTemplateRenderer implements SupportableHookableRendererInterface { - public const HOOKABLE_CONFIGURATION_PARAMETER = 'hookable_configuration'; - - public const HOOKABLE_DATA_PARAMETER = 'hookable_data'; - public function __construct( private Twig $twig, private DataProviderInterface $dataProvider, @@ -35,8 +32,8 @@ public function render(AbstractHookable $hookable, array $hookData = []): string $configuration = $this->configurationProvider->provide($hookable); return $this->twig->render($hookable->getTarget(), [ - self::HOOKABLE_DATA_PARAMETER => $data, - self::HOOKABLE_CONFIGURATION_PARAMETER => $configuration, + HooksRuntime::HOOKABLE_DATA_PARAMETER => $data, + HooksRuntime::HOOKABLE_CONFIGURATION_PARAMETER => $configuration, ]); } diff --git a/src/TwigHooks/src/Twig/HooksExtension.php b/src/TwigHooks/src/Twig/HooksExtension.php index 273d9dbc..687bf9be 100644 --- a/src/TwigHooks/src/Twig/HooksExtension.php +++ b/src/TwigHooks/src/Twig/HooksExtension.php @@ -15,8 +15,8 @@ final class HooksExtension extends AbstractExtension public function getFunctions(): array { return [ - new TwigFunction('get_hook_data', [HooksRuntime::class, 'getHookData'], ['needs_context' => true]), - new TwigFunction('get_hook_configuration', [HooksRuntime::class, 'getHookData'], ['needs_context' => true]), + new TwigFunction('get_hook_data', [HooksRuntime::class, 'getHookableData'], ['needs_context' => true]), + new TwigFunction('get_hook_configuration', [HooksRuntime::class, 'getHookableConfiguration'], ['needs_context' => true]), ]; } diff --git a/src/TwigHooks/src/Twig/Runtime/HooksRuntime.php b/src/TwigHooks/src/Twig/Runtime/HooksRuntime.php index 7b85e37b..e42ca8d3 100644 --- a/src/TwigHooks/src/Twig/Runtime/HooksRuntime.php +++ b/src/TwigHooks/src/Twig/Runtime/HooksRuntime.php @@ -13,6 +13,10 @@ final class HooksRuntime implements RuntimeExtensionInterface { + public const HOOKABLE_CONFIGURATION_PARAMETER = 'hookable_configuration'; + + public const HOOKABLE_DATA_PARAMETER = 'hookable_data'; + private ?Stopwatch $stopwatch = null; public function __construct ( @@ -27,21 +31,21 @@ public function __construct ( } /** - * @param array{hook_data?: array} $context + * @param array{hookable_data?: array} $context * @return array */ - public function getHookData(array $context): array + public function getHookableData(array $context): array { - return $context['hook_data'] ?? []; + return $context[self::HOOKABLE_DATA_PARAMETER] ?? []; } /** - * @param array{hook_configuration?: array} $context + * @param array{hookable_configuration?: array} $context * @return array */ - public function getHookConfiguration(array $context): array + public function getHookableConfiguration(array $context): array { - return $context['hook_configuration'] ?? []; + return $context[self::HOOKABLE_CONFIGURATION_PARAMETER] ?? []; } /** diff --git a/src/TwigHooks/tests/Unit/Hookable/Renderer/HookableTemplateRendererTest.php b/src/TwigHooks/tests/Unit/Hookable/Renderer/HookableTemplateRendererTest.php index 29793a79..20097a01 100644 --- a/src/TwigHooks/tests/Unit/Hookable/Renderer/HookableTemplateRendererTest.php +++ b/src/TwigHooks/tests/Unit/Hookable/Renderer/HookableTemplateRendererTest.php @@ -10,6 +10,7 @@ use Sylius\TwigHooks\Hookable\Renderer\HookableTemplateRenderer; use Sylius\TwigHooks\Provider\ConfigurationProviderInterface; use Sylius\TwigHooks\Provider\DataProviderInterface; +use Sylius\TwigHooks\Twig\Runtime\HooksRuntime; use Tests\Sylius\TwigHooks\Utils\MotherObject\HookableComponentMotherObject; use Tests\Sylius\TwigHooks\Utils\MotherObject\HookableTemplateMotherObject; use Twig\Environment as Twig; @@ -59,8 +60,8 @@ public function testItRendersHookableTemplate(): void $this->configurationProvider->expects($this->once())->method('provide')->willReturn(['some' => 'configuration']); $this->twig->expects($this->once())->method('render')->with('some-template', [ - HookableTemplateRenderer::HOOKABLE_DATA_PARAMETER => ['some' => 'data'], - HookableTemplateRenderer::HOOKABLE_CONFIGURATION_PARAMETER => ['some' => 'configuration'], + HooksRuntime::HOOKABLE_DATA_PARAMETER => ['some' => 'data'], + HooksRuntime::HOOKABLE_CONFIGURATION_PARAMETER => ['some' => 'configuration'], ])->willReturn('some-rendered-template'); $hookable = HookableTemplateMotherObject::withTarget('some-template');